Most recent file selection with WinSCP command line

Advertisement

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
29,070
Location:
Prague, Czechia

Re: Most recent file selection with WinSCP command line

Your duplicate question on stackoverflow:
https://stackoverflow.com/q/22388746/850848

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.

Reply with quote

Andreb
Guest

Re: Most recent file selection with WinSCP command line

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

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
29,070
Location:
Prague, Czechia

Re: Most recent file selection with WinSCP command line

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.

Reply with quote

SLee
Guest

use this

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.

Reply with quote

Advertisement

pgpsatish@...
Guest

get command with filemask in a MSDOS batch file

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.

"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

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
29,070
Location:
Prague, Czechia

Re: get command with filemask in a MSDOS batch file

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.

Reply with quote

Glenn
Guest

Error STOR 501 invalid 01 'STOR ': Invalid number of parameters

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

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
29,070
Location:
Prague, Czechia

Re: Error STOR 501 invalid 01 'STOR ': Invalid number of parameters

Glenn wrote:

Can help me with that.
We need a complete log file to help you.

Reply with quote

Advertisement

You can post new topics in this forum