File Size via FTP
Is there a preferred way to obtain the size of a file stored on an FTP server using the 2.0 Framework?
The best I've come up with is to contact the FTP server via an FtpWebRequest object, with its .Method property set to WebRequestMethods.Ftp.GetFileSize.
This causes the size to be returned in the FtpWebResponse object's StatusDescription property. But its preceded by the Status Code value, so I have to parse the StatusDescription to obtain the file size.
That's no big deal. But oddly, the FtpWebResponse object has properties that return the parsed value of replies such as the file's date of last modification. But it does not, as far as I can tell, handle file sizes.I've looked at other ways to connect to FTP sites, such as the WebClient class, and My.Computer.Network. But neither of these seem to offer anything better.
Suggestions?
Karen
One other suggestion for the Framework team -- please synchronize the names of the FTP methods and properties.
For example, to retrieve the date of last modification of a file on an FTP server, the FtpWebRequest's method property must be set to:
WebRequestMethods.Ftp.GetDateTimestamp
But the returned value is stored in the FtpWebResponse object's property named:.LastModified
Likewise, to retrieve a file's size, you use this value for the FtpWebRequest object's Method property:
WebRequestMethods.Ftp.GetFileSize
while the corresponding property in the response object is:
ContentLength
What's more, the ContentLength property appears to be overloaded (can you overload a property?). It can mean the length of the stream returned in response to a request. But in the special case of the .GetFileSize method, it returns the size of the remote file, not the length of the FTP server's response. :(
How about a .FileSize response property? And a .DateTimestamp property? Or a .GetLastModified method value?
Karen