bash scp 和远程 mkdir -p
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14702853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
scp and remote mkdir -p
提问by Jessesiu
hi i have some file path like /ifshk5/BC_IP/PROJECT/T1 1073/T11073_RICljiR/split/AG19_235/120225_I872_FCC0HN2ACXX_L8_RICljiRSYHSD2-1-IP AAPEK-17_1.fq.gz
嗨,我有一些文件路径,如 /ifshk5/BC_IP/PROJECT/T1 1073/T11073_RICljiR/split/AG19_235/120225_I872_FCC0HN2ACXX_L8_RICljiRSYHSD2-1-IP AAPEKq.gzf。
i need copy files from one ftp server to other. and also need to create directory if it not exist in server. i login the sever which contains those file then run this code
我需要将文件从一台 ftp 服务器复制到另一台。如果服务器中不存在目录,还需要创建目录。我登录包含这些文件的服务器然后运行此代码
#! /bin/bash
while read myline
do
for i in $myline
do
if [ -f $i ]
then
location=$(echo "$i" | awk -F "/" '{ print "", , , }' OFS="/")
#location shows /T11073_RICekkR/Fq/AS59_59304
location="/opt/CLiMB/Storage3/ftp/ftp_climb/100033"$location
echo $location
ssh [email protected] mkdir -p $location
scp -r $i [email protected]:$location
fi
done
done < /ifshk5/BC_IP/PROJECT/T11073/T11073_all_3254.fq.list
it has some problem, 1. it can't work always shows permission denied, please try again. but when i direct type
它有一些问题,1.它不能工作总是显示权限被拒绝,请再试一次。但是当我直接打字时
ssh [email protected] mkdir -p /sample/xxxx
it can work, and the new dir location is right it shows like /opt/CLiMB/Storage3/ftp/ftp_climb/100033/T11073_RICekkR/Fq/AS59_59304
它可以工作,并且新的目录位置是正确的,它显示为 /opt/CLiMB/Storage3/ftp/ftp_climb/100033/T11073_RICekkR/Fq/AS59_59304
回答by Aaron Digulla
I don't see where the "permission denied" error might come from; run the script with bash -xto see the command which causes the error. Maybe it's not what you expect.
我不知道“权限被拒绝”错误可能来自哪里;运行脚本bash -x以查看导致错误的命令。也许这不是你所期望的。
Also try rsyncinstead of inventing the wheel again:
也尝试rsync而不是再次发明轮子:
rsync --dirs $i [email protected]:$b
--dirswill create the necessary folders on the remote side (and it will give you good error messages when something fails).
--dirs将在远程端创建必要的文件夹(当出现故障时,它会给你很好的错误消息)。
It might even be possible to do everything with a single call to rsyncif you have the same folder structure on both sides:
rsync如果双方的文件夹结构相同,甚至可以通过一次调用完成所有操作:
rsync -avP /ifshk5/BC_IP/PROJECT/T11073/ [email protected]:/opt/CLiMB/Storage3/ftp/ftp_climb/100033/
Note the /after the paths! Don't omit them.
注意/路径之后!不要省略它们。
rsyncwill figure out which files need to be transferred and copy only those. If you want to transfer only a subset, use --include-from
rsync将找出需要传输的文件并仅复制那些文件。如果您只想传输一个子集,请使用--include-from

