I am in the process of writing an FTP client in .NET 2.0. During the testing of getFileSize, I have come across a strange and confusing error. I have a test directory of over 200+ files that I was testing this on, and for every file in this directory this method worked fine EXCEPT on files with an exact size of 17227 bytes. When I call this method on a file of this size I get the WebException with the message of:
"The remote server returned an error: 213 1722_"
Well, as you can see the 213 File Status response is fine except that the last '7' in the size is now a '_' .....
Let me say again, this method worked on every file in the test directory except files of size 17227 bytes. WTF
Any ideas anyone
public long getFileSize(string remoteFilePath)
{
long fileSize = 0;
try
{
//Set connection properties
ftpRequest =
(FtpWebRequest)FtpWebRequest.Create(new Uri(remoteFilePath));
ftpRequest.Credentials = new NetworkCredential(userName, password);
ftpRequest.UseBinary = useBinary;
ftpRequest.UsePassive = usePassive;
ftpRequest.KeepAlive = keepAlive;
ftpRequest.Proxy = null;
//Set command
ftpRequest.Method = WebRequestMethods.Ftp.GetFileSize;
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
Stream ftpStream = response.GetResponseStream();
fileSize = response.ContentLength;
ftpStream.Close();
response.Close();
}
catch
{
throw;
}
return fileSize;
}