c#为什么递归下载ftp整个文件夹时有些文件或文件夹下不到?

Candbasic 2009-04-30 02:48:32
c#为什么递归下载ftp整个文件夹时有些文件或文件夹下不到?
public 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;

}
}
...全文
460 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
superwarriors 2010-01-15
  • 打赏
  • 举报
回复
GetFilesDetailList() 方法里面是怎么得到文件列表的 ?
liuchuan98 2009-05-12
  • 打赏
  • 举报
回复
up
Candbasic 2009-05-11
  • 打赏
  • 举报
回复
up
mcot1986 2009-05-05
  • 打赏
  • 举报
回复
mark
Candbasic 2009-05-04
  • 打赏
  • 举报
回复
up
Candbasic 2009-05-04
  • 打赏
  • 举报
回复
up
Candbasic 2009-05-04
  • 打赏
  • 举报
回复
public void downloadfloder1(string path, string ftp_path) 
{
try {
string[] str = GetFilesDetailList(ftp_path);
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);

}
else {
downloadfiles(path, ftp_path + "/" + s);

}
}
return;
}
catch (Exception ex) {
MessageBox.Show(ex.Message)
return;
}
}



递归代码
阿牛138588 2009-05-04
  • 打赏
  • 举报
回复
没看到你递归的代码
Candbasic 2009-05-04
  • 打赏
  • 举报
回复
upupup
harderLi 2009-05-04
  • 打赏
  • 举报
回复
关注
Candbasic 2009-05-04
  • 打赏
  • 举报
回复
up
Candbasic 2009-05-04
  • 打赏
  • 举报
回复
都是分散的代码,有已经组合的吗?上传下载文件夹的
lijizun 2009-04-30
  • 打赏
  • 举报
回复
帮顶!
蓝海D鱼 2009-04-30
  • 打赏
  • 举报
回复
up
freewind0521 2009-04-30
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20081027/23/1121933a-8fd1-490c-bec2-8cf3e3a3176d.html
参考1楼的回答
itcrazyman 2009-04-30
  • 打赏
  • 举报
回复
mark up 帮顶

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧