Batch file for file transfer from network shared path to unix server

Advertisement

Zapp
Joined:
Posts:
1

Batch file for file transfer from network shared path to unix server

Hi,

I have to automate file transfer from NAS path location to unix server. Have been using below code but its throwing error as mentioned below (Also not able to find the winscp.log file in my system, can it work without that, if not what can be the alternative approach):

code:

@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\writable\path\to\log\WinSCP.log" /ini=nul ^
/command ^
"open sftp://zapp:xxx@hostname/ -hostkey=""ssh-rsa 2048 k6KSozSpdMksDTVkhLKUR7GDKgTHspD5cgeYTRENsU8=""" ^

"put filename.txt /home/zapp/Testdir/filename_Test.txt" ^
"exit"

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

exit /b %WINSCP_RESULT%

Result:
Please find attachment.

ResultCMD.PNG

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
29,791
Location:
Prague, Czechia

Re: Batch file for file transfer from network shared path to unix server

1) I'm pretty sure that C:\writable\path\to\log\WinSCP.log is not a valid existing path on your system. Use a real path, instead of this placeholder.
2) Your batch file syntax is wrong. You cannot have an unescaped empty line between "open" and "put" lines.
3) It seems that you have a new line between "ssh-rsa 2048" and "k6KSozSpdMksDTVkhLKUR7GDKgTHspD5cgeYTRENsU8".

Reply with quote

Advertisement

You can post new topics in this forum