Syllaba Abou Ndiaye
Syllaba Abou Ndiaye

Reputation: 211

Uipath SFTP connection

l would like to use the "With Ftp session" component to configure my connection to the SFTP server, However instead of using password i am using a key file. But i always have this error when i try to connect

Exception screen

Here is my config:

Activity Config

Upvotes: 0

Views: 3755

Answers (1)

Ilya Kochetov
Ilya Kochetov

Reputation: 18463

The With FTP Session activity ignored the private key argument and always tried to connect with a password. The error you were getting were due to the SSH library receiving an unitialized password variable.

This is the update code for the Activities/FTP/UiPath.FTP/SftpSession.cs which adds PrivateKey authentication mechanism. I will contribute this fix to the Github meanwhile.

Note that you will have to clone and build https://github.com/UiPath/Community.Activities) for this to work.

 public SftpSession(FtpConfiguration ftpConfiguration)
    {
        if (ftpConfiguration == null)
        {
            throw new ArgumentNullException(nameof(ftpConfiguration));
        }

        ConnectionInfo connectionInfo = null;

        var auths = new List<AuthenticationMethod>();
        if (!String.IsNullOrEmpty(ftpConfiguration.Password))
        {
            auths.Add(new PasswordAuthenticationMethod(ftpConfiguration.Username, ftpConfiguration.Password));
        }

        if (!String.IsNullOrEmpty(ftpConfiguration.ClientCertificatePath)) {
            PrivateKeyFile keyFile = new PrivateKeyFile(ftpConfiguration.ClientCertificatePath, ftpConfiguration.ClientCertificatePassword);
            var keyFiles = new[] { keyFile };
            auths.Add(new PrivateKeyAuthenticationMethod(ftpConfiguration.Username, keyFiles));
        }

        if (auths.Count == 0)
        {
            throw new ArgumentNullException("Need to provide either private key or password");
        }

        if (ftpConfiguration.Port == null)
        {
            connectionInfo = new ConnectionInfo(ftpConfiguration.Host, ftpConfiguration.Username, auths.ToArray());
        }
        else
        {
            connectionInfo = new ConnectionInfo(ftpConfiguration.Host, ftpConfiguration.Port.Value, ftpConfiguration.Username, auths.ToArray());
        }

        _sftpClient = new SftpClient(connectionInfo);

    }

Upvotes: 0

Related Questions