ftp服务器显示503,NET FTP Response error:(503) 的解决方法

1. 在应用。NET 访问FTP的Response来返回时,出现了如下错误。

da3d050601bdda21cd4701eac81534a1.png

2. 参考如下MSDN 和一些网络资源,尝试后解决了此问题.

> Ftp GetFileSize randomly throws FTP error 503 (Bad Sequence of

Commands)

>FtpWebRequest re-sending USER and PASS commands half way through

download loop

3. 问题是在此处应用此个FTP Request 之前曾经使用些地址创建了一个登录Session,

所以在后面同一地址会话建立时会有这个异常报告。

The remote server returned an error: (503) Bad sequence of commands.

解决办法就是将 request 对象的 KeepAlive 设为 False,其后基于同一IP创建的Session将不会抛出异常了。

FtpWebRequest reqFTP;

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(sUnixURL));//"ftp://"

+ "10.2.159.69" + "/" + fileInf.Name));

reqFTP.Credentials = new NetworkCredential("dwei", "Admin98");

reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;

reqFTP.UseBinary = true;

reqFTP.KeepAlive = false; // If keepalive is true will make the same IP

request response lead to failed !

FileStream outputStream = new FileStream(FILE_NAME, FileMode.Create);

// Create the writer for data.

BinaryWriter w = new BinaryWriter(outputStream);

FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值