Unable to use new SessionOptions statement in SSIS Script Task

Advertisement

joerobbi
Guest

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 "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();
}
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,614
Location:
Prague, Czechia

Re: Unable to use new SessionOptions statement in SSIS Script Task

The exception has an inner exception for sure. What is it?

Reply with quote

joerobbi
Guest

Re: Unable to use new SessionOptions statement in SSIS Script Task

That's part of what's killing me; I can't seem to trap an exception from the Script task. Try/Catch and full logging for that task give the error log below.

I admit I'm no expert, so if there's another way to catch that inner exception, I'm all ears. :-)

------------Error Log---------------
OnPreValidate,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:23 AM,1/25/2018 8:45:23 AM,0,0x,
OnPostValidate,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:23 AM,1/25/2018 8:45:23 AM,0,0x,
OnError,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:24 AM,1/25/2018 8:45:24 AM,1,0x,Exception has been thrown by the target of an invocation.
OnTaskFailed,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:24 AM,1/25/2018 8:45:24 AM,0,0x,
OnPostExecute,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:24 AM,1/25/2018 8:45:24 AM,0,0x,

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,614
Location:
Prague, Czechia

Re: Unable to use new SessionOptions statement in SSIS Script Task

joerobbi wrote:

That's part of what's killing me; I can't seem to trap an exception from the Script task. Try/Catch and full logging for that task give the error log below.

I admit I'm no expert, so if there's another way to catch that inner exception, I'm all ears. :-)
I do not know SSIS much, so I cannot advice here.

Though did you follow this guide?
https://winscp.net/eng/docs/library_ssis
Particularly did you install the assembly to GAC?

Reply with quote

Advertisement

You can post new topics in this forum