Re: SSIS xml logging
I'm sending you an email with a development version of WinSCP to the address you have used to register on this forum.
Session
object is disposed.
Session
object.
</Session>
element at that point.
session.XmlLogPath
, but it doesn't seem to do anything. I've been through the documentation, and i very well could be missing something, but it looks like i am calling it write in the script.
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using WinSCP;
namespace ST_465ac362c5e347efa0c10d3f4d89aa7b
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
string winscpPath = Dts.Variables["winSCPPath"].Value.ToString();
string username = Dts.Variables["ftpUsername"].Value.ToString();
string password = Dts.Variables["ftpPassword"].Value.ToString();
string ftpSite = Dts.Variables["ftpSite"].Value.ToString();
int ftpPort = (int)Dts.Variables["ftpPort"].Value;
string localPath = Dts.Variables["localPath"].Value.ToString();
string remoteFTPDirectory = Dts.Variables["remoteFTPDirectory"].Value.ToString();
string fileMask = Dts.Variables["fileMask"].Value.ToString();
string sshKey = Dts.Variables["sshKey"].Value.ToString();
string xmlLogPath = Dts.Variables["xmlLogPath"].Value.ToString();
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = ftpSite,
UserName = username,
Password = password,
PortNumber = ftpPort,
SshHostKeyFingerprint = sshKey
};
try
{
using (Session session = new Session())
{
//Set XML Logging
session.XmlLogPath = xmlLogPath;
// WinSCP .NET assembly must be in GAC to be used with SSIS,
// set path to WinSCP.exe explicitly, if using non-default path.
session.ExecutablePath = winscpPath;
// Connect
session.Timeout = new TimeSpan(0, 2, 0); // two minutes
session.Open(sessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
try
{
session.GetFiles(remoteFTPDirectory + "/" +
fileMask, localPath, false, transferOptions);
}
catch (Exception e)
{
Dts.Events.FireError(0, null,
string.Format("Error when using WinSCP to download file: {0}", e), null, 0);
Dts.TaskResult = (int)DTSExecResult.Failure;
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
Dts.Events.FireError(0, null,
string.Format("Error when using WinSCP to download file: {0}", ex), null, 0);
Dts.TaskResult = (int)DT_S+e+x_ecResult.Failure;
}
}
#region ScriptResults declaration
/// <summary>
/// This enum provides a convenient shorthand within the scope of this class for setting the
/// result of the script.
///
/// This code was generated automatically.
/// </summary>
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DT_S+e+x_ecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DT_S+e+x_ecResult.Failure
};
#endregion
}
}