Topic "Pass variables from batch DOS programs to file script SCP"

Author Message



A nice feature would be the ability to get in the script file the variables defined from the DOS command line...
With this enhancement, you can do some batch jobs and then use the results in SCP scripts.

Best regards to all
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
You can easily generate the script with values you need automatically.
Martin Prikryl


OK... I understand...

I will try !



It works well...
I use the SED command added on my Windows computer to manage files
I use the postie exe file to send mails for results

For example... I have a script that backups files from a Windows server to a Linux server
The problem is to select only files containing the date of the day in the file name
The main text script called SCR.TXT contains 2 lines like :
# Upload SGBD files to remote folder
put D:\files\zip\*AA*.zip /dev/backup/

Each night, a batch file do the following job :
1) It replace the AA string with the date of the day
2) It runs winscp.exe to transfer file to other server
3) It sends a mail containing the result of the process

set yy=%date:~6,4%
set mm=%date:~3,2%
set dd=%date:~0,2%

Rem Replace the string "AA" in the text script with date of the day
sed -e s/AA/%yy%%mm%%dd%/ SCR.TXT > SCRIPT.TXT

Rem Initiate the file transfer /console /script=SCRIPT.TXT

Rem Send result by mail
IF NOT errorlevel 1 (
  echo OK
  postie.exe -host:HOSTNAME -port:SMTPPort -s:"Backup ended on %COMPUTERNAME%" -to:MAIL_TO -from:MAIL_FROM -msg:"Server %COMPUTERNAME% : \r Process ended   : %TIME%"
) ELSE (
  echo Error
  postie.exe -host:HOSTNAME -port:SMTPPort -s:"Backup failed on %COMPUTERNAME%" -to:MAIL_TO -from:MAIL_FROM -msg:"Server %COMPUTERNAME% : \r Process ended   : %TIME%"

Rem Give time to the batch process to send the mail
ping -n 10 localhost

I hope this can help to make nice scripts !

You can post new topics in this forum


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