Topic "Most recent file selection with WinSCP command line"

Author Message
sivaramanm
[View user's profile]

Joined: 2013-11-19
Posts: 5
How do i achieve this using winscp command line automation commands?

https://winscp.net/eng/docs/script_download_most_recent_file
Advertisements
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26730
Location: Prague, Czechia
Your duplicate question on stackoverflow:
https://stackoverflow.com/q/22388746/850848

Quote:
You cannot do this on command-line only. If it was possible, the solution in WinSCP documentation would show it instead of the use of wrapper script.

The closest you can get with command-line only is using file mask with time constraint. For example, if you know that one file per day is added only, you can use *>1D mask to select files (one file actually) created within the last 24 hours.
Andreb

Guest


sivaramanm wrote:
How do i achieve this using winscp command line automation commands?

https://winscp.net/eng/docs/script_download_most_recent_file


Hi All... Please please can somebody help me - I'm struggling my ╤╚♦ off Smile
I have files - 6 of them sitting on a remote site, every day a new is placed, I need to download only the newest one, the file name changes every day to I'm aiming at using the "latest date" - needless to say my scripting knowledge is void - I've tied using the >1d - WinSCP does all sorts of weird things and gives me a file called %3C1d - what the hell is that??

my command currently reads "get //ftp05155/FTP*.* <1d"

Please can someby please assist with the correct syntax that would allow me to automate the download of the latest file between 6 others from the SFTP please - connectivity is working, just the download seems to be problematic....

thanks a Huge load for your efforts, much appreciated!
Andre
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26730
Location: Prague, Czechia
Andreb wrote:
my command currently reads "get //ftp05155/FTP*.* <1d"

There should be NO space between *.* and the time constraint + It should be >, not <.
Are you sure the path should start with two slashes?

Btw, it would be nice, if you accept the answer you got on stackoverflow.com.
SLee

Guest


I know its really old post , but I had similar requirement, and what worked for me is : get /out/abc.z*>16h %LOCAL_PATH% where abc.zip was my exact file name in out folder. It got me only abc.zip.
pgpsatish@...

Guest


Hello,

I'm trying to use below WinSCP script in a MSDOS batch file to automatically download the ZIP files from FTP server. I need to automatically download files every 2 hours from the FTP server.

Code:
"C:\Program Files\WinSCP5.7\WinSCP.com" ^
  /log="C:\Program Files\WinSCP5.7\WinSCP.log" /ini=nul ^
  /command ^
    "open ftp://electpub:elmelm5@obp-ftp.oxon.blackwellpublishing.com/" ^
    "get *.zip /ElecMediaOUT/ -filemask>=2H  H:\FTP-Blackwell\" ^
    "exit"



I get error as below

. 2017-07-20 12:16:16.578 Retrieving file information successful
< 2017-07-20 12:16:16.578 Script: Can't get attributes of file '/ElecMediaOUT/'.
< 2017-07-20 12:16:16.578 Script: File or folder '/ElecMediaOUT/Informatics/' does not exist.
. 2017-07-20 12:16:16.578 Script: Failed
. 2017-07-20 12:16:16.578 Script: Exit code: 1
. 2017-07-20 12:16:16.578 Disconnected from server

=============================

Pls let me know the correct syntax to be used for "get" with "filemask" script in a batch file.

I have attached log file for your quick ref

Thanks

Satish P
WinSCP.log (34.97 KB) [Download]

Description: (none)

martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26730
Location: Prague, Czechia
pgpsatish@... wrote:
Pls let me know the correct syntax to be used for "get" with "filemask" script in a batch file.

It should probably be:

"get /ElecMediaOUT/*.zip -filemask>=2H H:\FTP-Blackwell\" ^

Though your log file does not actually match the script, so it's hard to help you.
Glenn

Guest


Can help me with that.

my batch as follow:

@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Users\glenn_wan.MEDQUEST\Documents\Documents\execu3.log" /ini=nul ^
/command ^
"open ftp://xxxxxxxxxx@xxxxxxxxxxx/" ^
"lcd C:\Users\glenn_wan\Documents\Documents\" ^
"CD /Test/Test1"^
"put "C:\Users\glenn_wan\Documents\Documents\*.txt" -filemask=""*>=1D"" "^


"exit"



set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)

exit /b %WINSCP_RESULT%


having this error in log :

2017-08-17 10:15:41.227 File: 'C:\Users\glenn_wan.MEDQUEST\Documents\Documents\Glenntest123456.txt' [2017-08-17T02:01:04.310Z] [0]
. 2017-08-17 10:15:41.230 Copying "C:\Users\glenn_wan.MEDQUEST\Documents\Documents\Glenntest123456.txt" to remote directory started.
. 2017-08-17 10:15:41.231 Binary transfer mode selected.
. 2017-08-17 10:15:41.231 Starting upload of C:\Users\glenn_wan.MEDQUEST\Documents\Documents\Glenntest123456.txt
> 2017-08-17 10:15:41.232 TYPE I
< 2017-08-17 10:15:41.268 200 Type set to I.
> 2017-08-17 10:15:41.269 PASV
< 2017-08-17 10:15:41.299 227 Entering Passive Mode (101,100,170,14,193,254).
> 2017-08-17 10:15:41.301 STOR
. 2017-08-17 10:15:41.301 Connecting to 101.100.170.14:49662 ...
< 2017-08-17 10:15:41.328 501 'STOR ': Invalid number of parameters
. 2017-08-17 10:15:41.328 Copying files to remote side failed.
* 2017-08-17 10:15:41.329 (ExtException) **Copying files to remote side failed.**
* 2017-08-17 10:15:41.329 'STOR ': Invalid number of parameters
. 2017-08-17 10:15:41.329 Asking user:
. 2017-08-17 10:15:41.329 Error transferring file 'C:\Users\glenn_wan.MEDQUEST\Documents\Documents\Glenntest123456.txt'. ("Copying files to remote side failed.","'STOR ': Invalid number of parameters")
< 2017-08-17 10:15:41.329 Script: Error transferring file 'C:\Users\glenn_wan.MEDQUEST\Documents\Documents\Glenntest123456.txt'.
< 2017-08-17 10:15:41.330 Script: Copying files to remote side failed.

< 2017-08-17 10:15:41.330 'STOR ': Invalid number of parameters
* 2017-08-17 10:15:41.332 (EScpSkipFile) Error transferring file 'C:\Users\glenn_wan.MEDQUEST\Documents\Documents\Glenntest123456.txt'.
* 2017-08-17 10:15:41.332 Copying files to remote side failed.
* 2017-08-17 10:15:41.332 'STOR ': Invalid number of parameters
. 2017-08-17 10:15:41.332 Script: Failed
. 2017-08-17 10:15:41.332 Script: Exit code: 1
. 2017-08-17 10:15:41.337 Disconnected from server
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26730
Location: Prague, Czechia
Glenn wrote:
Can help me with that.

We need a complete log file to help you.
Advertisements

You can post new topics in this forum

Search

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