Topic "Get the most recent file from the FTP Folder"

Author Message
tarekahf
[View user's profile]

Joined: 2014-10-26
Posts: 2
Kindly see the following screencasts to get better idea about our requirement:

https://www.screenr.com/QmDN

https://www.screenr.com/ImDN

We want to automate the Text Datasource Generation and connection to MS Excel in order to make it easier to the end-user to connect to the Text Datasource (CSV) to MS Excel so that they can generate their own reports.

The steps I have in mind:

1. Use WinSCP FTP Client with Scripting

2. Write script to get the most recent updated file from FTP Folder

3. Or instead of step 2, download all generated files from FTP to a Shared Folder on the Network.

4. Get the most recent version of the Generated CSV File

5. Rename the file to the Standard Naming Convention. This must be the name used in MS Excel as the CSV Text Datasource.

6. Delete all other files

I developed sample script that can be used by WinSCP to download the files from FTP folder:

Code:
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect
open CSOD
# Change remote directory
cd /Reports/CAD
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
#get "Training Attendance Data - Tarek_22_10_21_2014_05_05.CSV" "D:\MyData\Business\Talent Management System\Reports\WinCSP\"
get "*.CSV" "D:\MyData\Business\Talent Management System\Reports\WinCSP\Files\"
# Disconnect
close
exit


Then, I can schedule the above code to run periodically using this command:

Code:
winscp.com /script=example.txt


The above sample is working fine, but the main problem is how to identify the most recent file, so that I can rename it, and delete all the other files.

Our ultimate objective is to automate the download of the CSV Files from FTP Folder, to make it easier for end-user to use them to connect to client reporting engine like MS Excel.

Appreciate your help.

Tarek

Last edited by tarekahf on 2014-10-29 14:48; edited 1 time in total
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Did you see this?
http://winscp.net/eng/docs/script_download_most_recent_file
_________________
Martin Prikryl
tarekahf
[View user's profile]

Joined: 2014-10-26
Posts: 2

Oh No Shocked

How did I miss that !

Thank you Very Happy

Tarek
Prashanth

Guest


Hi
i wanted to download the most recent file from the remote directory please see the below script

get filemask="*>1d"

get filemask="*<1d"

i used both the scripts but the result is same like it downloads all the files from remote directory.

and even my question is how to pass the specific timestamp into my script or batch file.

please help me to sort out from this

Thanks
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Prashanth wrote:
i wanted to download the most recent file from the remote directory please see the below script

get filemask="*>1d"

get filemask="*<1d"

i used both the scripts but the result is same like it downloads all the files from remote directory.
...

Duplicate post:
http://winscp.net/forum/viewtopic.php?t=14597
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License