May 21, 2010 at 11:49 am
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.
May 21, 2010 at 11:53 am
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
May 21, 2010 at 12:00 pm
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
May 21, 2010 at 12:04 pm
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
May 21, 2010 at 12:12 pm
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.
May 24, 2010 at 8:35 am
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))
'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
Catch ex As Exception
'Dts.TaskResult = ScriptResults.Failure
End Try
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
May 25, 2010 at 6:44 am
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.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply