Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Facing problem to get recent file

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:
https://winscp.net/forum/viewtopic.php?t=14597
Prashanth

Facing problem to get recent file

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
tarekahf

Get the most recent file from the FTP Folder

Kindly see the following screencasts to get better idea about our requirement:

<invalid hyperlink removed by admin>

<invalid hyperlink removed by admin>

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:

# 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:

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