Shell script to download file using ftp

Printer-friendly versionPDF version
#!/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
AttachmentSize
ftpget.sh817 bytes
No votes yet
paiphatinut1973's picture

Interesting information, I

Interesting information, I bookmark this page! viagra online viagra order online cialis buy online buy levitra sorry :( d7fnq02bdjkn7iassl3aber