我想将40天之前的文件从远程主机传输到本地主机。我能够连接远程服务器,但无法将文件从远程传输到本地服务器。它导致错误,提示没有文件没有这样的文件或目录,但文件存在于远程主机上。
file=`sshpass -p "password" ssh username@server_ip "find /arch -type f -ctime -40"`
sshpass -p "password" scp -r username@server_ip:$file /arch
echo SCP Completed.
cp: cannot stat ‘/arch/file1.xls’: No such file or directory
您必须照顾一两件事:
长话短说,可能您的问题不是sshpass
。
从现在开始,我们认为您没有与权限相关的问题。
您可以做的是这样的:
files="$(sshpass -p "passwd" ssh -l username rhost "find /arch -type f -ctime -40")"
for file in ${files}; do
if sshpass -p "passwd" scp "username@rhost:${file}" /arch; then
printf "SCP Completed\n"
fi
done
从理论上讲,$files
将不会包含您无法抓取的内容,因为find
它将打印在stderr
您无法访问的文件(文件夹)中,因此您应该以单独的方式进行管理。
在所有的选项,您可以合并stderr
使用stdout
,并在您添加一个条件for
循环或保存在另一个变种(或文件),并分别循环他们的错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句