D
D
Dima Avdoshin2021-12-09 10:05:21
FTP
Dima Avdoshin, 2021-12-09 10:05:21

How to read file size via FTP?

How to read file size via FTP? Every time I try to do this, I get 550 in response, the file type was not found, while other methods related to the date, for example, work and find it

//не работает
public long GetFileSize(string fileName) {
        var request = createRequest(combine(SERVER, fileName), WebRequestMethods.Ftp.GetFileSize);
        Console.WriteLine(combine(SERVER, fileName));
        using (var response = (FtpWebResponse)request.GetResponse()) {
            return response.ContentLength;
        }
    }
//работает нормально
public DateTime GetDateTimestamp(string fileName) {
        var request = createRequest(combine(SERVER, fileName), WebRequestMethods.Ftp.GetDateTimestamp);
      
        using (var response = (FtpWebResponse)request.GetResponse()) {
            return response.LastModified;
        }
    }

In the folder like the permissions are all worth it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ayazer, 2021-12-09
@D1m0nd

550 Requested action not taken. File unavailable (eg, file not found, no access). ( tyk )
there is SIZE, but it's not part of the ftp protocol, so not all servers support it (although in this case there should have been a different error code). maybe your ftp client is trying to send MLSD/LIST to get information about all files, and then extract the size of the one you need. And if the user does not have the right to do so, 550 looks plausible. those. unless you accidentally pass different filenames - this is NOT a problem with your code
In general - see ftp logs. If you don't have access to the server's admin console, look for the presence of a debug mode in the library itself. Ideally, you want to get a complete list of all requests/responses that are being sent. If this library can't do that, throw it away and take another one. We once settled on FluentFtp (although we had to contribute a little to finish the necessary feature in it), and it definitely has a debug mode
, and if you really want this particular library, but it doesn’t know how to debug, wireshark will help. it even has a ready-made filter for ftp, just remember that data and commands are sent on different ports

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question