Post a reply

Options
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)

Options

Topic review

agadkari

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