SSIS WinSCP C# 脚本任务正在运行但不执行任何操作 [英] SSIS WinSCP C# script task running but not doing anything
本文介绍了SSIS WinSCP C# 脚本任务正在运行但不执行任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码没有抛出任何错误,但它根本没有做任何事情.
My code is not throwing any error but it is not doing anything at all.
我正在尝试连接到 SFTP 服务器,任务本身没有显示任何错误,但它没有访问/获取存储在特定目录中的文件.
I'm trying to connect to a SFTP server, the task itself is not showing any error but it is not accessing/getting the file stored in a specific directory.
图片:
这是我的代码:
#region Namespaces
using System;
using Microsoft.SqlServer.Dts.Tasks;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Linq;
using WinSCP;
#endregion
namespace ST_t5fbgt5564cf3a165da70892d8c435v
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public int Main()
{
try
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
UserName = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Password = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
PortNumber = xx
};
using (Session session = new Session())
{
session.Open(sessionOptions);
const string remotePath = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const string localPath = @"C:\xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
RemoteDirectoryInfo directoryInfo = session.ListDirectory(remotePath);
RemoteFileInfo latest =
directoryInfo.Files
.Where(file => !file.IsDirectory)
.OrderByDescending(file => file.LastWriteTime)
.FirstOrDefault();
if (latest == null)
{
throw new Exception("No found");
}
session.GetFiles(
RemotePath.EscapeFileMask(latest.FullName), localPath).Check();
}
return 0;
}
catch (Exception e)
{
Console.WriteLine("Error: (0)", e);
return 1;
}
}
#region ScriptResults declaration
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
我的代码有什么问题吗?我错过了什么吗?
Is anything wrong with my code? am i missing anything?
编辑#2
我能够打印日志消息,这是错误:
I was able to print log messages and this is the error:
Error: Error: WinSCP.SessionLocalException: The version of C:\Program Files (x86)\WinSCP\winscp.exe (5.15.3.0) does not match version of this assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WinSCPnet\v4.0_1.7.2.11087__2271ec4a3c56d0bf\WinSCPnet.dll (5.17.10.0).
in WinSCP.ExeSessionProcess.CheckVersion(String exePath, FileVersionInfo assemblyVersion)
in WinSCP.ExeSessionProcess..ctor(Session session, Boolean useXmlLog, String additionalArguments)
in WinSCP.Session.Open(SessionOptions sessionOptions)
in ST_2u7fsdf8fdsfkjgd998fsdf9ss.ScriptMain.Main()
推荐答案
您问题的实际答案是:做一些日志记录!
The actual answer to your question is: Do some logging!
查看 WinSCP SSIS 示例:
将 try
/catch
放在整个代码中并记录所有异常:
Put try
/catch
around your whole code and log all exceptions:
try
{
// The code
}
catch (Exception e)
{
Dts.Events.FireError(
0, null, $"Error when using WinSCP to upload files: {e}", null, 0);
}
这篇关于SSIS WinSCP C# 脚本任务正在运行但不执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文