FTP Multiple Files download with File Name starting with

  • I have a requirement to download multiple files from FTP site based on the file name starting with

    Filename_YYYY-MM-DD_*.csv and load them into one single table.

    I'm using ssis package to download the files but no luck. Can anyone help me find a solution.

  • Please define your problem in a little more detail. What is/is not happening? Are you getting any errors? What have you already tried?

  • I tried below code in script task. I tried to test all the files starting with file name session_report_2011-07-22* but some how when i execute script task all the files from the FTP are copied to destination folder.

    ' Microsoft SQL Server Integration Services Script Task

    ' Write scripts using Microsoft Visual Basic

    ' The ScriptMain class is the entry point of the Script Task.

    Imports System

    Imports System.Data

    Imports System.Math

    Imports Microsoft.SqlServer.Dts.Runtime

    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.

    Public Sub Main()

    '

    ' Add your code here

    '

    Dim cm As ConnectionManager

    cm = Dts.Connections("FTP")

    '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

    Dim strfolders As String()

    Dim strfiles As String()

    Dim fileCount As Int32

    Dim FTPTargetFolder As String

    Dim fileName As String

    fileName = Dts.Variables("FiletoGet").Value.ToString()

    FTPTargetFolder = Dts.Variables("FileToCopy").Value.ToString()

    http://ftp.Connect()

    http://ftp.SetWorkingDirectory("/")

    If Not strFiles Is Nothing Then

    For Each fileName In strfiles

    If fileName.Contains("session_report_2011_07_22_") Then

    fileCount = fileCount + 1

    End If

    Next

    If fileCount > 0 Then

    http://ftp.ReceiveFiles(strfiles, FTPTargetFolder, True, False)

    http://ftp.DeleteFiles(strfiles)

    End If

    http://ftp.Close()

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class

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

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