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 the Script Task
code block I've found to retrieve the file name list and store in an XML file.
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='")
ftpFileNameListXML.Append(ftpFileNames(i))
ftpFileNameListXML.AppendLine("'/>")
Next i
ftpFileNameListXML.AppendLine("</filelist>")
Dts.Variables("FtpFileListXML").Value = ftpFileNameListXML.ToString()
Dts.TaskResult = ScriptResults.Success