With ftp session: Method not found: 'Void Renci.SshNet.PrivateKeyAuthenticationMethod..ctor(System.String, Renci.SshNet.PrivateKeyFile[])'

I am trying to upload files via SFTP, but unable to make connection and getting the following error:

With ftp session: Method not found: ‘Void Renci.SshNet.PrivateKeyAuthenticationMethod…ctor(System.String, Renci.SshNet.PrivateKeyFile)’.

In the properties panel, I have provided the required username, host, port and Private key file (openSSH key - under client certificate file), Use SFTP option is selected.

PS: I am using private key and not the password for connection.

Also, when trying to make connection using the above credentials in WinSCP everything works fine. This indicates that all the credentials and key file is correct. But somehow UiPath FTP activity is failing to authenticate. Not sure why, can anyone please suggest a solution for this?

Thanks in advance.

@kamna15

as a first resort did you happen to try to change the package version and check because as per error looks like some methods that are required are missing

may be a previous version or new version might have the same

also try to password protect the privatekey file and provide the password as well and check the same

basically UiPath uses the below…can try to use the below and check if it works directly

https://sshnet.github.io/SSH.NET/

password might be mandate as it checks for string or secure value to be present

cheers

1 Like

With WinSCP confirming that the access works in general,
and the assumption that the OpenSSH key format was properly extracted from WinSCP/Putty .ppk format:

example

The private key file must be in this format:

-----BEGIN OPENSSH PRIVATE KEY-----
…
-----END OPENSSH PRIVATE KEY-----

The extension is typically .pem or .key – but does not matter for this usecase.


I suggest to use the full path and filename

Whenever a file is used in an automation, I go 1 extra step and do not supply a string with the (relative) path/filename to any activity that expects a file.

Rather I always use a variable of type FileInfo, and then supply its property .FullName to the activity. Not only will that give an absolute path, but has the benefit:

Initializing a FileInfo (either by UiPath.Core.Activities.GetFileInfoX or in an Assign on the right side with new System.IO.FileInfo) a whole lot of extra properties and validation happens.

Used within a sequence or workflow I find a FileInfo has nothing but advantages. (I try to avoid to use it as a output argument as it might become too big in memory, but that is another topic.)

It is too easy to “loose” a file in C:\ or in .nuget or somewhere else. Not only key files, also .xlsx or .json or .csv: One extra step and .FullName is much more robust.

I recommend to place files with public or private keys in the Windows user’s .ssh directory:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh")

Because access to C:\ or C:\Temp is open to any user who may log onto the Robot, and an ITSec audit will make us LowCoders look amateurish.

Not sure if the path to the private key is the root cause of your problem, but one likely candidate.
And a minimal example project with the bare dependencies also works wonders.


Rounding off the secure FTP topic:

  • a private key file must never be stored in the process repo, no matter if protected by passphrase or not. Again, an ITSec scan of your repo will report this file very prominently.
  • in the UiPath ecosystem the key file can be stored securely as a credential in the Orchestrater in the “password” field as a base64 encoded string
  • then use InvokeMethod System.IO.File WriteAllBytes to write a on-the-fly casted credential into the filesystem

Convert.FromBase64String(new System.Net.NetworkCredential(String.Empty, SshKeyfileBase64).Password.ToString)

The InvokeMethod above is expected to write a file, beginning and ending with

-----BEGIN OPENSSH PRIVATE KEY-----
…
-----END OPENSSH PRIVATE KEY-----

How to convert text to base64?

  1. copy the text inside the ‘OpenSSH Private Key Format’ file into the clipboard
  2. convert
    a) use “C:\Program Files\PortableGit\git-bash.exe”: cat /dev/clipboard | base64
    b) use PowerShell: [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes((Get-Clipboard -Raw)))
  3. store in the Orchestrator credential as “password”
1 Like

Thanks Christian for such detailed answer.
It was really helpful.

Basically what worked for me:

  1. As suggested by you, I stored the private key out of the git repo folder (typically in c:).
  2. There was an extra dependency, so I removed the unused dependencies in my project. For me, the package SSH.net by Renci was the problem (not sure how it got added in my packages). It was creating the issue.

So, after the above two changes, I simply used FTP scope where I provided:

  1. Username (from credentials)
  2. Private key (.ppk file converted to openSSH key, path: stored in c:)
  3. host
  4. port
  5. use sftp enabled

and without any password it is now working.

Thanks Forum! :slight_smile:

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.