Sahil Sharma
Sahil Sharma

Reputation: 61

How to pass a user input in AutoIt Script to WinSCP?

I'm trying to build an FTP transfer script using AutoIt with WinSCP

I'm using winscp.com.

I want to take input from user (via GUI) and then use those inputs in my commands for WinSCP.

For example, I want to set the local directory based on user's choice.

Current Situation: I'm able to store the user's input, however when I try to pass the same in WinSCP command console using AutoIt script, it either doesn't read the variable or simply gives and unknown command error.

RunWait(@ComSpec & ' /k ' & 'winscp.com /command  "option batch continue" ' & '"option confirm off" '  & ' "open xyz"' & ' "lcd" ' & $Dir )

Where $Dir has value for user input stored using GUICtrlRead().

Please suggest if there is any other way to make the WinSCP console read my user data (I want to capture unique data by user every time, so don't want to make a config file).

Thanks

Upvotes: 0

Views: 1266

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202282

While I do not know Autoit syntax, I'm pretty sure you have quotes wrong.

Double-quotes have to be around the whole lcd command, including its argument. An expanded command have to be like "lcd /path/to/dir", not "lcd" /path/to/dir, as you have it now. Just as you have it with the open (i.e. "open xyz").

Additionally, had you need to use spaces in the path, the path itself has to be double-quoted. As the quoting happens on a command-line (as opposite to a script file), where double-quotes have their meaning, the in-command double-quotes have to be escaped by doubling them, e.g. the resulting syntax is "lcd ""/path/to/dir""".

So, instead of

... ' "lcd" ' & $Dir

use

... ' "lcd ""' & $Dir & '"""'

References:
https://winscp.net/eng/docs/commandline#syntax
https://winscp.net/eng/docs/scripting#syntax

Also I believe you do not really need all those concatenations between constant strings, just do:

RunWait(@ComSpec & ' /k winscp.com /command "option batch continue" "option confirm off" "open xyz" "lcd ""' & $Dir & '"""')

Upvotes: 1

Related Questions