File Transfer Protocol (FTP) is a standard network protocol used to transfer files to and from a remote network.
To transfer file using ftp,we require ftp server, user account and ftp client .
Below is the procedure to 'copy file using file transfer protocol (FTP) shell scrip' and we will see 'How to Use Linux FTP Command to Transfer Files'. In this shell script(filetoftp.sh) we will receive notification on mail if file transfer(ftp) fail due to any reason.
Manually to get and put the file on one server to another server(remote server):-
ftp -n 192.168.11.10
ftp>quote USER employee
ftp>quote PASS ******
230 OK. Current restricted directory is /
ftp> cd /data01
ftp> lcd /backup01 --> change local directory on local server.
ftp> mget ***.csv -->to get the file from ftp server to local server.
ftp> mput ****.csv -->to transfer file from local to ftp server.
Automatically transfer the file on remote server using shell script:-
/data01/crontab_scripts/tada_schedule/filetoftp.sh
#!/bin/sh
# Created by Sajid Quamer
#CSV file to be transfer from db server to ftp server
cd /data05/TADA_Master_curr
CURR_DT=`date +%d-%m-%Y`
export CURR_DT
CSV_FILE1=TADA_CITY_MASTER_$CURR_DT.csv
CSV_FILE2=TADA_POLICY_MASTER_$CURR_DT.csv
CSV_FILE3=TADA_EMPLOYEES_MASTER_$CURR_DT.csv
CSV_FILE4=Leave_pending_$CURR_DT.csv
CSV_FILE5=CONTRACT_DATA_$CURR_DT.csv
CSV_FILE6=BILL_DATA_$CURR_DT.csv
Scriptfile=/data01/crontab_scripts/tada_schedule/tadatoftp.sh
export CSV_FILE1
export CSV_FILE2
export CSV_FILE3
export CSV_FILE4
export CSV_FILE5
export CSV_FILE6
export Scriptfile
ftp -n << 'EOF'
open 192.168.11.10
quote USER *******
quote PASS *******
cd /employees
prompt no
lcd /data05/TADA_Master_curr
mput TADA_CITY_MASTER*
mput TADA_POLICY_MASTER*
mput TADA_EMPLOYEES_MASTER*
mput Leave_pending_*
bye
EOF
echo "done"
#check if a file exists or not
if [[ -f $CSV_FILE1 && -f $CSV_FILE2 && -f $CSV_FILE3 && -f $CSV_FILE4 ]]; then
echo "File Transfer Process was Successful and '$CSV_FILE1' exist"
else
echo "FTP File Transfer Process Failed '$CSV_FILE1' Does not exist at `hostname`. Please contact System Adminis
trator! $Scriptfile" | mailx -s "File Transfer Failed" abc@gmail.com, acb@gmail.com
fi
#check if a file exists or not
if [[ -f $CSV_FILE1 && -f $CSV_FILE2 && -f $CSV_FILE3 && -f $CSV_FILE4 ]]; then
echo "File Transfer Process was Successful and '$CSV_FILE2' exist"
else
echo "FTP File Transfer Process Failed '$CSV_FILE2' Does not exist at `hostname`. Please contact System Adminis
trator! $Scriptfile" | mailx -s " File Transfer Failed" abc@gmail.com, acb@gmail.com
fi
if [[ -f $CSV_FILE1 && -f $CSV_FILE2 && -f $CSV_FILE3 && -f $CSV_FILE4 ]]; then
echo "File Transfer Process was Successful and '$CSV_FILE3' exist"
else
echo "FTP File Transfer Process Failed '$CSV_FILE3' Does not exist at `hostname`. Please contact System Adminis
trator! $Scriptfile" | mailx -s " File Transfer Failed" abc@gmail.com, acb@gmail.com
fi
if [[ -f $CSV_FILE1 && -f $CSV_FILE2 && -f $CSV_FILE3 && -f $CSV_FILE4 ]]; then
echo "File Transfer Process was Successful and '$CSV_FILE4' exist"
else
echo "FTP File Transfer Process Failed '$CSV_FILE4' Does not exist at `hostname`. Please contact System Adminis
trator! $Scriptfile" | mailx -s "File Transfer Failed" abc@gmail.com, acb@gmail.com
fi
cd /data05/TADA_Master_curr
rm -rf $CSV_FILE1
rm -rf $CSV_FILE2
rm -rf $CSV_FILE3
rm -rf $CSV_FILE4
1 comment:
Vcyavunapht_hi Christina Evans https://wakelet.com/wake/TfQfPzSgtzaCoi21bRDSA
diafurnsifer
Post a Comment
Thanks for reading till end. I hope this will help you more to improve your knowledge.
Now it's your turn!
What do you think? Share your experience in the comments box and subscribe for more interesting post.