晚辈最近用C#写了一个教育网FTP搜索引擎,希望能得到高手的指点。
网址:http://soso.ccnu.com.cn http://it.ccnu.edu.cn/soso
部分代码:
using System;
using softplib;
using System.Threading;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Data;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace spider
{
/// <summary>
/// IndexClass 的摘要说明。
/// </summary>
//编制索引类
class IndexClass
{
private IPAddress ip;
private string name;
private SqlProcedure sp;
public IndexClass(IPAddress _ip,string _name)
{
ip=_ip;
name=_name;
}
public void createIndex()
{
FTPFactory ff = new FTPFactory();
ff.setDebug(false);
string header="ftp://"+ip.ToString();
string address=name;
try
{
ff.setRemoteHost(ip.ToString());
ff.login();
Queue q=new Queue();
ArrayList fileNames=ff.getFileList("*.*");
ArrayList subdirNames=ff.getSubdir("*",ref fileNames);
if(fileNames!=null && fileNames.Count>0)
foreach(string s in fileNames)
{
try
{
Console.WriteLine(header+"/"+s);
int h=-1;
long _size=0;
try
{
_size=ff.getFileSize(s);
h=s.IndexOf("/");
}
catch
{
_size=0;
Console.WriteLine("size error");
}
if(s!=null && s.Trim()!="")
{
DataUnit datau=new DataUnit(s,_size,header+"/",DateTime.Now,ip.ToString(),address);
Class1.DataQueue.Enqueue(datau);
}
}
catch(Exception ex){Console.WriteLine(ex.Message);};
}
if(subdirNames!=null && subdirNames.Count>0)
foreach(string s in subdirNames)
{
if(s.Equals("..") || s.Equals("."))continue;
if(s!=null && s.Trim()!="")
{
q.Enqueue("/"+s);
DataUnit datau=new DataUnit(s,(long)0,header+"/",DateTime.Now.AddHours(1),ip.ToString(),address);
Class1.DataQueue.Enqueue(datau);
}
}
while(q.Count>0)
{
string parent=q.Dequeue() as string;
//Console.WriteLine("change to "+parent.Trim());
try
{
ff.chdir(parent.Trim());
}
catch
{
Console.WriteLine(parent.Trim());
ff.setRemoteHost(ip.ToString());
ff.login();
Console.WriteLine("=======Continue========");
continue;
}
fileNames=ff.getFileList("*.*");
subdirNames=ff.getSubdir("*",ref fileNames);
if(fileNames!=null && fileNames.Count>0)
foreach(string s in fileNames)
{
try
{
Console.WriteLine(header+parent+"/"+s);
long _size=0;
int h=-1;
try
{
_size=ff.getFileSize(s);
h=s.IndexOf("/");
}
catch
{
_size=0;
Console.WriteLine("size error");
}
if(s!=null && s.Trim()!="")
{
DataUnit datau=new DataUnit(s,_size,header+parent+"/",DateTime.Now,ip.ToString(),address);
Class1.DataQueue.Enqueue(datau);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
ff.setRemoteHost(ip.ToString());
ff.login();
ff.chdir(parent.Trim());
Console.WriteLine("=======Continue========");
continue;
};
}
if(subdirNames!=null && subdirNames.Count>0)
foreach(string s in subdirNames)
{
if(s.Equals("..") || s.Equals(".") || s.StartsWith("\0"))continue;
if(s!=null && s.Trim()!="")
{
q.Enqueue(parent+"/"+s); &nb