Try converting your SSH .ppk
(PuTTY Private Key File) to a .pem
key.
For that, you can use PuTTYgen, a tool that can convert keys to the required PuTTY format .ppk
.
Here’s a step-by-step guide:
- Open PuTTYgen and select Load.
- Change the file type to ‘All Files’.
- Browse and select the
.ppk
file. - Click
Save private key
and save it to the desired location. This would create a.ppk
file in the specified location. - Open the
.ppk
file with a text editor (such as Notepad++). - Select the text presented in the text editor and copy it.
- Open a new text document and paste the text copied from the
.ppk
file. - Save the text document with the extension
.pem
.
After converting the key from .ppk
to .pem
, try to use it with the FTP Scope activity (UiPath.FTP.Activities.2.4.0).
If the businesses have security concerns, such as handling the private key in an open manner, then consider using secure vaults or secure ways to handle private keys.
Alternately, if you are comfortable with coding, then you can make use of the SSH.NET library (a complete rewrite of SSH2 Client Library for .NET with many additional features), it supports SFTP downloads with the .ppk
file directly. However, it would require manual package import installation and also working with .NET code. You can use it within an Invoke Code (for C# or VB.Net)
activity in UiPath.
References:
How to convert a .ppk file into .pem to be used in FTP Activities.
Alternative solution
- Create a new Windows project. If you already installed the UiPath.FTP.Activities, remove it from the project.
- Install the SSH.NET.2024.1.0 from
https://api.nuget.org/v3/index.json
- In the UiPath Studio project, under the Imports panel add these references System.IO, Renci.SshNet, and Renci.SShNet.Sftp
- Add an Invoke Code activity for CSharp.
Note: Replace "path\to\key.ppk"
, "passphrase"
, "username"
, "hostname"
, "/remote/path/to/file.txt"
, and "C:\\local\\path\\to\\file.txt"
with your actual values.
Renci.SshNet.PrivateKeyFile keyFile = new PrivateKeyFile(@"path\to\key.ppk", "passphrase");
var keyFiles = new[] { keyFile };
var methods = new List<AuthenticationMethod>();
methods.Add(new PrivateKeyAuthenticationMethod("username", keyFiles));
ConnectionInfo con = new ConnectionInfo("hostname", "port", "username", methods.ToArray());
using (var client = new SftpClient(con))
{
client.Connect();
if (client.IsConnected)
{
// Specify the remote file path and the local file path
string remoteFilePath = "/remote/path/to/file.txt";
string localFilePath = @"C:\local\path\to\file.txt";
// Download the file
using (var fileStream = File.Create(localFilePath))
{
client.DownloadFile(remoteFilePath, fileStream);
}
}
// Perform your other actions...
client.Disconnect();
}
Note: If your private key does not have a passphrase, you can simply omit the passphrase parameter when creating the PrivateKeyFile
object. Here’s how you can adapt your code:
Renci.SshNet.PrivateKeyFile keyFile = new PrivateKeyFile(@"path\to\key.ppk", String.Empty);
var keyFiles = new[] { keyFile };
var methods = new List<AuthenticationMethod>();
methods.Add(new PrivateKeyAuthenticationMethod("username", keyFiles));
ConnectionInfo con = new ConnectionInfo("hostname", "port", "username", methods.ToArray());
using (var client = new SftpClient(con))
{
client.Connect();
if (client.IsConnected)
{
// Specify the remote file path and the local file path
string remoteFilePath = "/remote/path/to/file.txt";
string localFilePath = @"C:\local\path\to\file.txt";
// Download the file
using (var fileStream = File.Create(localFilePath))
{
client.DownloadFile(remoteFilePath, fileStream);
}
}
client.Disconnect();
}