DATE variable for script to tranfer a folder from W do U

Advertisement

Ghost_W
Joined:
Posts:
1

DATE variable for script to tranfer a folder from W do U

Hi all,
I know this must be a stupid question, but I'm getting mad for this...
I need to daily tranfer a folder from a Windows Server to a Red Hat one.
This folder on the windows server has the naming convention of "Stats_dd-mm-yyyy".
I'm trying to create a script for automate a daily sftp between this two folder, but I'm not able to pass the "date" variable.
Here is the script i'm trying:


#Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
#SET DATE VARIABLE
set Stats_dd-mm-yyyy=Stats_%date:~4,2%-%date:~7,2%-%date:~10,4%
# Connect
open sftp://user:password@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Force binary mode transfer
option transfer binary
#Put file to the remote directory /tmp
put C:\Scripts\output\%Stats_dd-mm-yyyy% /tmp/test_Stats/
#Log activities
log="c:\scripts\log_winscp_transfer.txt"
# Disconnect
close
# Exit WinSCP
exit


Every time I run this I get error becouse of the "set" command, it's not recognized...
Where am I wrong?????
Thank you

Reply with quote

Advertisement

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

Re: DATE variable for script to tranfer a folder from W do U

There's no "set" command in WinSCP.

You probably wanted to do somethink like:

runwinscp.bat:
set Stats_dd-mm-yyyy=Stats_%date:~4,2%-%date:~7,2%-%date:~10,4%
winscp.com /script=script.txt

script.txt:
option batch abort
...
open sftp://user:password@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
...
put C:\Scripts\output\%Stats_dd-mm-yyyy% /tmp/test_Stats/

Reply with quote

Advertisement

You can post new topics in this forum