Archived Forum Post

Index of archived forum posts

Question:

Can't open data connection for transfer of "/test.txt"

Sep 29 '17 at 01:51

Hi Team,

I am trying to upload one sample file to FTPs (TLS).

I am geeting below log error -

---------Upload Error  --------- ChilkatLog:
  PutFile:
    DllDate: Aug 30 2017
    ChilkatVersion: 9.5.0.69
    UnlockPrefix: Anything for 30-day trial
    Architecture: Little Endian; 32-bit
    Language: .NET 4.5
    VerboseLogging: 0
    RemoteFilename: test.txt
    LocalFilename: C:Testtest.txt
    ProgressMonitoring:
      enabled: yes
      heartbeatMs: 0
      sendBufferSize: 65536
    --ProgressMonitoring
    IdleTimeoutMs: 60000
    ReceiveTimeoutMs: 60000
    ConnectTimeoutSeconds: 30
    soRcvBuf: 4194304
    soSndBuf: 262144
    uploadFromLocalFile:
      localFileSize: 39
      uploadFromDataSource:
        initialGreeting: 220 PwC CFT FTP Server
        restartNext: 0
        modeZ: 0
        binaryMode: 1
        pbsz_protp:
          simpleCommand:
            sendCommand:
              sendingCommand: PROT P
            --sendCommand
            readCommandResponse:
              replyLineQP: 200 Protection level set to P
            --readCommandResponse
          --simpleCommand
        --pbsz_protp
        setupDataConnection:
          active transfer mode
          setupActiveDataSocket:
            Using ephemeral port range for Active data connection.
            dataPort: 60543
            portIpAddress: 172.22.64.87
            MyIPv4: 172,22,64,87,236,127
            sendCommand:
              sendingCommand: PORT 172,22,64,87,236,127
            --sendCommand
            readCommandResponse:
              replyLineQP: 200 Port command successful
            --readCommandResponse
          --setupActiveDataSocket
        --setupDataConnection
        sendUploadCommand:
          sendCommand:
            sendingCommand: STOR test.txt
          --sendCommand
        --sendUploadCommand
        completeDataConnection:
          acceptDataConnection:
            controlChannelReply:
              Reading intermediate response..
              readCommandResponse:
                replyLineQP: 150 Opening data channel for file upload to server of "/test.txt"
              --readCommandResponse
            --controlChannelReply
            controlChannelReply:
              Reading intermediate response..
              readCommandResponse:
                replyLineQP: 425 Can't open data connection for transfer of "/test.txt"
              --readCommandResponse
              Final response indicates error.
            --controlChannelReply
          --acceptDataConnection
          Failed to accept data connection.
        --completeDataConnection
        Failed to complete data connection.
      --uploadFromDataSource
      Failed.
    --uploadFromLocalFile
    TotalTime: Elapsed time: 10781 millisec
    Failed.
  --PutFile
--ChilkatLog


Code Snippet -

Chilkat.Ftp2 ftp = new Chilkat.Ftp2();

            bool success;

            //  Any string unlocks the component for the 1st 30-days.
            success = ftp.UnlockComponent("Anything for 30-day trial");
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                return ftp.LastErrorText;
            }

            //  If this example does not work, try using passive mode
            //  by setting this to true.
            ftp.Passive = false;
            ftp.Hostname = parameters.HostName;
            ftp.Username = parameters.UserName;
            ftp.Password = parameters.Password;
            ftp.Port = 20017;

            //  We don't want AUTH SSL:
            ftp.AuthTls = true;

            //  We want Implicit SSL:
            ftp.Ssl = false;

            //  Connect and login to the FTP server.
            success = ftp.Connect();
            if (success != true)
            {
                Console.WriteLine(ftp.LastErrorText);
                ftp.Disconnect();
                return ftp.LastErrorText;
            }
            else
            {
                //  LastErrorText contains information even when
                //  successful. This allows you to visually verify
                //  that the secure connection actually occurred.
                Console.WriteLine(ftp.LastErrorText);
                Console.WriteLine("FTPS Channel Established!");

                success = ftp.ChangeRemoteDir("/");
                if (success != true)
                {
                    return ftp.LastErrorText;//Directory Change Error.

                }
                else
                {
                    success = ftp.PutFile("C:\\Test\\test.txt", "test.txt");

                    if (success != true)
                    {
                        //ftp.Disconnect();
                        return  "---------Upload Error  --------- " + ftp.LastErrorText + "---" ;//Upload Error.
                    }
                    else
                    {
                        ftp.Disconnect();
                        return "File Uploaded sucessfully.";
                    }

                }

Answer

Did you try setting ftp.Passive to true? When set to false you are in active mode which often fails. In Active mode the FTP server will open a connection to your computer (an incoming connection) which often fails (firewalls). In Passive mode all connections are made by your program (outgoing connections to the FTP server). Firewalls normally won't object to that.