How can I copy and rename a file on FTP server in SSIS package

  • I am doing this in script task. Here is my code. This step is successfull but not doing anything. Can some one help me?

    Imports System

    Imports System.Data

    Imports System.Math

    Imports Microsoft.SqlServer.Dts.Runtime

    Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

    Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

    Imports Microsoft.VisualBasic.FileIO.FileSystem

    Imports System.IO.FileSystemInfo

    Imports System.IO

    Imports System.Net

    Public Class ScriptMain

    ' The execution engine calls this method when the task executes.

    ' To access the object model, use the Dts object. Connections, variables, events,

    ' and logging features are available as static members of the Dts class.

    ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

    '

    ' To open Code and Text Editor Help, press F1.

    ' To open Object Browser, press Ctrl+Alt+J.

    Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal HINet As Integer) As Integer

    Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer

    Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Integer, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Integer, ByVal lFlags As Integer, ByVal lContext As Integer) As Integer

    Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Integer, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean

    Public Sub Main()

    Dim INet, INetConn As Integer

    Dim RC As Boolean

    INet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0)

    INetConn = InternetConnect(INet, "testserver", 0, "username", "password", 1, 0, 0)

    MsgBox(INetConn)

    RC = FtpRenameFile(INetConn, "\\inetdir\input.txt", "input.hl7") ' want to move to root directory

    InternetCloseHandle(INetConn)

    InternetCloseHandle(INet)

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class

    Thank You

  • You should REALLY not be doing it that way. Win32 API is not the way to get this done - you should be using the included .Net Framework libraries to do it. This thread should give you all you need to know: SSIS Script task that FTP's files. Yes, you'll have to do some more method calls that may not be in that thread, but the majority of the work is laid out for you there...

    Todd McDermid - SQL Server MVP, MCTS (SQL 08 BI), MCSD.Net
    My Blog - Dimension Merge SCD Component for SSIS - SSIS Community Tasks and Components

  • That is to move file. How can I rename after moving file to FTP server?

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply