在FTP服务器中上传文件时遇到问题。当我在我的计算机上运行FileZilla服务器(127.0.0.1)时,图像文件会成功上传。但我在同一网络中的另一台计算机上运行FileZilla服务器。(10.0.0.25)。我可以在这台计算机上创建目录,但我无法上传图像文件,尽管我的用户对此计算机有完全控制权。
public bool Upload(Stream srcStream, string dstFilePath)
{
Create FtpWebRequest object from the Uri provided
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(serverUri + dstFilePath));
reqFTP.Credentials = credential;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false;
reqFTP.KeepAlive = false;
reqFTP.ContentLength = srcStream.Length;
byte[] buff = new byte[UPLOAD_DOWNLOAD_BUFFER_SIZE];
int contentLen;
// Stream to which the file to be upload is written
using (Stream dstStream = reqFTP.GetRequestStream())
{
// Read from the file stream 2kb at a time
contentLen = srcStream.Read(buff, 0, UPLOAD_DOWNLOAD_BUFFER_SIZE);
// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the FTP Upload Stream
dstStream.Write(buff, 0, contentLen);
contentLen = srcStream.Read(buff, 0, UPLOAD_DOWNLOAD_BUFFER_SIZE);
}
dstStream.Close();
}
}
// Get the response to the upload request.
bool ret;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
// ret = (response.StatusCode == FtpStatusCode.ClosingData); //
response.Close();
ret = (GetFileSize(dstFilePath) == srcStream.Length);
return ret;
}
当我将行9更改为reqFTP.UsePassive=true时,服务器返回(227进入被动模式(h1,h2,h3,h4,p1,p2))。现在它返回(500)语法错误,命令无法识别。会出现什么问题?感谢
我可以在防病毒软件运行时上传图像Filezilla。然而,当我使用我的代码块进行尝试时。它返回端口错误消息。防病毒程序停止后,一切正常。