We help IT Professionals succeed at work.

Winscp ftp script not working

I have a WinSCP batch file that I am trying to utilize for uploading a file.  The batch when run does open, but logs in only and does not upload the file or exit even from the script.  Just keeps the window open.  Any help would be greatly appreciated.  Attaching file.
71142Orders.txt
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
You have a tab character at the end of line 6 ("open ..."), which prevents the line continuation form working, and in line 9 ("put ..."), you're defining the target for the put as a separate command.
Can't test it, but try it like this:
@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\Scripts\71142Orders.log" /ini=nul ^
  /command ^
    "open ftp://71142:mypassword@edi.unfi.com/" ^
    "lcd \\ibgfs1\ecomedate\it_out\UNFI\Orders" ^
    "cd /Orders" ^
    "put UNFIPHI*.txt ." ^
    "exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)

exit /b %WINSCP_RESULT%

Open in new window

Murugesan NWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
CERTIFIED EXPERT
@ibgadmin

I am from Linux oriented.
Hence thought of sharing the same.

Tried the same using:
1. Started vmplayer (Linux) at windows
2. Shared a folder at windows to Linux
3. mounted that folder at Linux
4. Modified given code based on above steps
5. Written codes (as per commands from FTP/batch commands)

@ECHO OFF
"C:\PROGRA~2\WinSCP\WinSCP.com" ^
	/LOG="C:\Users\murugesandins\71142Orders.log" /ini=nul ^
	/COMMAND ^
	"OPEN sftp://root:password@VMLINUXIP4 -hostkey=""ssh-rsa 2048 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="""^
	"LCD \\EE\murugesandins\experts_exchange" ^
	"CD /mnt/murugesandins" ^
	"PUT murugesandins.txt" ^
	"EXIT"
SET WINSCP_RESULT=%ERRORLEVEL%
IF %WINSCP_RESULT% EQU 0 (
	ECHO SUCCESS
) ELSE (
  ECHO ERROR
)
EXIT /b %WINSCP_RESULT%

Open in new window


Sample output:
C:\Users\murugesandins> .\29176518.cmd
Searching for host...
Connecting to host...
Authenticating...
Using username "root".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] root@VMLINUXIP4
\\EE\murugesandins\experts_exchange
/mnt/murugesandins
murugesandins.txt                     |           6 KB |    0.0 KB/s | binary | 100%
SUCCESS

C:\Users\murugesandins>

Open in new window


Verified the file at mounted location of Linux
root@VMLINUXIP4 /mnt/murugesandins [ 0 ]
$ /usr/bin/ls -l murugesandins.txt
-rwxrwSrwx 1 root root 6652 Mar 24 13:26 murugesandins.txt
root@VMLINUXIP4 /mnt/murugesandins [ 0 ]
$

Open in new window

13:26 => 01:26 PM

Also verified the same using C:\Windows\System32\cmd.exe
C:\Users\murugesandins\experts_exchange> DIR /O:D /A /X murugesandins.txt
 Volume in drive C is C
 Volume Serial Number is CC14-05B4

 Directory of C:\Users\murugesandins\experts_exchange

Tue 24-Mar-2020  01:26 PM             6,652              murugesandins.txt
               1 File(s)          6,652 bytes
               0 Dir(s)  223,532,724,224 bytes free

C:\Users\murugesandins\experts_exchange>

Open in new window