我正在使用以下代码上传文件,它可以正常工作,但有时会引发此错误“底层连接已关闭:服务器违反了协议”,并停止了该过程,当我再次运行该文件时,它没有任何问题地上传文件.
我注意到的一件事是,如果我运行此过程来上传多个文件,则有时会收到此错误;如果我的文件少于5个,则说明工作正常,不知道我在哪里以及要查看的内容.
我在google上搜索时,找不到任何可靠的解决方案,甚至一个msdn博客都说这是FTPwebrequest中的错误,但不确定.
环境:C#4.0,IIS FTP服务器.
提前致谢
FileInfo fileInf = new FileInfo(filename);
FtpWebRequest reqFTP;
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create
(new Uri(path + fileInf.Name));
// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(user, pwd);
// By default KeepAlive is true, where the control connection
// is not closed after a command is executed.
reqFTP.KeepAlive = false;
// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// Speci