Automate file transfer activity from local machine to remote machine using WinSCP script

时间秒杀一切 提交于 2020-01-24 01:43:28

问题


I want to transfer file(s) in bulk (approx 50 files at a time) from my local machine to remote machine (Linux server) and I wanted to automate this activity using WinSCP.

I already have generated code by doing manually in WinSCP. Saved the code and created batch file. But it is throwing error like

The filename, directory name, or volume label syntax is incorrect

The system cannot find the path specified.

However the given destination and source are valid/correct.

@echo

"open sftp://XXXXXXXXXXXXXX/ -hostkey=""ssh-rsa XXXX gk:op:09:n8:00:44:32:00:11:bn:mm:pp:45:bh:03:ea"""
"lcd C:\Users\007\Documents\testdata"
"cd /XXX/XXX/XXX/testdata"
"put *"
"exit"

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

exit /b %WINSCP_RESULT%

回答1:


What you have posted is no way a batch file that WinSCP would generate. You must have manually altered the script (and broke it).

A batch file that WinSCP would generate would look like:

@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\writable\path\to\log\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://XXXXXXXXXXXXXX/ -hostkey=""ssh-rsa XXXX gk:op:09:n8:00:44:32:00:11:bn:mm:pp:45:bh:03:ea""" ^
    "lcd C:\Users\007\Documents\testdata" ^
    "cd /XXX/XXX/XXX/testdata" ^
    "put *" ^
    "exit"

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

exit /b %WINSCP_RESULT%

An example of WinSCP dialog for generating a batch file for a file transfer:



来源:https://stackoverflow.com/questions/57054701/automate-file-transfer-activity-from-local-machine-to-remote-machine-using-winsc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!