问题
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