Best Method to SFTP or FTPS Files via SSIS [closed]

梦想与她 提交于 2019-11-28 21:08:31
Martin Carpenter

The following question might be of use:

What would be a recommended choice of SSIS component to perform SFTP or FTPS task?

Cozyroc:

It should be easy to test ssh protocol availability by setting the server to "allow only SSHv2" and testing. Have your tried asking Cozy's sales dept?

Command line sftp:

The unknown filename problem could be solved simple scripting/use of wildcards (at least under Cygwin).

3rd party lib:

Why do you need a third party lib for FTPS? .NET has supported this protocol since 2.0 or so.

http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.enablessl.aspx

I just wanted to provide an update on what we actually decided to do to resolve the SFTP issues in SSIS. Here's the breakdown of what happened:

  1. I initially tried using Putty and some batch files to upload files, but it was difficult to capture errors. Also, I was storing our SFTP credentials in clear text files since it was part of the Putty upload scripts.

  2. We purchased a CozyRoc license for our SSIS server for a couple hundred dollars a year and I'm completely satisified with the results of using their product. With CozyRoc's product, the control flow task raises errors if there are any problems with the upload. Since I also have several junior SSIS programmers on my team, it was easier for them to understand how to setup the control flow task than to use the Putty scripts method. And finally, the password is encrypted using SSIS's native encryption for protecting sensitive data. I no longer have any passwords stored in clear text on my server.

I did review some of the other 3rd party libraries that were recommended in this question, but it appears CozyRoc was the cheapest of the vendors and they also had a few other SSIS tasks that I have been able to use in my BI team. Thanks, CozyRoc!

sacha79

Without component, you can use script task. See this link

Imports System
Imports Microsoft.SqlServer.Dts.Runtime
Imports Ftp
Imports System.IO

Public Class ScriptMain

    Public Sub Main()

        Try

            Dim cm As ConnectionManager = Dts.Connections.Add("FTP")
            cm.Properties("ServerName").SetValue(cm, Dts.Variables("SFTPServerName").Value.ToString)
            cm.Properties("ServerUserName").SetValue(cm, Dts.Variables("SFTPLogin").Value.ToString)
            cm.Properties("ServerPassword").SetValue(cm, Dts.Variables("SFTPPassword").Value.ToString)
            cm.Properties("ServerPort").SetValue(cm, Dts.Variables("SFTPPortNumber").Value.ToString)
            cm.Properties("Timeout").SetValue(cm, "0")
            cm.Properties("ChunkSize").SetValue(cm, "0") '1000 kb
            cm.Properties("Retries").SetValue(cm, "0")
            Dts.Variables("Continue").Value = 0

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

            Dim Separator As String = ";"
' \\ServerName\Share1;\\ServerName\Share2 : Local copy
            Dim FolderLocalListSrc As String = Dts.Variables("FolderLocalListSrc").Value.ToString
            Dim FolderLocalListDst() As String = Split(FolderLocalListSrc, Separator)
            Dim Counter As Integer

            ftp.Connect()
            ftp.GetListing(FolderName, FilesList)

            If FilesList IsNot Nothing Then

                Dim FileName As String

                For Each FileName In FilesList

                    Dim FileToProcess(0) As String
                    Dim FileToMove(0) As String

                    For Counter = 0 To FolderLocalListDst.GetUpperBound(0)

                        FileToProcess(0) = FileName
                        FileToMove(0) = FolderLocalListDst(Counter) + FileName

                        If (File.Exists(FileToMove(0)) = False) Then

                            ' Téléchargement en local
                            ftp.ReceiveFiles(FileToProcess, FolderLocalListDst(Counter), True, True)

                        End If

                    Next

                    ' Upload du fichier dans les archives du FTP
                    ftp.SendFiles(FileToMove, "/Archives", True, False)

                    ' Suppression du fichier à la racine du FTP
                    ftp.DeleteFiles(FileToProcess)

                Next

            End If

            ftp.Close()

            Dts.TaskResult = Dts.Results.Success
        Catch ex As Exception
            Dts.TaskResult = Dts.Results.Failure
        End Try

    End Sub

End Class
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!