Reputation: 3445
I have to transfer files whose names consists of two variables X, Y and they are in the directory ABC in ftp server to my local unix directory XYZ. after transfering files i have to go to local directory path and I should untar (input files are compressed files) them. I have to use username and password for connecting to FTP. When copying files to local server also I have to use my username and password.
Here's my current attempt. Will it work? How can I improve it?
ftp -n hostname <<EOF
user username pwd
cd ABC
get ls *X*.tar | ls *Y*.tar username1@pwd1 : XYZ
EOF
bye
for next in `ls *.tar`
do
tar -zvxf $next
done
Upvotes: 1
Views: 13171
Reputation: 61
You can use wget
to download files from FTP server to unix
system
cd YOUR_DIRECTORY
wget --user=USERNAME --password='PASSWORD' HOST_NAME/REMOTE_PATH/FILE_NAME.EXTENSION
Upvotes: -1
Reputation: 9240
I would suggest you just look into the manual of ftp command line ftp-tool and script with that.
Alternative: use wget to download the ftp-file to local machine, then scp to target machine, I suppose using public-key-authentication for ssh, that scp does not need a password, then it should end up simple like this.
wget --ftp-user=$USERNAME --ftp-password=$PASSWORD ftp://$HOSTNAME/ABC/$Y.tar
scp $Y.tar $SCPUSER@$SCPHOST/targetpath/$X.tar
Upvotes: 1
Reputation: 7259
Please try below code. Hope this helps you.
#! /bin/bash
cd local_path
USER='username'
PASSWD='password'
file_name='files'
for HOST in ftpserver
do
echo $HOST
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
bin
prompt
cd "remote_path"
lcd "local_path"
mget $file_name.gz*
quit
END_SCRIPT
done
#extract file
mkdir -p ../archive/$DATE
for HOST in ftpserver
do
gunzip $file_name.gz
done
Upvotes: 2