c#如何下载ftp整个文件夹? c#如何下载ftp整个文件夹? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 C# codepublic void downloadfloder1(string path, string ftp_path) { try { string[] str = GetFilesDetailList(ftp_path); foreach (string s1 in str) { Form1.TextBox1.Text += s1 + Constants.vbCrLf; } int x = 0; for (x = 0; x <= str.Length - 1; x++) { string s = Conversion.str(x).Substring(Conversion.str(x).LastIndexOf(" ") + 1, Conversion.str(x).Length - Conversion.str(x).LastIndexOf(" ") - 1); if (Conversion.str(x)(0) != "d" & Conversion.str(x)(0) != "-") { continue; } if (s == "." | s == "..") { continue; } if (Conversion.str(x)(0) == "d") { My.Computer.FileSystem.CreateDirectory(path + "/" + s); downloadfloder1(path + "/" + s, ftp_path + "/" + s); //Form1.TextBox1.Text += ftp_path + "/" + s + vbCrLf System.Threading.Thread.Sleep(200); } else { downloadfiles(path, ftp_path + "/" + s); //Form1.TextBox1.Text += ftp_path + "/" + s + vbCrLf System.Threading.Thread.Sleep(200); } } //reqFTP = Nothing return; } catch (Exception ex) { //MessageBox.Show(ex.Message) return; } } public void downloadfiles(string filePath, string fileName) { //上面的代码实现了从ftp服务器下载文件的功能 try { string onlyFileName = Path.GetFileName(fileName); string newFileName = filePath + "\\" + onlyFileName; if (File.Exists(newFileName)) { return; } string url = "ftp://" + ftpServerIP + "/" + fileName; Connect(url); //连接 reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); Stream ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int bufferSize = 2048; int readCount = 0; byte[] buffer = new byte[bufferSize]; readCount = ftpStream.Read(buffer, 0, bufferSize); FileStream outputStream = new FileStream(newFileName, FileMode.Create); while (readCount > 0) { outputStream.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); } ftpStream.Close(); outputStream.Close(); response.Close(); } catch (Exception ex) { Form1.TextBox1.Text += "ftp://" + ftpServerIP + "/" + fileName + Constants.vbCrLf + ex.Message + Constants.vbCrLf; } } 通过反射动态SHOW出的窗体 怎么传递参数 dataGridView列显示问题? 序列化的问题 在c#桌面程序中, 如果得到html中内嵌js脚本执行的结果? (立结20分超级简单的问题)这个程序错在那里?? c# mail发送邮件,使用SSL认证,只有gmail可以发送,其他都是发送失败 菜鸟求助,一个关于MDI容器的问题 asp.net PasswordRecovery控件问题 愁死了 简单的问题大家来看看 IE启动问题 C#除了能做asp.net的网站以外还能开发其他的程序么? 刚学了委托,自己写了一个也不知道对不对 大家帮看看啊!
C# codepublic void downloadfloder1(string path, string ftp_path)
{ try { string[] str = GetFilesDetailList(ftp_path); foreach (string s1 in str) {
Form1.TextBox1.Text += s1 + Constants.vbCrLf;
} int x = 0;
for (x = 0; x <= str.Length - 1; x++) {
string s = Conversion.str(x).Substring(Conversion.str(x).LastIndexOf(" ") + 1, Conversion.str(x).Length - Conversion.str(x).LastIndexOf(" ") - 1);
if (Conversion.str(x)(0) != "d" & Conversion.str(x)(0) != "-") {
continue;
}
if (s == "." | s == "..") {
continue;
}
if (Conversion.str(x)(0) == "d") {
My.Computer.FileSystem.CreateDirectory(path + "/" + s);
downloadfloder1(path + "/" + s, ftp_path + "/" + s);
//Form1.TextBox1.Text += ftp_path + "/" + s + vbCrLf
System.Threading.Thread.Sleep(200);
}
else { downloadfiles(path, ftp_path + "/" + s); //Form1.TextBox1.Text += ftp_path + "/" + s + vbCrLf
System.Threading.Thread.Sleep(200);
}
}
//reqFTP = Nothing
return;
}
catch (Exception ex) {
//MessageBox.Show(ex.Message)
return;
}
}
public void downloadfiles(string filePath, string fileName)
{
//上面的代码实现了从ftp服务器下载文件的功能
try { string onlyFileName = Path.GetFileName(fileName); string newFileName = filePath + "\\" + onlyFileName; if (File.Exists(newFileName)) { return;
}
string url = "ftp://" + ftpServerIP + "/" + fileName;
Connect(url);
//连接
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount = 0;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize); FileStream outputStream = new FileStream(newFileName, FileMode.Create);
while (readCount > 0) { outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close(); response.Close();
}
catch (Exception ex) { Form1.TextBox1.Text += "ftp://" + ftpServerIP + "/" + fileName + Constants.vbCrLf + ex.Message + Constants.vbCrLf; }
}