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.
Then look at the queue pane and below it (on the status bar) you should see a message indicating the queue size. Very good solution. This way, you can get the total number of files and the total size without Downloading any file. The FTP command used by Filezilla is MLSD (recursively) if anybody is curious about it.
public static long GetFtpFileSize(Uri requestUri, NetworkCredential networkCredential) { //Create ftpWebRequest object with given options to get the File Size. var ftpWebRequest = GetFtpWebRequest(requestUri, networkCredential, WebRequestMethods. Ftp. GetFileSize); try { return ((FtpWebResponse)ftpWebRequest.
Re: How can I view each file's size using FileZilla? The file size is displayed in the file size column for every file, aggregate size is displayed in the status bar below the file list.
Answer: There is not a limit on the size of the file. But keep in mind that the bigger the file the longer it will take to be transferred. However, either a ReadTimeout or OutOfMemory message may appear, depending on how many files are on the ftp server, and how large the files are.
Try reqSize.Method = WebRequestMethods.Ftp.GetFileSize;
instead of GetDateTimestamp
This worked for me:
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://servername/filepath"));
request.Proxy = null;
request.Credentials = new NetworkCredential("user", "password");
request.Method = WebRequestMethods.Ftp.GetFileSize;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
long size = response.ContentLength;
response.Close();
I tried to get file size while downloading it. Both, given answers doesn't work for me, so I made this, using StatusDescription property of FtpWebResponse with DownloadFile method:
int openingBracket = response.StatusDescription.IndexOf("(");
int closingBracket = response.StatusDescription.IndexOf(")");
var temporarySubstring = response.StatusDescription.Substring(openingBracket+1, closingBracket - openingBracket);
var fileSize = temporarySubstring.Substring(0, temporarySubstring.IndexOf(" "));
I suppose there is better way to do this with RegEx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With