Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 get latest file from ftp

Author  Topic 

shilpash
Posting Yak Master

103 Posts

Posted - 2013-07-26 : 16:02:42
I am trying to get the latest file from ftp.File format is like this-
abc_xx_123_a_b_c.exe
abc_xx_124_a_b_c.exe
abc_xx_125_a_b_c.exe
abc_xx_126_a_b_c.exe

There is no datestamp in the filename but number like 126 determine the latest file.So here abc_TEST_126_a_b_c.exe
is greater than abc_TEST_123_a_b_c.exe
and abc_xx_123_a_b_c.exe is the oldest file.

How would I accomplish this and I would prefer without doing script task.Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-27 : 03:44:36
Add a for each loop to loop through the files and add filenames received to a table. Then add a logic to get max of number value within filename, something like

SELECT TOP 1 filename
FROM Table
ORDER BY LEFT(STUFF(filename,1,PATINDEX('%[0-9]%',filename)-1,''),CHARINDEX('_',STUFF(filename,1,PATINDEX('%[0-9]%',filename)-1,''))-1)*1 DESC



then in a file system task pass the filename got above as source to move file to wherever you want

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -