Problem with space in folder name

Advertisement

surfer01
Guest

Problem with space in folder name

Hello,

I have the following problem. I use WinSCP with a script to synchronize some folders to a webdrive. It works fine if the folder name does not include a space (like Bilder). If it includes a space (like Eigene Bilder) it does not work and I can't change to this folder on the webspace. Any idea how to solve the problem?
@echo off
set pathname0="/users/XXXXXXX/Backup_PC/Laufwerk_J/Eigene Bilder/"
 
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="K:\Test\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://xxxx:xxxx@sftp.hidrive.strato.com/ -hostkey=""ssh-rsa xxxx xx:xx:xx:Xx:xx:xx:xx:xx""" ^
    "cd %pathname0%" ^
    "synchronize remote J:\" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%

Regards
surfer

Reply with quote

Advertisement

Guest

Hi Martin,

Sorry, but that doesn't work :-( I get this error message in the logfile:
> 2017-02-06 20:07:47.296 Script: cd "/users/xxxxx/Backup_PC/Laufwerk_J/Eigene
. 2017-02-06 20:07:47.296 Changing directory to "/users/xxxxx/Backup_PC/Laufwerk_J/Eigene".
. 2017-02-06 20:07:47.296 Getting real path for '/users/xxxxx/Backup_PC/Laufwerk_J/Eigene'
> 2017-02-06 20:07:47.296 Type: SSH_FXP_REALPATH, Size: 53, Number: 272
< 2017-02-06 20:07:47.374 Type: SSH_FXP_STATUS, Size: 29, Number: 272
< 2017-02-06 20:07:47.374 Status code: 2, Message: 272, Server: No such file, Language:

set pathname0="/users/surfer-01/Backup_PC/Laufwerk_J/Eigene Bilder/"
"cd ""%pathname0%""" ^
Any other Idea?

Regards
surfer

Reply with quote

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

OK, remove the quotes in the set command:
set pathname0=/users/XXXXXXX/Backup_PC/Laufwerk_J/Eigene Bilder/
(that's basically not a WinSCP issue)

Reply with quote

Advertisement

Web88
Joined:
Posts:
4
Location:
Düsseldorf, Deutschland

I have the some issue..

set privatekeypath=c:\Projects\UploadScript\Privatekey\privatekey.ppk
set user=user
set path=/user
set scriptPath=c:\Projects\UploadScript\
set inputhPath=c:\Projects\UploadScript\Input\
 
%scriptPath%\App\WinSCP\winscp.exe /ini=nul /log=%~dp0\App\Logs\log_%datetime%.txt /command ^
    "open sftp://%user%@server.net/ -hostkey=""ssh-rsa "" -privatekey="%privatekeypath%"" ^
    "cd %path%" ^
    "lcd %inputhPath%" ^
    "get *.* *.* -delete -nopreservetime" ^
    "close" ^
    "exit"
pause
is working fine for me. But I have a free space in the folder path where the script is located.

set privatekeypath=c:\Projects\Upload Script\Privatekey\privatekey.ppk
set user=user
set path=/user
set scriptPath=c:\Projects\Upload Script\
set inputhPath=c:\Projects\Upload Script\Input\
 
%scriptPath%\App\WinSCP\winscp.exe /ini=nul /log=%~dp0\App\Logs\log_%datetime%.txt /command ^
    "open sftp://%user%@server.net/ -hostkey=""ssh-rsa "" -privatekey="%privatekeypath%"" ^
    "cd %path%" ^
    "lcd %inputhPath%" ^
    "get *.* *.* -delete -nopreservetime" ^
    "close" ^
    "exit"
pause

I am getting the error
"c:\Projects\Upload Script\" is not recognized as an internal or external command, operable program or batch file.
I tried to double quote the path, but still is not working for me.
set privatekeypath=c:\Projects\Upload Script\Privatekey\privatekey.ppk
set user=user
set path=/user
set scriptPath=c:\Projects\Upload Script\
set inputhPath=c:\Projects\Upload Script\Input\
 
""%scriptPath%""\App\WinSCP\winscp.exe /ini=nul /log=%~dp0\App\Logs\log_%datetime%.txt /command ^
    "open sftp://%user%@server.net/ -hostkey=""ssh-rsa "" -privatekey="""%privatekeypath%"""" ^
    "cd %path%" ^
    "lcd ""%inputhPath%""" ^
    "get *.* *.* -delete -nopreservetime" ^
    "close" ^
    "exit"
pause
Now I'm getting the error
The system cannot find the path specified.
Thanks for your support.

Reply with quote

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

Re: I have the some issue..

You have to use double double quotes (neither single nor triple) – the same way you have them correctly around -hostkey argument (and in lcd command):
 "open sftp://.../ -hostkey=""ssh-rsa "" -privatekey=""%privatekeypath%""" ^
See https://winscp.net/eng/docs/commandline#syntax

Your duplicate question on Stack Overflow:
Error quoting spaces to locate destination filepath WinSCP script issue

Reply with quote

Advertisement

wilf32
Joined:
Posts:
1

Script: Failed

Hi,

Sorry to bring up old topics, but I didn't want to create new duplicate topics.

I have this script which works fine however I want to change the "C:\" folder
open scp://winscp:XXXXXXXXX@192.168.XX.XXX/ -hostkey="ssh-ed25519 255 *******************************************="
 
synchronize local -delete "C:\Tools\zammad /var/tmp/zammad_backup/"
 
exit
Below is the desired folder location but it doesn't work due to the spaces. I have tried it with and without the quotes.
open scp://winscp:XXXXXXXXX@192.168.XX.XXX/ -hostkey="ssh-ed25519 255 *******************************************="
 
synchronize local -delete "C:\Tools\IT Helpdesk Information\Backups\zammad_backups /var/tmp/zammad_backup/"
 
exit
I look forward to your response.

Thank you.

Reply with quote

user212121
Joined:
Posts:
2

Same Problem

Solved: When I used the synchronize command, the directory couldn't be found. You have to put it in double quotations!
@echo off
:start
cls
echo             Roboter SD-Karte zuruecksetzen
echo             ==============================
echo.
echo   [1] Loeschen
echo   [2] Beenden
echo.
 
set asw=0
set /p asw="Bitte Auswahl eingeben: "
 
if %asw%==1 goto Loeschen
if %asw%==2 goto Beenden
 
:Loeschen
net use t: \\nas_Trainer\Trainer /user:Trainer
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Users\ABB Kunde\Desktop\Test.log" /ini=nul ^
/command ^
"option batch abort" "open sftp://Default%%20User:robotics@191.168.64.101/ -hostkey=""ssh-rsa 2048 e6:88:f5:ae:c8:60:02:35:c6:a4:4c:4c:0a:b0:58:7e""" "cd /" "rmdir BACKUP" "rmdir RSC" "rmdir TEMP" "cd /IRB_253/HOME" "rm *.*" "synchronize remote "C:\Users\ABB Kunde\Desktop\SD" /" "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo.
  echo Success
) else (
  echo.
  echo Error
)
 
pause
goto start
 
:Beenden
Last edited by user212121 on 2021-09-07 13:04; edited 2 times in total

Reply with quote

Advertisement

user212121
Joined:
Posts:
2

Re: Same Problem

Hello again,
I have realized that I have to put the directory in double quotations.
Like this if anyone is wondering
"synchronize remote ""C:\Users\ABB Kunde\Desktop\SD"" /"

Reply with quote

Advertisement

You can post new topics in this forum