从FTP下载文件时出现问题 [英] Problem in Downloading files from FTP

查看:94
本文介绍了从FTP下载文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从ftp服务器下载文件,当调试文件夹中有类似文件时,下载时很好,如果调试文件夹中没有类似的文件可以跳过该文件,任何人都可以知道这个问题



I am trying to download files from ftp server, its good while downloading when similar files are available in debug folder, if the similar file is not available in debug folder its skipping that file, can any one know about this problem

FtpWebRequest ftp;
                   ftp = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPAddress + file));
                   ftp.Credentials = new NetworkCredential(uID, pswrd);
                   ftp.KeepAlive = false;
                   ftp.Method = WebRequestMethods.Ftp.DownloadFile;
                   ftp.UseBinary = true;
                   ftp.Proxy = null;
                   ftp.UsePassive = false;
                   FtpWebResponse ftpR = (FtpWebResponse)ftp.GetResponse();
                   Stream responseStream = ftpR.GetResponseStream();
                   FileStream writeStream = new FileStream(".\\" + file, FileMode.Create);
                   int Length = 2048;
                   Byte[] buffer = new Byte[Length];
                   int bytesRead = responseStream.Read(buffer, 0, Length);
                   while (bytesRead > 0)
                   {
                       writeStream.Write(buffer, 0, bytesRead);
                       bytesRead = responseStream.Read(buffer, 0, Length);

                   }

推荐答案

我刚刚尝试了你的代码(稍微更改为可以使用我的ftp ):

I just tried your code (slightly changed to work with my ftp):
string file = @"0eeeab9f-0587-461b-b966-f12c033e704a.thumb.jpg";
string strConnect = @"ftp://[MyUsername]:[MyPassword]@ftp.Images.[MyDomain].com/Images/" + file;
FtpWebRequest ftp;
ftp = (FtpWebRequest)FtpWebRequest.Create(strConnect);
ftp.KeepAlive = false;
ftp.Method = WebRequestMethods.Ftp.DownloadFile;
ftp.UseBinary = true;
ftp.Proxy = null;
ftp.UsePassive = false;
FtpWebResponse ftpR = (FtpWebResponse)ftp.GetResponse();
Stream responseStream = ftpR.GetResponseStream();
FileStream writeStream = new FileStream(".\\" + file, FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
while (bytesRead > 0)
    {
    writeStream.Write(buffer, 0, bytesRead);
    bytesRead = responseStream.Read(buffer, 0, Length);
    }

(网站特定的东西被编辑并替换为[...])



它的工作原理无论文件是否存在于调试文件夹中都没关系。



那我在做什么你不是,反之亦然?

(The site specific stuff is redacted and replaced with [...])

It works fine regardless of whether the file exists in the debug folder or not.

So what am I doing that you aren''t, or vice versa?


这篇关于从FTP下载文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆