Unable to use new SessionOptions statement in SSIS Script Task
I'm attempting to use the WinSCP assembly for the first time in SSIS, and I can't seem to get it to work (code below). The Script task fails each time with that useless "Exception has been thrown by the target of an invocation" error. Starting at the bottom and incrementally commenting out code, it doesn't start running until I comment out the
Actual Code (servers/filenames redacted):
SessionOptions soOpt = new SessionOptions
lines. WinSCP is installed, and I've added the assembly as a Reference on the task, but no joy. Any help would be very much appreciated!
Actual Code (servers/filenames redacted):
using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; using WinSCP; public void Main() { SessionOptions soOpt = new SessionOptions { Protocol = Protocol.Sftp ,SshHostKeyFingerprint = "ssh-rsa 2048 00:00..." ,HostName = "server.company.com" ,UserName = "UserName" ,SshPrivateKeyPath = @"X:\Directory\Key_Private.ppk" }; using (Session seNew = new Session()) { seNew.ExecutablePath = @"E:\Program Files (x86)\WinSCP\winscp.exe"; seNew.Open(soOpt); TransferOptions xfrOptions = new TransferOptions(); xfrOptions.TransferMode = TransferMode.Binary; TransferOperationResult xfrResult; xfrResult = seNew.GetFiles(@"/home/UserName/file.txt", @"X:\Directory\file.txt", false, xfrOptions); xfrResult.Check(); } }