Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

jpantera

Perl Script SFTP Downloads with .Net Assembly and SSH Key Authentication and Non-Blank Passphrase

Hello Martin & WinSCP Support Forum,

Question related to the .Net Assembly usage, and some Perl scripts I have written and support.

Specifically this page in the WinSCP documentation:
https://winscp.net/eng/docs/library_perl

And this section on that page (uses a username and an SFTP password):

use Win32::OLE;
use Win32::OLE::Const;
use Win32::OLE::Variant;

Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
my $session = Win32::OLE->new('WinSCP.Session');

my $consts = Win32::OLE::Const->Load($session);

my $sessionOptions = Win32::OLE->new('WinSCP.SessionOptions');

$sessionOptions->{'Protocol'} = $consts->{'Protocol_Sftp'};
$sessionOptions->{'HostName'} = 'example.com';
$sessionOptions->{'UserName'} = 'user';
$sessionOptions->{'Password'} = 'mypassword';

$sessionOptions->{'SshHostKeyFingerprint'} = 'ssh-rsa 2048 xxxxxxxxxxx...';

I use this method quite frequently on SFTP accounts where I am forced to use username & password. But we prefer to use SSH keys and a secure passphrase, which up until now, I've limited myself to using within a winscp.com script file automation, where my Perl script builds the SFTP processes "on the fly". This also limits me somewhat, as I like the .Net Assembly's ability to query files and their properties, on the remote SFTP server, as opposed to trying to "grab all files" to copy onto my server, and ferret through them there, some of which would be better served querying remotely.

Can you please provide the "$sessionOptions" from that type of script, we would use, and example(s), so we could use the .Net Assembly with our SSH key with passphrase, authenticated accounts? (like we use slightly different parameters for such, when we build the winscp.com script-file automation).

Or if there is a reason that can't work, or is more complicated, please explain.

Thanks you!

- Joe P.