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
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
#! /bin/bash
while read myline
do
for i in $myline
do
if [ -f $i ]
then
location=$(echo "$i" | awk -F "/" '{ print "", $6, $7, $8 }' 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
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
SCP syntax is pretty simple. Just invoke SCP followed by the remote username, @, the IP address or host, colon, and the path to the file. If not specified, the default path is the remote user's home directory. Then, define the local path where the file will be stored locally.
The scp tool relies on SSH (Secure Shell) to transfer files, so all you need is the username and password for the source and target systems. Another advantage is that with SCP you can move files between two remote servers, from your local machine in addition to transferring data between local and remote machines.
To copy a directory (and all the files it contains), use scp with the -r option. This tells scp to recursively copy the source directory and its contents. You'll be prompted for your password on the source system ( deathstar.com ).
I don't see where the "permission denied" error might come from; run the script with bash -x
to see the command which causes the error. Maybe it's not what you expect.
Also try rsync
instead of inventing the wheel again:
rsync --dirs $i [email protected]:$b
--dirs
will create the necessary folders on the remote side (and it will give you good error messages when something fails).
It might even be possible to do everything with a single call to rsync
if you have the same folder structure on both sides:
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.
rsync
will figure out which files need to be transferred and copy only those. If you want to transfer only a subset, use --include-from
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With