devxlogo

Get the Size of a File in FTP with C#

Get the Size of a File in FTP with C#

Using the System.Net.WebRequestMethods.FTP class, we can use the “SIZE” FTP Protocol method to get the size of the file in FTP. Below is an example in C#:

var request = (FtpWebRequest)FtpWebRequest.Create(ftpUrl);request.Credentials = new NetworkCredential("username", "password");request.KeepAlive = false;//Use the GetFileSize FILE SIZE Protocol methodrequest.Method = WebRequestMethods.Ftp.GetFileSize;request.UseBinary = true;FtpWebResponse response = (FtpWebResponse)request.GetResponse();fileSize = response.ContentLength;response.Close();request.Abort(); 

devx-admin

Share the Post: