FTP是通过网闸访问的,用资源管理器可以直接连上FTP并操作,但用C#的类访问则返回无法识别的命令,该类在不通过网闸访问FTP是都是正常的。
通过网闸访问时执行到(FtpWebResponse)Request.GetResponse();时抛出异常:“远程服务器返回错误: (500) 语法错误,无法识别命令。” ,求解
异常方法如下:
/// <summary> 建立FTP链接,返回响应对象 </summary>
/// <param name="uri">FTP地址 传入值:"ftp://10.0.0.1/DownLoad/" </param>
/// <param name="FtpMathod">操作命令 传入值:"LIST" </param>
private FtpWebResponse Open(Uri uri, string FtpMathod)
{
try
{
Request = (FtpWebRequest)WebRequest.Create(uri);
Request.Method = FtpMathod;
Request.UseBinary = true;
Request.Credentials = new NetworkCredential(this.UserName, this.Password);
if (this.Proxy != null)
{
Request.Proxy = this.Proxy;
}
return (FtpWebResponse)Request.GetResponse();
}
catch (Exception ep)
{
ErrorMsg = ep.ToString();
throw ep;
}
}
通过网闸访问时执行到(FtpWebResponse)Request.GetResponse();时抛出异常:“远程服务器返回错误: (500) 语法错误,无法识别命令。” ,求解
异常方法如下:
/// <summary> 建立FTP链接,返回响应对象 </summary>
/// <param name="uri">FTP地址 传入值:"ftp://10.0.0.1/DownLoad/" </param>
/// <param name="FtpMathod">操作命令 传入值:"LIST" </param>
private FtpWebResponse Open(Uri uri, string FtpMathod)
{
try
{
Request = (FtpWebRequest)WebRequest.Create(uri);
Request.Method = FtpMathod;
Request.UseBinary = true;
Request.Credentials = new NetworkCredential(this.UserName, this.Password);
if (this.Proxy != null)
{
Request.Proxy = this.Proxy;
}
return (FtpWebResponse)Request.GetResponse();
}
catch (Exception ep)
{
ErrorMsg = ep.ToString();
throw ep;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货