We often use the WINSCP tool to upload get files via the SFTP protocol, which describes batch processing of files through bat.
First, we open the DOS command window using CD \d:D \WINSCP to open the WinSCP installation directory
Upload file:
Winscp.exe/console/command "option Batch Continue" "option confirm off" "open Sftp://user:[email Protected]:p ort" "Optio N Transfer binary "" Put d:\ file path to upload/server file directory "exit"/log=log_file.txt
Here for the convenience of understanding, explained.
Winscp421.exe/console/command command name
"Option batch Continue" default batch
"option confirm off" prompt message
"Open ftp://user:[email protected]:p ort" User: Access username, pwd: User password, IP:IP address, Port: port number Default 22
"Option Transfer binary" is transmitted using binary format
Log=log_file.txt log file Address
"Exit":: Exit after executing command
Note: The above command after the parameters should be reflected in a line as you want to write separately can put the command to a file
such as: Aa.txt
Option echo off
Option Transfer Binary
Open <sftp_or_ftp>://<user>:<password>@CD <remote_dir>
Put *.doc
Exit
Execute the script with a command:winscp/script=aa.txt/ini=<winscp.ini_location>/log=<log_file>
If you need to configure the transport parameters in the Winscp.ini configuration, for example preservetime=0 keep the timestamp of the source file
Download file:
Here is the download file code, as with the upload, such as the need to write a separate script can be used as a separate save script execution.
CD/D D:\WinSCP
Winscp.exe/console/command "option Batch Continue" "option confirm off" "Open sftp://root:[email protected]:22" "option Transfer binary "" Get/test.txt D:\sftptest\ "Exit"/log=d:\sftptest\log.txt
WINSCP Automatic Script execution