Simple Batch File Possible?

Advertisement

solid
Joined:
Posts:
5
Location:
NH

Simple Batch File Possible?

Hello WinSCP. This is all new to me, so be kind. :)

I have a file that I upload every weekday @ 11:00am. I want to automate the FTP process that I currently do manually. The file is created every weekday @ 9:30am, and is named "1234_MMDDYY_01". "1234_" and "_01" are constant, but the MMDDYY changes everyday. The answer to this is here I'm sure:

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

...but I can't figure out the date part of the filename. I also found this example in the forum, but I don't think this will work:

@echo off
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
   Set Month=%%A
   Set Day=%%B
   Set Year=%%C
       
        set file=1234_%Month%%Day%%Year%_01

If someone could type out a quick example, that would be great.

Thanks in advance.

Reply with quote

Advertisement

solid
Joined:
Posts:
5
Location:
NH

I'm not sure if this will work?

winscp.com /command ^
    "option batch abort" ^
    "option confirm off" ^
    "open ftp://user:password@example.com/" ^
    "put 1234_%TIMESTAMP#mmddyy%_01" ^
    "exit"

Martin Prikryl, I'm sure you know this.

Reply with quote

solid
Joined:
Posts:
5
Location:
NH

OK, here's what I'm seeing now. So close, yet so far...

C:\PROGRA~2\WinSCP3>pause
Press any key to continue . . .

C:\PROGRA~2\WinSCP3>WinSCP.com /script=test.txt
batch           abort
confirm         off
Connecting to ftp.website.com ...
Connected with ftp.website.com. Waiting for welcome message...
Connected
Starting the session...
Reading remote directory...
Session started.
Active session: [1] username@ftp.website.com
File or folder 'C:\test\1234_%%TIMESTAMP#mmddyy%%_01' does not exist.
System Error.  Code: 2.
The system cannot find the file specified
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort

I tried single "%", double, etc. :(

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

solid wrote:

I'm not sure if this will work?

winscp.com /command ^
    "option batch abort" ^
    "option confirm off" ^
    "open ftp://user:password@example.com/" ^
    "put 1234_%TIMESTAMP#mmddyy%_01" ^
    "exit"

Martin Prikryl, I'm sure you know this.
This is correct. But from the "WinSCP3" in the path, I assume you are using some really ancient version of WinSCP. The %TIMESTAMP% syntax is supported in the latest WinSCP 5.6.x RC version only.

Reply with quote

solid
Joined:
Posts:
5
Location:
NH

martin wrote:


This is correct. But from the "WinSCP3" in the path, I assume you are using some really ancient version of WinSCP. The %TIMESTAMP% syntax is supported in the latest WinSCP 5.6.x RC version only.

Mr. Prikryl,

You are correct. I was testing with an outdated version of WinSCP, but I've upgraded to the latest version: 5.5.6 (Build 4746), but it still doesn't seem to work for me. For now, I'm just using a wildcard, but would like to use the actual file name if possible.

Working:
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect to FTP server
open ftp://user:pass@ftp.company.com/
# Upload file
put C:\pathtofile\1234*
# Disconnect
close
# Exit
exit

Is this exactly how the code should appear?:

put C:\pathtofile\1234_%TIMESTAMP#mmddyy%_01

Reply with quote

Advertisement

martin
Site Admin
martin avatar

solid wrote:

but I've upgraded to the latest version: 5.5.6 (Build 4746), but it still doesn't seem to work for me.
Again, the %TIMESTAMP% syntax is supported in the latest WinSCP 5.6.x RC version only.

Reply with quote

solid

Mr. Prikryl,

I apologize. I did not read your first response correctly. I will try with the RC version. Sorry about that, and thank you for the reply. :oops:

Reply with quote

Advertisement

You can post new topics in this forum