Avatar of ibgadmin
ibgadmin
Flag 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
FTPWindows BatchScripting Languages

Avatar of undefined
Last Comment
MURUGESAN N

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MURUGESAN N

@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

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes