Click here to Skip to main content
15,921,203 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Why I am unable to connect to SFTP using Rebex in Windows server?
C#
        SftpConnectionState IsActive = null;
        IsActive = uSftp.GetConnectionState();
        //End
        WriteLog("SFTP_Download() : Connecting Sftp:" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss:fff"));

        string[] sSFTPHost = ConfigurationManager.AppSettings["SFTPHost"].Split('|');
        if (copyAction == "U")
        {

            //Added  on 18.8.2015 for Rebex
             if (IsActive.Connected == false)
             {
                 uSftp.Connect(sSFTPHost[0], Convert.ToInt32(sSFTPHost[1]));
                 uSftp.Login(sSFTPHost[2], sSFTPHost[3]);

            }
            //End
        }
        else
        {
            //Added  on 18.8.2015 for Rebex
            if (IsActive.Connected == false)
            {
                uSftp.Connect(sSFTPHost[0], Convert.ToInt32(sSFTPHost[1]));
                uSftp.Login(sSFTPHost[2], sSFTPHost[3]);

            }
            //End
        }
    }
    catch (Exception ex)
    {
        WriteLog("SFTP_Download() :Exception while connecting sftp:Exception:"+ex.Message.ToString() + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss:fff"));
        throw new System.Exception("ConnectSftp(): " + ex.Message);
    }
}
Posted
Comments
Sinisa Hajnal 19-Aug-15 4:33am    
What happens? You just said you cannot connect, but not what error (and line) you get.
Also, your if with copyaction does the same thing in both branches and can be removed, leave just isactive.connected == false part
sreeyush sudhakaran 19-Aug-15 5:04am    
what is the error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900