Topic "Trying to set username variable in batch script"

Author Message


So my server requires the username in the format:

This seems to cause problems when I attempt to put it all on the one line:
open s

So I found another forum post where it is mentioned to use a variable for the username, by adding this line to the script:
set /P USERNAME=""

and then using %USERNAME% for the open script:
open s

When I try to run this it returns 'unknown command 'set'.'

My batch file is just simple:
WinSCP.exe /console /script=script.txt

and contents of script.txt:
option batch on
option confirm off
set /P USERNAME=""
open s
option transfer binary
put test2.txt /

Any help appreciated!
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24755
Location: Prague, Czechia
The set command should be in a wrapping batch file, not in WinSCP script.
But it won't help you anyway. It makes no difference if you specify the username directly or via environment variable.

Solution is to URL-encode the slash and at sign:
open s



Thank you so much prikryl - URL-encoding the slash and @ symbol worked like a treat. Greatly appreciated! Very Happy


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