每当我尝试从此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。
答案 0 :(得分:-1)
切换到" UsePassive"如你所说,它返回"语法错误,命令无法识别"。这意味着你的语法错误,导致你不在这里公开完整的源代码,所以我无法弄清楚。