Uploading File to SFTP using Key Authentication in SSIS

Advertisement

Ravindra Chate
Guest

Uploading File to SFTP using Key Authentication in SSIS

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.

Reply with quote

Advertisement

asher629
Joined:
Posts:
3
Location:
Mobile, AL

using private key for an SFTP connection from SSIS package

Martin, which of the following parameters named in the thread I am responding to, for an SFTP connection with a private key are mandatory: Host name, User name, Ssh Host Key Fingerprint, Ssh Private Key Path? Someone I need to send files to, and receive files from, gave me the host name and private key only. No fingerprint, no user name. Thank you

Reply with quote

asher629
Joined:
Posts:
3
Location:
Mobile, AL

using private key for an SFTP connection from SSIS package

Thank you, Martin. Will the attached image give you any clue as to what I did wrong in establishing a new connection? I will send an email to introduce myself, will post all the questions here. Thank you
  • time_out.JPG (88.79 KB, Private file)

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: using private key for an SFTP connection from SSIS package

Can you connect to that hostname using any SSH/SFTP client at all? Can you ping the host?

Reply with quote

Advertisement

You can post new topics in this forum