gpt4 book ai didi

linux - 使用 scp 命令将特定文件从服务器复制到本地计算机 (Linux)

转载 作者:太空宇宙 更新时间:2023-11-04 04:11:16 25 4
gpt4 key购买 nike

我使用基于Linux的操作系统。假设我有一个服务器包含 10 个文件,例如 tmp1 .... tmp10,我想将三个特定文件复制到我的本地计算机,比如说 tmp3、tmp7 和 tmp10。在这种情况下,我必须使用“scp-command”三次,其中我也必须输入密码三次。问题是,我必须经常执行此过程,所以我“编写”了下面的脚本。我的问题是,脚本运行时没有任何错误消息,但文件没有被复制。

echo "insert path of source:" #prompt to enter the path of files you want to copy
read SOURCE # saving the path in the variable SOURCE
echo "insert path of target:" #prompt to enter the path, where you want to past the copied files
read TARGET # saving the path in the variable SOURCE
echo "Insert the port" # prompt to enter the port of the server
read port # saving the port in the variable PORT
echo "Password?" # asking for password
read -s -a PASSWORD # saving the password in the variable PASSWORD
x=(tmp1 tmp2) # An array contains the files i want to copy.
for i in "${x[@]}" # A for-loop to copy each of the files in the array (x) from the SOURCE to the TARGET
do
echo "the file $i" # just to check if the array has been read.
#!/usr/bin/expect -f # to read the expect-programm
expect -c "
spawn /usr/bin/scp -P $prot $SOURCE/$i $TARGET
expect {
"Password:" { send $PASSWORD\r\n; interact }
eof { exit }
}
exit
"
done # End of the for-loop
PASSWORD=0 # To delete the variable PASSWORD

提前谢谢您!!

最佳答案

您可以使用 as scp 来复制多个文件。例如:

scp remote:tmp{3,7,10} local

关于linux - 使用 scp 命令将特定文件从服务器复制到本地计算机 (Linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18975800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com