【问题标题】:SSIS Task - FTP Conecction [duplicate]SSIS 任务 - FTP 连接 [重复]
【发布时间】:2021-12-02 12:15:36
【问题描述】:

全部,

SSIS - 尝试使用 Visual Basic 编程语言中的脚本任务建立 ftp 连接以将文件上传到 ftp 服务器,但我遇到了问题。我在搜索中没有找到类似的东西,因此非常感谢您的帮助。

[连接管理器“FTP”] 错误:请求的 FTP 操作发生错误。详细错误说明:220
控制通道需要 550 SSL/TLS

代码:

Public Sub Main()

    '
    ' Add your code here
    '

    Try

        Dim cm As ConnectionManager

        cm = Dts.Connections("FTP")

        'Set the properties like username & password
        cm.Properties("ServerName").SetValue(cm, "ftps.example.com")
        cm.Properties("ServerUserName").SetValue(cm, "username")
        cm.Properties("ServerPassword").SetValue(cm, "password")
        cm.Properties("ServerPort").SetValue(cm, "port")
        cm.Properties("Timeout").SetValue(cm, "0") 'The 0 setting will make it not timeout
        cm.Properties("ChunkSize").SetValue(cm, "1000") '1000 kb
        cm.Properties("Retries").SetValue(cm, "1")

        'create the FTP object that sends the files and pass it the connection created above.

        Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))

        'Connects to the ftp server

        ftp.Connect()


        'Build a array of all the file names that is going to be FTP'ed (in this case only one file)

        Dim files(0) As String

        files(0) = "C:\ local path file"

        'ftp the file 

        ftp.SendFiles(files, "/remote path", True, False) ' the True makes it overwrite existing file and False is saying that it is not transferring ASCII

        ftp.Close()

    Catch ex As Exception

        Dts.TaskResult = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure


    End Try

【问题讨论】:

  • 我没有找到有关这些 FTP 连接属性的任何文档。无论如何,一旦你编写了所有代码,为什么不使用标准的 .NET FtpWebRequest 和它的 EnableSsl = True?见Upload file to FTP site using VB.NET。

标签: ssis ftp ftps script-task


【解决方案1】:

……我终于解决了。我将语言脚本任务更改为 C#(它在 VB 中工作,您只需调整代码)并使用来自 this 注释的代码。

注意:如果服务器位于 21 以外的端口上,则必须在远程路径中指定它。谢谢。

   public void Main()
   {
    // TODO: Add your code here
     FtpWebRequest request =
    (FtpWebRequest)WebRequest.Create("ftp://ftps.example.com:port/remote/path/file.zip");
    request.Credentials = new NetworkCredential("username", "password");
        request.EnableSsl = true;
        request.Method = WebRequestMethods.Ftp.UploadFile;  

        using (Stream fileStream = File.OpenRead(@"C:\local\path\file.zip"))
        using (Stream ftpStream = request.GetRequestStream())
          {
        fileStream.CopyTo(ftpStream);
          }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多