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.
更多推荐
发布评论