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;



//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;








return fileSize;


Re: .NET Framework Networking and Communication FTP GetFileSize Confusing Problem


Does it do the same thing with another file of the exact same size, but a different name What about for larger files

Re: .NET Framework Networking and Communication FTP GetFileSize Confusing Problem


No matter what the name it gives the error. Bigger files, smaller files work fine. I created a test .txt file after coming across this error that was 17227 bytes in size and the method throw an exception. Made the file one byte bigger and the method worked. Turns out that ANY size ending with '227' causes a problem.