Issue with passing command line parameter (path) with space

Advertisement

Carmageddon
Joined:
Posts:
4
Location:
Israel

Issue with passing command line parameter (path) with space

Hi, I am developing tools for our company's server farm monitoring - to ease the job of the operators.

One of the things we need to do sometimes, is retrieve the certain event logs from servers.
So far people would use WinSCP manually.

I am trying to get them now automatically via JavaScript with just single click from web status monitoring page, something like this:
winscp.exe /ini=C:\WinSCP.ini" SessionName1 /console /command "cd /home/username1/logs/uut/MN00093\IVT Gen2" "get event* c:\tmp"
Then, in the command line window, I get something like:
Too many parameters for the command 'cd'.
And of course, then it would (or would not..) copy entirely different files since it didn't change to the folder with space in it...

I have tried everything I could think of... I tried doing \ to escape the space, I tried the web standard of %20 - nothing works.

WinSCP version is 4.1.8 build 415.

Is there a workaround to this? if not this really needs some fix please.. asap :)

Also - one more question please: how do I specify actions other than the /defaults parameter? so I can customize the actions via the command line parameters too :)

Thanks!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,025
Location:
Prague, Czechia

Re: Issue with passing command line parameter (path) with space

Please read documentation. If that does not help, come back.

Also - one more question please: how do I specify actions other than the /defaults parameter? so I can customize the actions via the command line parameters too :)
I do not understand. Give me an example of what you are trying to do.

Reply with quote

Carmageddon
Joined:
Posts:
4
Location:
Israel

Re: Issue with passing command line parameter (path) with space

From the documentation:
Command parameters that include space(s) have to be enclosed in double-quotes....
put "file with spaces and ""quotes"".html"
However, this is good for running a static SCRIPT file, not for when I try to use command line parameters using the /command parameter to RUN the application in /console mode.

I however went ahead and tried out like in the instructions example (note the extra quotes for the path inside cd command):
winscp.exe /ini=C:\WinSCP.ini" SessionName1 /console /command "cd "/home/username1/logs/uut/MN00093\IVT Gen2"" "get event* c:\tmp"
I get this error in the running console:
Error changing directory to '/home/username1/logs/uut/MN00093\IVT'.
Cannot get real path for '/home/username1/logs/uut/MN00093\IVT'.
So, seems there is nothing documented for spaces passed inside a PARAMETER to the application(not in a script!).
Any other suggestions?

Regarding the bit about /defaults – what I mean is, if I for example use /synchronize parameter - if I don't specify the /default parameter, its gonna ask the user, whether I want to port to local, remote, which files to overwrite etc.
Is there a way to specify all these options manually in command line parameters? other than /defaults?

I hope now you understand, what I am trying to accomplish :)

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
36,025
Location:
Prague, Czechia

Re: Issue with passing command line parameter (path) with space

Carmageddon wrote:

So, seems there is nothing documented for spaces passed inside a PARAMETER to the application(not in a script!).
It is the same:
winscp.exe /ini=C:\WinSCP.ini" SessionName1 /console /command "cd ""/home/username1/logs/uut/MN00093\IVT Gen2""" "get event* c:\tmp"
Regarding the bit about /defaults – what I mean is, if I for example use /synchronize parameter - if I dont specify the /default parameter, its gonna ask the user, whether I want to port to local, remote, which files to overwrite etc.
Is there a way to specify all these options manually in command line parameters? other than /defaults?
No. But you can run WinSCP with custom INI file with your preferences.

Reply with quote

Carmageddon
Joined:
Posts:
4
Location:
Israel

Re: Issue with passing command line parameter (path) with space

Thank you! it works indeed :)
I still dont quite get why this works though, because the double-double quotes (according to the documetnation), are designed to escape a quotation character(use literally) - at least according to the explanation.

So, you might want to update the documentation along with an example, as this bit isnt quite clear:
Command parameters that include space(s) have to be enclosed in double-quotes. To use double-quote literally, double it:
Should be:
Command parameters that include space(s) have to be enclosed in DOUBLE-double-quotes. To use double-quote literally, double it:
And the example
put "file with spaces and ""quotes"".html"
Needs to be:
put ""file with spaces and ""quotes"".html""
At least that is the way you fixed the example in my case, and which actually works for me.

Again, thank you!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,025
Location:
Prague, Czechia

Re: Issue with passing command line parameter (path) with space

Carmageddon wrote:

I still dont quite get why this works though, because the double-double quotes (according to the documetnation), are designed to escape a quotation character(use literally) - at least according to the explanation.
The double-double-quoting here is because of the command-line not because of the script, what the documentation refers to. This is not documented, but the behaviour is identical to the double-double-quoting in the script file. So the actual script command does not have any double-double quotes. If it had, there would had to be quad-double-quotes on the command line.

Reply with quote

riyas_26
Joined:
Posts:
1

applied two double quote yet no luck

I am using the below command and the local path is havin space , so made it under two double quotes
but still i m getting error "Too many parameters for command 'lcd'."

The file is getting downloaded in the same path where i am executing the script, not going to the
path which i explictily made under lcd.

please help experts to fix it.

winscp version:4.1.9(build 416)
"C:\Program Files\WinSCP\WinSCP.com" 
/log="d:\WinSCP.log" /ini=nul 
/command "option confirm off"
 "option batch continue" 
 "open sftp://testuser:password@20.20.20.20/" 
 "cd /44/remotepath/2021/MAR/remotefolder" 
 "lcd ""Z:\test path\2021\Mar""" 
 "get REMOTEFILE.TXT" "exit"
confirm      off
batch        continue
Searching for host...
Connecting to host...
Authenticating...
The server's host key was not found in the cache. You have no guarantee that the
 server is the computer you think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 ************************
If you trust this host, press Yes. To connect without adding host key to the cac
he, press No. To abandon the connection press Cancel.
Continue connecting and add host key to the cache?
(Y)es, (N)o, C(a)ncel, (C)opy Key: Yes
Using username "testuser".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] testuser@20.20.20.20
/44/remotepath/2021/MAR/remotefolder
Too many parameters for command 'lcd'.
REMOTEFILE.TXT       |          0 KiB |    0.0 KiB/s | binary | 100%

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
36,025
Location:
Prague, Czechia

Re: applied two double quote yet no luck

riyas_26 wrote:

I am using the below command and the local path is havin space , so made it under two double quotes
but still i m getting error "Too many parameters for command 'lcd'."
Your command-line seems ok. At least for the latest version of WinSCP. Note sure about 4.1.9, which is 12 years old. You urgently need to upgrade. If that does not help, post a log file on /loglevel=1.

Reply with quote

Advertisement

You can post new topics in this forum