本文介绍了需要C#代码才能使用代理从FTP服务器下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用beow C#代码从FTP下载文件。生成的文件包含错误文本。请让我知道如何解决错误。 错误消息 : < / H1 > < PRE > 200 类型 设置 我 。 200 PORT命令成功 。 550 / ftp 。 txt : 没有这样的 文件 或 目录 。 < / PRE > < / BODY > < / HTML > string file = " ftp.txt" ; string fileName = @ " D:\ Test \" +文件; FtpWebRequest downloadRequest =(FtpWebRequest)FtpWebRequest.Create( ftp:// ServerName +" / " + file); downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile; //downloadRequest.Credentials = new NetworkCredential(" UserName "," 密码 "); WebProxy myProxy = new WebProxy(); Uri newUri = new Uri( http:// ProxyName:ProxyPortNo ); //将newUri对象与'myProxy'对象相关联,以便可以设置新的myProxy设置。 myProxy.Address = newUri; //创建NetworkCredential对象并将其与请求对象的 // Proxy属性相关联。 myProxy.Credentials = new NetworkCredential(" USerName "," 密码 "," 域 " ); downloadRequest.Proxy = myProxy; FtpWebResponse response =(FtpWebResponse)downloadRequest.GetResponse(); 流responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); FileInfo downloadFile = new FileInfo(fileName); FileStream outputStream = new FileStream(fileName,FileMode.Append); 流ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int bufferSize = 4096; int readCount; byte [] buffer = new byte [bufferSize]; readCount = ftpStream.Read(buffer,0,bufferSize); MessageBox.Show(" 已连接 : 正在下载 档案 " ); while(readCount> 0) { outputStream.Write(buffer,0,readCount); readCount = ftpStream.Read(buffer,0,bufferSize); //Console.WriteLine(readCount.ToString()); } ftpStream.Close(); outputStream.Close(); response.Close(); MessageBox.Show(" 正在下载 完整 "); 谢谢, Saikat 解决方案 我正在使用beow C#代码从FTP下载文件。生成的文件包含错误文本。 错误消息:< / H1> < PRE> 200类型设置为I. 200 PORT命令成功。 550 /ftp.txt:没有这样的文件或目录。 < / PRE> < / BODY> < / HTML> string file =" ftp.txt" ;; string fileName = @" D:\Test \" +文件; FtpWebRequest downloadRequest =(FtpWebRequest)FtpWebRequest.Create( ftp:// ServerName +" /" + file); downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile; //downloadRequest.Credentials = new NetworkCredential(" UserName"," Password"); WebProxy myProxy = new WebProxy(); Uri newUri = new Uri( http:// ProxyName:ProxyPortNo ); //将newUri对象与'myProxy'对象相关联,以便可以设置新的myProxy设置。 myProxy.Address = newUri; //创建NetworkCredential对象并将其与请求对象的 // Proxy属性相关联。 myProxy.Credentials = new NetworkCredential(" USerName"," Password"," Domain"); downloadRequest.Proxy = myProxy; FtpWebResponse response =(FtpWebResponse)downloadRequest.GetResponse(); 流responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); FileInfo downloadFile = new FileInfo(fileName); FileStream outputStream = new FileStream(fileName,FileMode.Append); 流ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int bufferSize = 4096; int readCount; byte [] buffer = new byte [bufferSize]; readCount = ftpStream.Read(buffer,0,bufferSize); MessageBox.Show(" Connected:Downloading File"); while(readCount> 0) { outputStream.Write(buffer,0,readCount); readCount = ftpStream.Read(buffer,0,bufferSize); //Console.WriteLine(readCount.ToString()); } ftpStream.Close(); outputStream.Close(); response.Close(); MessageBox.Show(" Downloading Complete"); 谢谢, Saikat Hi,I am using the beow C# code for downloading the files from FTP. The file gets generated with error text which says. Please let me know how to resolve the error.error message : </H1><PRE>200 Type set to I.200 PORT Command successful.550 /ftp.txt: No such file or directory. </PRE></BODY></HTML> string file = "ftp.txt"; string fileName = @"D:\Test\" + file; FtpWebRequest downloadRequest = (FtpWebRequest)FtpWebRequest.Create(ftp://ServerName + "/" + file); downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile; //downloadRequest.Credentials = new NetworkCredential("UserName", "Password"); WebProxy myProxy = new WebProxy(); Uri newUri = new Uri(http://ProxyName:ProxyPortNo); // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set. myProxy.Address = newUri; // Create a NetworkCredential object and associate it with the // Proxy property of request object. myProxy.Credentials = new NetworkCredential("USerName", "Password","Domain"); downloadRequest.Proxy = myProxy; FtpWebResponse response = (FtpWebResponse)downloadRequest.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); FileInfo downloadFile = new FileInfo(fileName); FileStream outputStream = new FileStream(fileName, FileMode.Append); Stream ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int bufferSize = 4096; int readCount; byte[] buffer = new byte[bufferSize]; readCount = ftpStream.Read(buffer, 0, bufferSize); MessageBox.Show("Connected: Downloading File"); while (readCount > 0) { outputStream.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); //Console.WriteLine(readCount.ToString()); } ftpStream.Close(); outputStream.Close(); response.Close(); MessageBox.Show("Downloading Complete");Thanks,Saikat 解决方案 Hi,I am using the beow C# code for downloading the files from FTP. The file gets generated with error text which says.error message : </H1><PRE>200 Type set to I.200 PORT Command successful.550 /ftp.txt: No such file or directory. </PRE></BODY></HTML> string file = "ftp.txt"; string fileName = @"D:\Test\" + file; FtpWebRequest downloadRequest = (FtpWebRequest)FtpWebRequest.Create(ftp://ServerName + "/" + file); downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile; //downloadRequest.Credentials = new NetworkCredential("UserName", "Password"); WebProxy myProxy = new WebProxy(); Uri newUri = new Uri(http://ProxyName:ProxyPortNo); // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set. myProxy.Address = newUri; // Create a NetworkCredential object and associate it with the // Proxy property of request object. myProxy.Credentials = new NetworkCredential("USerName", "Password","Domain"); downloadRequest.Proxy = myProxy; FtpWebResponse response = (FtpWebResponse)downloadRequest.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); FileInfo downloadFile = new FileInfo(fileName); FileStream outputStream = new FileStream(fileName, FileMode.Append); Stream ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int bufferSize = 4096; int readCount; byte[] buffer = new byte[bufferSize]; readCount = ftpStream.Read(buffer, 0, bufferSize); MessageBox.Show("Connected: Downloading File"); while (readCount > 0) { outputStream.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); //Console.WriteLine(readCount.ToString()); } ftpStream.Close(); outputStream.Close(); response.Close(); MessageBox.Show("Downloading Complete");Thanks,Saikat 这篇关于需要C#代码才能使用代理从FTP服务器下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-28 11:47