无法将文件上传到ftp这是我的代码....
string filename = Path.GetFileName(source);
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(ftp + ftpFolder + filename);
request.Credentials = new NetworkCredential("username", "password");
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Proxy = new WebProxy();
FileStream fs = File.OpenRead(source);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = request.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
File.Delete(source);
始终在GetRequestStream()
发生错误,命令无法识别...如何克服此错误?
任何帮助将不胜感激....
答案 0 :(得分:0)
添加这两行
request.KeepAlive = false;
request.UsePassive= false;
然后,如果它不工作,请检查您的防病毒软件是否阻止FTP