【问题标题】:SSIS WinSCP C# script task running but not doing anythingSSIS WinSCP C# 脚本任务正在​​运行但不执行任何操作
【发布时间】:2021-07-01 15:46:30
【问题描述】:

我的代码没有抛出任何错误,但它根本没有做任何事情。

我正在尝试连接到 SFTP 服务器,任务本身没有显示任何错误,但它没有访问/获取存储在特定目录中的文件。

图片:

这是我的代码:

#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

    }
}

我的代码有什么问题吗?我错过了什么吗?


编辑:


编辑#2

我能够打印日志消息,这是错误:

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()

【问题讨论】:

    标签: c# ssis sftp winscp script-task


    【解决方案1】:

    您的问题的实际答案是:做一些记录!

    WinSCP SSIS example

    • 经常使用Dts.Events.FireInformation

    • try/catch 放在整个代码周围并记录所有异常:

      try
      {
          // The code
      }
      catch (Exception e)
      {
          Dts.Events.FireError(
              0, null, $"Error when using WinSCP to upload files: {e}", null, 0);
      }
      

    【讨论】:

      【解决方案2】:

      我能够通过下载正确版本的应用程序来解决这个问题。

      谢谢大家!

      【讨论】:

        猜你喜欢
        • 2014-03-09
        • 2013-04-10
        • 1970-01-01
        • 1970-01-01
        • 2012-09-20
        • 2022-06-23
        • 2015-09-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多