Topic "Special %date% variable not working"

Author Message
Jim Mc
[View user's profile]

Joined: 2012-11-26
Posts: 1
Location: Newcastle, UK
Hi there,

I'm trying to use the following WinSCP script which calls a script remotely and generates a tar.bz2 file which includes a date in the name, e.g. Backup-Nov-2012.tar.bz2. This part works correctly however the script does not appear to correctly interpret the special date environment variable which is in the following format: %date:~3,8%

Through the regional settings on the Windows client I have configured the date short format to show up as dd-MMM-yyyy which actually translates to for example 26-Nov-2012, so when I use %date:~3,8% I get Nov-2012.

The following is my script, if I call it on the command line I can see that it is not correctly evaluating the date variable:


option confirm off
open -timeout=18000 diesel
call /home/diesel/tmpbackup/ >/dev/null 2>&1
lcd c:\foobar
get /home/diesel/tmpbackup/Backup-"%date:~3,8%".tar.bz2


C:\Program Files (x86)\WinSCP> /script=c:\foobar\backup.txt
confirm         off
Searching for host...
Connecting to host...
Using username "xyz".
Authenticating with pre-entered password.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] diesel
transfer        binary
Can't get attributes of file '/home/diesel/tmpbackup/Backup-%date:~3,8%.tar.bz2'
No such file or directory.
Error code: 2
Error message from server: No such file
Request code: 7

Your help appreciated.
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24759
Location: Prague, Czechia
WinSCP supports only plain environment variables.

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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License