Looping through files in FTP Site folder is possible or not?

  • Hi everyone,

    I need to loop through some of the Zip files inside the FTP site. I don't want to download the files to my local machine and then loop through the files using for each loop container.

    Please let me know if anyone has any idea and would be much appreciated if they can share their idea or thought on this.

    Thanks in advance.

  • nope, there is no way to read the contents of a zip file unless it exists locally; so if the file exists on the FTP site, you have to download it to peek at it.

    you could put a process on the FTP site itself which sends the contents of any zip file to a file on the FTP site, but you have to have control of the FTP server.

    You would use 7zip or some other utility on the FTP server to open each zip file, and put the names of the files into a text file, most likely with nearly the same name as the file;,

    so Applications.zip gets a Applications_Contents.txt, with a list of all the files.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Hi lowell,

    I apologize if my post is not clear enough. I just want to loop through zip files inside the ftp site folder and I am not trying to unzip these zip files inside the ftp site.

    Thanks

  • i think i understood you correctly...say there is a file Archive.zip on your ftp site, you wanted to know the names of the files / contents INSIDE Archive.zip before having to download it, correct?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I want to know the names of the zip files and its creation time and I am not concerned about the contents inside the zip files. The reason I want creation time is that I want to pick the latest one after loading the filenames and creation time inside a table.

    In brief my task is to take the filenames and its creation time values and load into sql server table and then pick the zip file with latest creation time.

    Thanks a lot and I appreciate for your postings.

  • You will need to write a script to get the list of all the files and then store them in a variable and later load into a table.. I am not good at scripting but i have used the below to get my work done.. you might use this to get started. The script below basically connects to the FTP server and then checks for files..

    Dim RemoteFile As IO.FileInfo()

    Public Sub Main()

    '

    ' Add your code here

    '

    Dim ftpConnectionManager As ConnectionManager

    ftpConnectionManager = Dts.Connections("FTP Connection Manager")

    Dts.Connections("FTP Connection Manager").Properties("ServerPassword").SetValue(ftpConnectionManager, Dts.Variables("FTPPwd").Value)

    Try

    'Create the connection to the ftp server

    Dim cm As ConnectionManager = Dts.Connections.Add("FTP")

    'Set the properties like username & password

    cm.Properties("ServerName").SetValue(cm, "XX.XXX.XX.X")

    cm.Properties("ServerUserName").SetValue(cm, "XX")

    cm.Properties("ServerPassword").SetValue(cm, "XX")

    cm.Properties("ServerPort").SetValue(cm, "21")

    cm.Properties("Timeout").SetValue(cm, "0") 'The 0 setting will make it not timeout

    cm.Properties("ChunkSize").SetValue(cm, "1000") '1000 kb

    cm.Properties("Retries").SetValue(cm, "1")

    'create the FTP object that sends the files and pass it the connection created above.

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

    http://ftp.Connect()

    'Connects to the ftp server

    'Get file listing

    Dim fileNames() As String

    Dim folderNames() As String

    http://ftp.GetListing(folderNames, fileNames)

    If fileNames.Length >= 1 Then

    Dts.Variables("FileExists").Value = True

    Else

    Dts.Variables("FileExists").Value = False

    End If

    http://ftp.Close()

    Catch ex As Exception

    'Dts.TaskResult = ScriptResults.Failure

    End Try

    Dts.TaskResult = ScriptResults.Success

    End Sub

    End Class

  • saidwarak01 (5/21/2010)


    I want to know the names of the zip files and its creation time and I am not concerned about the contents inside the zip files. The reason I want creation time is that I want to pick the latest one after loading the filenames and creation time inside a table.

    In brief my task is to take the filenames and its creation time values and load into sql server table and then pick the zip file with latest creation time.

    Thanks a lot and I appreciate for your postings.

    There is a way to get the list of the remote files, but NO WAY to get the creation time. If you can use third-party solutions, check the commercial CozyRoc SFTP Task. You can retrieve both the remote files list and also the creation time.

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

Viewing 7 posts - 1 through 6 (of 6 total)

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