550 Error When I try to get the size of a file on an FTP
- by Eric
I'm trying to use an FtpWebRequest to get the size of a file on a company FTP. Yet whenever I try to get the response an exception is thrown. See the error details in the catch block in the code below.
string uri = "ftp://ftp.domain.com/folder/folder/file.xxx";
FtpWebRequest sizeReq = (FtpWebRequest)WebRequest.Create(uri);
sizeReq.Method = WebRequestMethods.Ftp.GetFileSize;
sizeReq.Credentials = cred;
sizeReq.UsePassive = proj.ServerConfig.UsePassive; //true
sizeReq.UseBinary = proj.ServerConfig.UseBinary; //true
sizeReq.KeepAlive = proj.ServerConfig.KeepAlive; //false
long size;
try
{
//Exception thrown here when I try to get the response
using (FtpWebResponse fileSizeResponse = (FtpWebResponse)sizeReq.GetResponse())
{
size = fileSizeResponse.ContentLength;
}
}
catch(WebException exp)
{
FtpWebResponse resp = (FtpWebResponse)exp.Response;
MessageBox.Show(exp.Message); // "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
MessageBox.Show(exp.Status.ToString()); //ProtcolError
MessageBox.Show(resp.StatusCode.ToString()); // ActionNotTakenFileUnavailable
MessageBox.Show(resp.StatusDescription.ToString()); //"550 SIZE: Operation not permitted\r\n"
}
This code does work, however, when connected to my personal FTP. The StatusDescription of the response says that the operation is "not permitted". Could it be that my office FTP just wont allow for the querying of a file size?
I've also tried listing the directory details, which will return the size, and have noticed that my office FTP reports the directory details in a different format then my personal FTP. Maybe this is the problem?
//work ftp ListDirectoryDetails
-rw-r--r-- 1 (?) user 12345 Nov 16 20:28 some file name.xxx
//personal ftp ListDirectoryDetails
-rw-r--r-- 1 user user 12345 Mar 13 some file name.xxx
From reading this blog post I think that my personal ftp is returning a Unix formatted response, but my work is returning a windows formatted response. Maybe this is unrelated but I thought I'd mention it.