Topic "Uploading File to SFTP using Key Authentication in SSIS"

Author Message
Ravindra Chate

Guest


Hi,

I want to upload file to SFTP using private key authentication. So i wrote below code in SSIS Script Task. Can you please suggest this much code is enough for the same or am i missing anything ?. Thanks in advance for your valuable answers.

SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = sftpHostName, //Destination server to which we need to connect to
UserName = sftpUserId, //Destination server UserId (or Source server user id?)
SshHostKeyFingerprint = sftpHosyKeyFingerPrint,
SshPrivateKeyPath = sftpPrivateKeyPath //Entire physical path that maps to .ppk private key (Eg: C:\PrivateKey\SFTPKey.ppk)
};


//Start Session
using (Session session = new Session())
{
session.ExecutablePath = executablePath;
session.Open(sessionOptions);
// Upload files

TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = session.PutFiles(fileToUpload, sftpDestinationServerPath, false, transferOptions);

// Throw on any error
transferResult.Check();
}










Also put query on the WinSCP site forum and put the below code [2] in there to check if this code will be good enough for authentication and file transfer using private-public key? Or else additional coding is required for key authentication.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Your code looks good. Is there any problem?
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License