I'm trying to get the file size from a remote FTP file through anonymous FTP.
public static long GetSize(string ftpPath)
{
try
{
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpPath));
request.Proxy = null;
request.Credentials = new NetworkCredential("anonymous", "´");
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.GetFileSize;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
long size = response.ContentLength;
response.Close();
return size;
}
catch (WebException e)
{
string status = ((FtpWebResponse)e.Response).StatusDescription;
MessageBox.Show(status);
return 0;
}
}
This currently returns the error "550 Size not allowed in ASCII mode." I'm aware that I have to use binary mode, but setting UseBinary
to true (see above) doesn't fix the issue.