Command line + winscp under windows to realize remote file transfer with linux

Install WinSCP

WinSCP is an open source graphical SFTP client for SSH for Windows. Also supports SCP protocol. Its main function is to securely copy files between local and remote computers, and to edit files directly.
- Download: https://winscp.net/eng/download.php
- Install

Set the environment variable to add the winscp path

Right-click My Computer -> Select Properties -> Select Advanced System Settings -> System Properties Item -> Advanced -> Environment Variables -> System Environment Variables -> Select PATH Edit Add a semicolon at the end of
the value line ";" and then Add the path to winscp

Of course, you can also directly call winscp.exe by cd to the installation path of winscp, but this is not convenient for batch processing in the code.

Use winscp command

Reference https://www.cnblogs.com/binw/p/4065607.html

Open the cmd command line window under windows, or call the command line in the code, use the following commands to upload files from windows to linux or download files on Linux

1. Upload

winscp.exe /console /command "option batch continue" "option confirm off" "open sftp://user:pwd@ip:port" "option transfer binary" "put D:\需要上传的文件路径 /服务器文件存放目录/" "exit" /log=log_file.txt

for example:

winscp.exe /console /command "option batch continue" "option confirm off" "open sftp://ggg:ggg@[2001:25gg:1004:5043:ae1f:gggg:gggg:gggg]:22" "option transfer binary" "put D:\1.pdf /home/ggg/" "exit" /log=D:\log_file.txt
  • winscp421.exe /console /command command name
  • "option batch continue" default batch
  • "option confirm off" closes the prompt
  • "open sftp://user:pwd@ip:port" user: access user name, pwd: user password, ip: ip address, port: port number is 22 by default. IPv6 addresses need to be enclosed in []
  • "option transfer binary" transfer using binary format
  • log=log_file.txt log file address
  • "exit" :: exit after executing the command

2. Download

winscp.exe /console /command "option batch continue" "option confirm off" "open sftp://user:pwd@ip:port" "option transfer binary" "get /服务器文件路径 D:\保存文件路径\" "exit" /log=log_file.txt

for example:

winscp.exe /console /command "option batch continue" "option confirm off" "open sftp://ggg:ggg@[2001:25gg:1004:5043:ae1f:gggg:gggg:gggg]:22" "option transfer binary" "get //home/gggy/1.pdf D:\" "exit" /log=D:\log_file.txt 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324743082&siteId=291194637