以下是我的部分ftp源程序,可以实现客户端到服务器的上传,可是只能实现某个目录下的一个文件的上传,有谁能实现将客户端整个目录下的所有文件上传到服务器的?
private void button1_Click(object sender, System.EventArgs e)
{
FTPFactory ff = new FTPFactory();
ff.setDebug(true);
ff.setRemoteHost("172.22.68.4");
ff.setRemoteUser("webipp");
ff.setRemotePass("");
ff.login();
ff.chdir("bt");
string[] fileNames = ff.getFileList("*.*");
for(int i=0;i < fileNames.Length;i++)
{
Console.WriteLine(fileNames[i]);
}
ff.setBinaryMode(true);
if(textBox1.Text=="")
{
MessageBox.Show("文件名不能为空!请重新输入文件名。");
return;
}
ff.upload(textBox1.Text);
ff.close();
}
public FTPFactory()
{
remoteHost = "172.22.68.4";
remotePath = ".";
remoteUser = "webipp";
remotePass = " ";
remotePort = 21;
debug = false;
logined = false;
}
public void upload(string fileName)
{
upload(fileName,false);
}
foreach(string Fn in Directory.GetFiles(@"c:\abc","*.*"))
{
if (File.Exists(Fn))
ff.upload(Fn);
}