I want to get the size of a file on an FTP.
//Get File Size
reqSize = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpPath + filePath));
reqSize.Credentials = new NetworkCredential(Username, Password);
reqSize.Method = WebRequestMethods.Ftp.GetFileSize;
reqSize.UseBinary = true;
FtpWebResponse respSize = (FtpWebResponse)reqSize.GetResponse();
long size = respSize.ContentLength;
respSize.Close();
I have tried the following but get a 550 error. File not found / no access. However, the following code works...
reqTime = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpPath + filePath));
reqTime.Credentials = new NetworkCredential(Username, Password);
reqTime.Method = WebRequestMethods.Ftp.GetDateTimestamp;
reqTime.UseBinary = true;
FtpWebResponse respTime = (FtpWebResponse)reqTime.GetResponse();
DateTime LastModified = respTime.LastModified;
respTime.Close();
EDIT: The reason this isn't working for me is that my FTP Server does not support the SIZE method.
//Simplest and Efficient way to Get FTP File Size.
var size = GetFtpFileSize(new Uri("ftpURL"), new NetworkCredential("userName", "password"));
Try
reqSize.Method = WebRequestMethods.Ftp.GetFileSize;
instead of GetDateTimestampThis worked for me: