Archived Forum Post

Index of archived forum posts

Question:

Getting Error when transferring file through FTPS (with TLS) though Connection to the server is being established.

Oct 06 '17 at 04:50

I am not able to transfer text file over FTPS (with TLS). I am able to establish connection with FTPS server. Able to change the directory, but whenever i am trying to upload the file i am getting below log error. I have given both code details as well as error log details. please help.

Below is my code snippet for transferring file through FTPS server.

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 = true;
            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
                {
                    //string localfilename = "\\hgsqlp14\\Transfer\\BI\\PWC-t\\test.txt";
                    //string remotefilename = "test.txt";

                    //byte[] dataBytes = ConvertToArray(fileStream);

                    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.";
                    }

                }
            }

The Error log got from Chilkat -

---------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:
          passive transfer mode
          setupPassiveDataSocket:
            sendCommand:
              sendingCommand: PASV
            --sendCommand
            readCommandResponse:
              replyLineQP: 227 Entering Passive Mode (172,31,120,157,19,203)
            --readCommandResponse
            dataConnect:
              hostname: 172.31.120.157
              port: 5067
              socket2Connect:
                connect2:
                  ConnectFailReason: Connection rejected
                  A few possible causes for a connection being rejected are:
                  - A firewall (software or hardware), such as Windows Firewall, is blocking the connection .
                  - Nothing is listening at the remote host:port
                --connect2
              --socket2Connect
              dataConnectSuccess: 0
            --dataConnect
            setupPassiveDataSocket dataConnect failed.
          --setupPassiveDataSocket
          Failed to setup passive data socket
        --setupDataConnection
        Failed to setup data connection for upload.
        readRepliesAfterFailedDataConn:
          readCommandResponse:
            Failed to read beginning of SSL/TLS record.
            b: 0
            dbSize: 0
            nReadNBytes: 0
            idleTimeoutMs: 1000
            Failed to receive more TLS application data.
            tlsApp: Socket operation timeout.
            elapsedMs: Elapsed time: 1031 millisec
            Failed to read FTP control channel reply.
            readFtpReply: Socket operation timeout.
          --readCommandResponse
        --readRepliesAfterFailedDataConn
      --uploadFromDataSource
      Failed.
    --uploadFromLocalFile
    TotalTime: Elapsed time: 22219 millisec
    Failed.
  --PutFile
--ChilkatLog



Answer

try put_PassiveUseHostAddr(true), see https://www.chilkatsoft.com/refdoc/vcCkFtp2Doc.html#prop65


Answer

No luck. I have tried this option. But same error I am getting.

In my code I am using different port(20017) rather than default port. I have set port number in my code. But in log I can see the different port 5067 like below.

Could you please let me know if that makes any issue.

dataConnect: hostname: 172.31.120.157 port: 5067 socket2Connect: connect2:


Answer

Hello, 5067 is the port used for data transfer. It seems that cannot arrive at 172.31.120.157 , port 5067. Maybe a local firewall or a remote firewall is locking connection. Try it disabling local firewall and local antivirus.

Regards,


Answer

See http://cknotes.com/determining-ftp2-connection-settings/

Also, try adding a rule to Windows Firewall that allows your app's executable (.exe) to pass. No need to disable the entire firewall just for testing.. :)


Answer

Hello, the port used for passive data transfer is established by the ftp server. In most of ftp servers you can set the port range used in passive transfers. In Windows 2008 R2 and above using IIS server for ftp server you can set port range. In Linux the majority of ftp servers you can set port range. Regards,


Answer

Hi David,

The FTP server to which I am connecting has opened port 20017 for data connection.

In the code using chilkat dll I have set the port to 20017. But in log it says that its trying to connect to the port no 5067.

Do you have any ideas regarding this.

Or is it something constraints of chilkat dll that it is not able override the port number.

Please suggest me.

Waiting for your reply.

Thanks, Sabari