【发布时间】:2018-01-21 00:47:17
【问题描述】:
每当我尝试从这个 ftp 服务器下载文件时,我都会收到此错误:
System.Net.WebException: 'The remote server returned an error: 227 Entering Passive Mode (37,60,247,183,135,216)
public static main(string[] args){
FtpWebRequest ftpRequest = null;
FtpWebResponse ftpResponse = null;
ftpRequest = (FtpWebRequest)FtpWebRequest.Create("ftp://ftp.autoherosrpg.com/hash.xml");
ftpRequest.Credentials = new NetworkCredential("game@autoherosrpg.com", "*********");
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = false;
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
ftpResponse = (FtpWebResponse) ftpRequest.GetResponse();
}
但即使我将“UsePassive”切换为 false,我也会得到:
public static main(string[] args){
FtpWebRequest ftpRequest = null;
FtpWebResponse ftpResponse = null;
ftpRequest = (FtpWebRequest)FtpWebRequest.Create("ftp://ftp.autoherosrpg.com/hash.xml");
ftpRequest.Credentials = new NetworkCredential("game@autoherosrpg.com", "*********");
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = false;
ftpRequest.KeepAlive = false;
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
ftpResponse = (FtpWebResponse) ftpRequest.GetResponse();
}
System.Net.WebException: 'The remote server returned an error: (500) Syntax error, command unrecognized.'
这是我第一次尝试通过 C# 连接到 ftp 服务器。此连接适用于任何 ftp 客户端和浏览器
更新: FTP 服务器目前不支持 TLS。一旦我让这段代码在没有加密的服务器上工作,我将修改代码以使用 TLS。
【问题讨论】:
-
您能否使用运行 C# 代码的同一台计算机上的任何独立 FTP 客户端连接到 FTP 服务器?向我们展示它的日志文件。
-
是的,我可以。我在帖子的最后说过,如果我厌倦了任何 ftp 客户端或浏览器,我可以连接到 ftp 服务器。我可以发布日志文件
-
那是无用的日志。它不显示 FTP 协议脚本。它是服务器端日志吗?向我们展示详细客户端日志。