FTP连接失败“无法连接到远程服务器”(FTP Connection Failing “Unable to connect to the remote server”)

编程入门 行业动态 更新时间:2024-10-25 02:20:12
FTP连接失败“无法连接到远程服务器”(FTP Connection Failing “Unable to connect to the remote server”)

我正尝试连接到FTP服务器以上载文件。 我收到“无法连接”错误。 如果我使用命令行并打开FTP连接,我可以连接。 不知道为什么我以编程方式连接时出现错误。 任何帮助肯定会被赞赏。

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://1.23.84.2"); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential("user","password"); // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader(path); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription); response.Close();

I am trying to connect to an FTP server to upload a file. I am getting the " Unable to connect" error. If I use command line and open an FTP connection, I am able to connect. Not sure why I get error when connecting programatically. Any help will surely be appreciated.

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://1.23.84.2"); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential("user","password"); // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader(path); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription); response.Close();

最满意答案

因此,经过几个小时的问题解决之后,McAfee就阻止了ftp端口。 必须暂时禁用本地机器上的服务。

So after a few hours of trouble shooting, It was McAfee blocking the ftp port. had to temporarily disable the services on a local machine.

更多推荐

本文发布于:2023-04-28 03:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1330256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   服务器   Connection   FTP   Failing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!