本文介绍了如何从Ftp服务器下载.dll文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好朋友, 我想直接从FTP服务器下载.dll文件到我的本地系统。如何使用C#来做到这一点。 我尝试使用下面的代码,但我得到例外,例如无法从传输连接读取数据:现有连接被远程主机强行关闭。 Uri url = new Uri(@ftp://+ ftpServerIP); if(url.Scheme == Uri.UriSchemeFtp ) { FtpWebRequest objRequest =(FtpWebRequest)FtpWebRequest.Create(url); //如果需要设置凭证,否则请注释此凭据代码 NetworkCredential objCredential = new NetworkCredential(ftpUserID,ftpPassword); objRequest.Credentials = objCredential; objRequest.UsePassive = true; objRequest.UseBinary = true; objRequest.KeepAlive = false; //objRequest.ProtocolVersion = HttpVersion.Version10; objRequest.Ser vicePoint.ConnectionLimit = 1; objRequest.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse objResponse =(FtpWebResponse)objRequest.GetResponse(); StreamReader objReader = new StreamReader(objResponse.GetResponseStream()); byte [] buffer = new byte [16 * 1024]; int len = 0; FileStream objFS =新的FileStream(strMainPath +\\\\ _7.dll,FileMode.Create,FileAccess.Write,FileShare.Read); while((len = objReader.BaseStream.Read(buffer,0,buffer.Length))!= 0) { objFS.Write(buffer,0,len); } objFS.Close(); objResponse.Close(); } 请帮帮我。解决方案 您可以使用edtFTPnet开源dll将文件从FTP下载到您的计算机。创建与FTP的连接,稍后您可以使用C#代码从FTP上传,下载和删除文件。 您可以在谷歌上搜索获取Dll。 Hello friends,I want to download .dll file directly from FTP server to my local system. how to do it by using C#.I trying by using below code but i got exception like "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host." Uri url = new Uri(@"ftp://" + ftpServerIP); if (url.Scheme == Uri.UriSchemeFtp) { FtpWebRequest objRequest = (FtpWebRequest)FtpWebRequest.Create(url); //Set credentials if required else comment this Credential code NetworkCredential objCredential = new NetworkCredential(ftpUserID, ftpPassword); objRequest.Credentials = objCredential; objRequest.UsePassive = true; objRequest.UseBinary = true; objRequest.KeepAlive = false; //objRequest.ProtocolVersion = HttpVersion.Version10; objRequest.ServicePoint.ConnectionLimit = 1; objRequest.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse objResponse = (FtpWebResponse)objRequest.GetResponse(); StreamReader objReader = new StreamReader(objResponse.GetResponseStream()); byte[] buffer = new byte[16 * 1024]; int len = 0; FileStream objFS = new FileStream(strMainPath + "\\7z.dll", FileMode.Create, FileAccess.Write, FileShare.Read); while ((len = objReader.BaseStream.Read(buffer, 0, buffer.Length)) != 0) { objFS.Write(buffer, 0, len); } objFS.Close(); objResponse.Close(); }please help me. 解决方案 Hi,You can use edtFTPnet open source dll to download file from FTP to your computer. create a connection to FTP and later you can upload, download, delete a file from FTP using your C# code.You can search on google to get the Dll. 这篇关于如何从Ftp服务器下载.dll文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-30 06:39