FluentFTP: Failed to open file after using DownloadFile

Hi,

trying to download a 100MB+ file from a plain FTP server and getting the below error (after listing directory contents and confirming that the file exists)

FluentFTP.FtpCommandException: Failed to open file. at FluentFTP.FtpClient.OpenActiveDataStream(FtpDataConnectionType type, String command, Int64 restart) at FluentFTP.FtpClient.OpenDataStream(String command, Int64 restart) at FluentFTP.FtpClient.OpenRead(String path, FtpDataType type, Int64 restart)

What causes this?

I’ve had many weird errors, such that the directory list returns 0 items when in “AutoActive” mode, but returns 28 items (correct) in AutoPassive.

To download the file, I then disconnect and re-connect to switch to AutoActive, as AutoPassive on downloading gives the following:

FluentFTP.FtpException: Failed to get the EPSV port from: Switching to ASCII mode. at FluentFTP.FtpClient.OpenPassiveDataStream(FtpDataConnectionType type, String command, Int64 restart) at FluentFTP.FtpClient.OpenDataStream(String command, Int64 restart) at FluentFTP.FtpClient.OpenRead(String path, FtpDataType type, Int64 restart)

the “FEAT” returns in the tracing for the FTP server:

Response: 230 Login successful. Command: FEAT Response: 211 End Response: 211-Features: Response: EPRT Response: EPSV Response: MDTM Response: PASV Response: REST STREAM Response: SIZE Response: TVFS Status: Text encoding: System.Text.UTF8Encoding+UTF8EncodingSealed Command: OPTS UTF8 ON Response: 501 Option not understood. Command: SYST Response: 215 UNIX Type: L8

I don’t own or control the FTP server, but have no issues downloading files in WinSCP or Filezilla, so doubt the issue is there.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

Hi @hgupta9

using (var remoteFileStream = _ftpClient.OpenRead(remotePath, FtpDataType.Binary))
{
    using (var newFileStream = File.Create(localPath))
    {
        byte[] buffer = new byte[8 * 1024];
        int len;

        while ((len = remoteFileStream.Read(buffer, 0, buffer.Length)) > 0)
        {
            newFileStream.Write(buffer, 0, len);
        }
    }
}

Please call GetReply() at end to read the FTP response. Else there will be other issues. If this does not work for your server then skip it.

Dear Developer,

This OpenRead & OpenWrite is really turning into a problem. I got everything working properly for a while now, but simply trying to Duplicate a file like this throws nothing but Errors… no matter the FtpDataConnectionType i use… It is quite inconsistent, works for 1 File fails for the Next one etc… Always get “Failed to get the EPSV port” or “Malformed PASV response” or “Bad Sequence of Commands” “Connection Timed out” or something alike. The code is the same as with #wernerbarnard above. Mind you, ussually the data was transferred though … The file on the other end is complete and works. Only when trying to access it again over FTP it throws the error of an Incomplete File.

FYI I am using the latest Version: 19.1.2

Please Help …