Re: Unable to use new SessionOptions statement in SSIS Script Task
This all is already documented:
static
script. By loading the path of the WinSCP.dll, and it worked.
static ScriptMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("WinSCPnet"))
{
string path = @"C:\Program Files (x86)\WinSCP";
return Assembly.LoadFile(Path.Combine(path, "WinSCPnet.dll"));
}
return null;
}
------------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,
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!
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();
}
}