通过SSIS连接到SFTP

问题描述 投票:3回答:2

我正在尝试通过SFTP程序包连接到SSIS服务器。程序包使用WinSCP文件中的以下连接字符串执行.txt

open sftp://username:fc$#[email protected]:22

但是,该软件包一直无法连接而失败。与密码中的特殊字符有关吗?

如果替换字符串,我能够连接到其他SFTP,所以我知道这一定与上面的语法有关。我尝试如下将双引号引起来,但没有成功:

open "sftp://username:fc$#[email protected]:22"
ssis sftp winscp ssis-2012
2个回答
4
投票

最近我的一个工作项目我也必须这样做。我们在SSIS脚本任务中使用了WinSCP .NET程序集,因为WinSCP也建议将其作为在SSIS中使用WinSCP来实现SFTP的方法。

请参见本指南-Using WinSCP .NET Assembly from SQL Server Integration Services (SSIS)。它会引导您完成安装和设置,并包含有效的示例代码(当然,在您根据需要更改脚本之后!)。

示例代码-在引用WinSCPnet.dll程序集后-在下面。

using System;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.ScriptTask;
using System.AddIn;
using WinSCP;

namespace ST_5a30686e70c04c5a8a93729fd90b8c79.csproj
{
    [AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : VSTARTScriptObjectModelBase
    {
        public void Main()
        {
            // Setup session options
            SessionOptions sessionOptions = new SessionOptions
            {
                Protocol = Protocol.Sftp,
                // To setup these variables, go to SSIS > Variables.
                // To make them accessible from the script task, in the context menu of the task,
                // choose Edit. On the Script task editor on Script page, select ReadOnlyVariables,
                // and tick the below properties.
                HostName = (string) Dts.Variables["User::HostName"].Value,
                UserName = (string) Dts.Variables["User::UserName"].Value,
                Password = (string) Dts.Variables["User::Password"].Value,
                SshHostKeyFingerprint = (string) Dts.Variables["User::SshHostKeyFingerprint"].Value
            };

            try
            {
                using (Session session = new Session())
                {
                    // As WinSCP .NET assembly has to be stored in GAC to be used with SSIS,
                    // you need to set path to WinSCP.exe explicitly, if using non-default location.
                    session.ExecutablePath = @"C:\winscp\winscp.exe";

                    // Connect
                    session.Open(sessionOptions);

                    // Upload files
                    TransferOptions transferOptions = new TransferOptions();
                    transferOptions.TransferMode = TransferMode.Binary;

                    TransferOperationResult transferResult;
                    transferResult = session.PutFiles(@"d:\toupload\*", "/home/user/", false, transferOptions);

                    // Throw on any error
                    transferResult.Check();

                    // Print results
                    bool fireAgain = false;
                    foreach (TransferEventArgs transfer in transferResult.Transfers)
                    {
                        Dts.Events.FireInformation(0, null, 
                            string.Format("Upload of {0} succeeded", transfer.FileName),
                            null, 0, ref fireAgain);
                    }
                }

                Dts.TaskResult = (int)DTSExecResult.Success;
            }
            catch (Exception e)
            {
                Dts.Events.FireError(0, null,
                    string.Format("Error when using WinSCP to upload files: {0}", e),
                    null, 0);

                Dts.TaskResult = (int)DTSExecResult.Failure;
            }
        }
    }
}

0
投票

/命令“选项批处理打开”“选项确认关闭”“打开sftp:// USER:PWD @ SFTPSeverHost:22 -hostkey =” ssh-Key“ put -delete -resume -preservetime File_To_upload FolderDestination”“关闭”退出“

© www.soinside.com 2019 - 2024. All rights reserved.