Linux FTP Shell
jopen
9年前
#!/bin/bash ### serverip=127.0.0.1 serveruser=username serverpass=passwd remotedir=./ localdir=~/ftp_data getftp(){ # _st=`date +%s` echo "-----------------------------------------------------------------------------------------------------" echo "[`date +"%F %T.%N"`] - start ftp download on " $serverip ftp -ivn $serverip << END_FTP open $serverip user $serveruser $serverpass binary cd $remotedir ls lcd $localdir mget test.txt close bye END_FTP echo "local directory listing" ls -l $localdir/*.txt echo -e "[`date +"%F %T.%N"`] - completed,using `expr $(date +%s) - $_st` secs." } getlftp(){ # _st=`date +%s` echo "-----------------------------------------------------------------------------------------------------" echo "[`date +"%F %T.%N"`] - start lftp download on " $serverip lftp $username:$passwd@$serverip << END_FTP set xfer:clobber on cd $remotedir ls lcd $localdir mget test.txt quit END_FTP echo "local directory listing" ls -l $localdir/*.txt echo -e "[`date +"%F %T.%N"`] - completed,using `expr $(date +%s) - $_st` secs." } wgetftp(){ _st=`date +%s` echo "-----------------------------------------------------------------------------------------------------" echo "[`date +"%F %T.%N"`] - start ftp download on " $serverip echo "remote directory listing" #curl ftp://$serverip -u $username:$passwd #curl ftp://$serverip/test.txt -u $username:$passwd -o test.txt wget -O test.txt ftp://$username:$passwd@$serverip/test.txt #wget -nH -m ftp://$username:$passwd@$serverip/ echo "local directory listing" ls -l $localdir/*.txt echo -e "[`date +"%F %T.%N"`] - completed,using `expr $(date +%s) - $_st` secs." } ### ftp_download(){ while true do _week=`date +%w` _hour=`date +%H%M` if [ $_week -gt 0 -a $_week -lt 6 -a $_hour -ge 900 -a $_hour -le 1530 ]; then # wgetftp >> ./logs/get_ftp.log.`date +%F` 2>&1 getftp >> ./logs/get_ftp.log.`date +%F` 2>&1 fi sleep 30 done } # ftp_download