Topic "Simple Batch File Possible?"

Author Message
solid
[View user's profile]

Joined: 2015-02-04
Posts: 5
Location: NH
Hello WinSCP. This is all new to me, so be kind. Smile

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:

http://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:

Code:
@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.
Advertisements
solid
[View user's profile]

Joined: 2015-02-04
Posts: 5
Location: NH
I'm not sure if this will work?

Code:
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.
solid
[View user's profile]

Joined: 2015-02-04
Posts: 5
Location: NH
OK, here's what I'm seeing now. So close, yet so far...

Code:
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. Sad
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
solid wrote:
I'm not sure if this will work?

Code:
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.
_________________
Martin Prikryl
solid
[View user's profile]

Joined: 2015-02-04
Posts: 5
Location: NH
prikryl 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:
Code:

# 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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
_________________
Martin Prikryl
solid
[View user's profile]

Joined: 2015-02-04
Posts: 5
Location: NH
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. Embarassed
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