Link to home
Start Free TrialLog in
Avatar of ibgadmin
ibgadminFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@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