Click here to Skip to main content
15,887,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We use the FTP task in SSIS to download about 500 files from an FTP server, with the biggest file about 2 Gigabytes in size. The download fails 50% of the time. We would like to implement a step in our SSIS package that would retrieve the list of files on the FTP Server and the file sizes before we try download them for processing. The FTP Task doesn't have an operation that retrieves the file list and the file sizes. Can you provide an example of how to do this?

Below is a working Script Task code block I've found to retrieve the file name list and store in an XML file.

VB
Dim ftpFileNameListXML As New StringBuilder
ftpFileNameListXML.AppendLine("<filelist>")

Dim ftpcm As ConnectionManager = Dts.Connections("FTP")
Dim ftp As FtpClientConnection = _
            New FtpClientConnection(ftpcm.AcquireConnection(Nothing))
Dim ftpFileNames() As String
Dim ftpFolderNames() As String

ftp.Connect()
ftp.SetWorkingDirectory(Dts.Variables("FtpWorkingDirectory").Value.ToString())
ftp.GetListing(ftpFolderNames, ftpFileNames)
ftp.Close()

Dim i As Integer
For i = 0 To ftpFileNames.GetUpperBound(0)
    ftpFileNameListXML.Append("<file name="")<br mode="hold" />        ftpFileNameListXML.Append(ftpFileNames(i))<br mode="hold" />        ftpFileNameListXML.AppendLine("" />")
Next i

ftpFileNameListXML.AppendLine("</filelist>")
Dts.Variables("FtpFileListXML").Value = ftpFileNameListXML.ToString()

Dts.TaskResult = ScriptResults.Success
Posted
Updated 16-Apr-15 12:10pm
v2
Comments
PIEBALDconsult 16-Apr-15 18:02pm    
Dunno, I have never used the FTP Task. I do use a Script Task to download some files via HTTP though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900