Unable to change the directory through script using lcd command

Advertisement

agadkari
Joined:
Posts:
1
Location:
India

Unable to change the directory through script using lcd command

Hi All,

Greetings for the day!!

I am trying to download files sftp server to my local machine, with created a date-wise folder.
But it's falling at the point of lcd.

Here is my script.
@echo off
 
set datetime=%date:~7,2%%date:~4,2%%date:~10,4%
set "mydir=D:\Test\%datetime%\"
mkdir "%mydir%"
 
echo My Directory is created "%mydir%"
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="D:\temp\WinSCP.log" /ini=nul ^
  /command ^
   "open sftp://username:password@sftp.server1/logs/Test/ -hostkey=""ssh-key=""" ^
 
"lcd %mydir%" ^
 
    "get *.xml>1D" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%

Here is the Error Code:
> 2021-03-18 09:17:10.392 lcd D:\Test\18032021\
< 2021-03-18 09:17:10.392 Script: Unknown command '
< 2021-03-18 09:17:10.392 lcd'.
. 2021-03-18 09:17:10.393 Script: Failed
. 2021-03-18 09:17:10.393 Script: Exit code: 1
. 2021-03-18 09:17:10.393 Closing connection.
. 2021-03-18 09:17:10.393 Sending special code: 1
. 2021-03-18 09:17:10.579 Session sent command exit status 0
. 2021-03-18 09:17:10.579 Main session channel closed
. 2021-03-18 09:17:10.580 All channels closed
I tried with many options but it's still failing. Any suggestion pointer much appreciated.

Regards,
Aniruddha

Reply with quote

Advertisement

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

Re: Unable to change the directory through script using lcd command

See https://winscp.net/eng/docs/faq_batch_file#newline_escaping

Your duplicate (and answered) question on Stack Overflow:
Some WinSCP commands in a batch file are not working

Though here you have posted a batch file with syntax that will indeed produce the error you are describing. On Stack Overflow you did not preserve the exact indentation, so the error did not make sense.

Reply with quote

Advertisement

You can post new topics in this forum