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(); 

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist