Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Jim Mc

Special %date% variable not working

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/backup.sh >/dev/null 2>&1
lcd c:\foobar
bi
get /home/diesel/tmpbackup/Backup-"%date:~3,8%".tar.bz2
exit


C:\Program Files (x86)\WinSCP>winscp.com /script=c:\foobar\backup.txt

confirm         off
Searching for host...
Connecting to host...
Authenticating...
Using username "xyz".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] diesel
C:\foobar
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.