Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


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

Your duplicate (and answered) question on Stack Overflow:

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.

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\" ^
  /log="D:\temp\WinSCP.log" /ini=nul ^
  /command ^
   "open sftp://username:password@sftp.server1/logs/Test/ -hostkey=""ssh-key=""" ^
"lcd %mydir%" ^
    "get *.xml>1D" ^
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error

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.