I am currently having a problem where WebRequestMethods.Ftp.GetFileSize
is throwing an exception
File unavailable (eg, file not found, can not access the file)
I have researched the issue and read that the issue is occurring because my FTP server doesn't support the function. I later contacted my web server provider which they confirmed that the function is not supported unless I purchase one of their VPS plans (I am currently on shared hosting).
// get size of file
FtpWebRequest sizeRequest = (FtpWebRequest)WebRequest.Create("ftp://ftp.domain.com/test.txt");
sizeRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; // or GetFileSize();
sizeRequest.Credentials = new NetworkCredential("user", "password");
sizeRequest.UsePassive = true;
sizeRequest.UseBinary = true;
sizeRequest.KeepAlive = true;
int size = (int)sizeRequest.GetResponse().ContentLength;
My question is that are there solutions to the GetFileSize
method? I have looked into ListDirectoryDetails
. However since I only need one piece of data, I would need to parse the rest of the data which after looking into how to do that, It was going to take me a while to sufficiently understand what code I need to write since I am only a novice C# programmer.