Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use ssh to upload files in batch

Shulou Source: shulou.com Published: 2022-06-01 21:04:31 09月10日 Update

This article introduces the knowledge of "how to use ssh to upload files in batch". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Do not enter password for scp upload

If you want to use scp to upload files, the first step is to remove the scp upload and enter the password. Otherwise, there will be no way to upload in bulk. For details, please see: ssh does not need to enter a password

II. Ssh batch upload script

1. Put the list of files to be uploaded into a test file

Root@ubuntu:/home/zhangy# cat test/home/zhangy/test/aaa/home/zhangy/test/nginx.conf/home/zhangy/test/test.sql/home/zhangy/test/pa.txt/home/zhangy/test/password

The file to be uploaded above.

2. Script uploaded in batch

Vim file_ upload.sh[neiqian]

#! / bin/shDATE= `date +% Y% masks% dudes% H`if [$1] then for file in $(sed'/ ^ $/ d' $1) / / remove the blank line do if [- f $file] / / ordinary file then res= `scp $file $2sed $file` / upload file if [- z $res] / upload successful then echo $file > > $ {DATE} _ upload.log / / successfully uploaded log fi elif [- d $file] / / directory then res= `scp-r $file $2purl $file`if [- z $res] then echo $file > > ${DATE} _ upload.log fi fi doneelse echo "no file" > > ${DATE} _ error.logfi

After the upload is successful, a blank line is returned. If the upload is not successful, nothing will be returned.

[erji] 3. Upload format [erji]

. / file_upload.sh test 192.168.1.13

Test is the place to upload the list file, [neiqian] 192.168.1.13 file to.

This is the end of the content of "how to use ssh to upload files in bulk". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Files success passwords input content more knowledge blank lines scripts practical ordinary successful learning next no methods dilemmas places actual situations articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Huawei Redmi Microsoft