开发者

Need Shell Script to download file from ftp link?

开发者 https://www.devze.com 2023-03-25 12:51 出处:网络
I need to get this file ftp://1034733:ze3Kt699vy14@idx.living.net/idx_fl_ftp_down/idx_ftmyersbeach_dn/ftmyersbeach_data.zip

I need to get this file ftp://1034733:ze3Kt699vy14@idx.living.net/idx_fl_ftp_down/idx_ftmyersbeach_dn/ftmyersbeach_data.zip to my site's server. THis seems like an easy enough task... but, I cannot find a solution at this point. PHP doesn't seem to be capable of getting the job done. Wget was my next thought, however, godaddy's installation of wget gives me a 'connection refused' problem (although it wget works for this on my computer - mac os x 10.6). I'm now thinking it has to do with godaddy's side of things, but I am stuck with what I have. My goal here is to write a script that will execute through a cron job (i need to开发者_运维知识库 download this file every day). Someone please help! I am to the point of ripping my hair out of my head! I've spent the last two weeks on this! Also, I've tried using curl through the shell and wget. both have failed. Unfortunately I only have access to this link, I do not have an ftp login for idx.living.net


#!/bin/sh

# ftpget - given an ftp: style URL, unwrap it, and try to obtain the file using ftp.

if [ $# -ne 2 ] && [ $# -ne 3 ]; then
  echo "Usage: $0 ftp://... username [password]" >&2
  exit 1
fi

# Typical URL: ftp://ftp.ncftp.com/2.7.1/ncftpd-2.7.1.tar.gz

if [ "$(echo $1 | cut -c1-6)" != "ftp://" ] ; then
  echo "$0: Malformed url. I need it to start with ftp://" >&2;
  exit 1
fi

server="$(echo $1 | cut -d/ -f3)"
filename="/$(echo $1 | cut -d/ -f4-)"
basefile="$(basename $filename)"
username="$(echo $2)"
password=""
if [ $# -eq 3 ] ; then
  password="$(echo $3)"
fi

#rm $basefile
echo ${0}: Downloading $basefile from server $server

ftp -n << EOF
open $server
user $username $password
bin
get $filename $basefile
quit
EOF

if [ $? -eq 0 ] ; then
  #chmod +x $basefile
  ls -l $basefile
fi

exit 0
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号