Reputation: 71
I have a problem while uploading a file in FTP server. When i run FileZilla server on my computer(127.0.0.1), the image files are succesfully uploaded. But i run FileZilla server on another computer in the same network.(10.0.1.25). I can create directories on this computer but i cannot upload the image file although my user have full control on this computer.
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;
}
When i change the line 9 to reqFTP.UsePassive = true, the server returns the (227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)). Now it returns (500) Syntax error, command unrecognized. What will the problem? Thanks
Upvotes: 2
Views: 643
Reputation: 71
I can upload image Filezilla while antivirus is running. However when i try it by using my code block. It returns port error message. After antivirus is stopped, everything works well.
Upvotes: 0