Shell script to remove whole ftp directory structure

in Categories Ftp last updated April 9, 2008
#!/bin/bash
# Shell script to remove whole (nuke) ftp directory structure  
# See url for more info:
# https://www.cyberciti.biz/tips/how-to-nuke-a-ftp-server.html
# -----------------------------------------------
# Copyright (c) 2006 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# NOTE: Requires ncftp/ncftlls ftp clients/commands
# =========================================================================
# Ftp server settings 
 
### change me ###############################
# ftp login user
FUSER='vivek' 
 
# ftp password
FPASSWD='password' 
 
# ftp server ip/name 
FTPS='array05.wan.nixcraft.co.in'
 
# ftp dirs to nuke Separate multiple dirs using
# a blank/white space i.e. /dir1 /dir2)
FTPDIRS='/dir1 /dir2'
##############################################
for d in $FTPDIRS
do
 subdires="$(ncftpls -u $FUSER -p $FPASSWD  ftp://${FTPS}/${d}/)"
 for dir in $subdires
 do
 rdir="${d}/${dir}"
ncftp -u"$FUSER" -p"$FPASSWD" $FTPS<<EOF
cd $rdir
rm *
rmdir $rdir
quit
EOF
  done
done
# end of script

Shell script to copy all files recursively and upload them to remote FTP server

in Categories Backup, Ftp last updated April 9, 2008
#!/bin/bash
# Shell script to copy all files recursively and upload them to 
# remote FTP server (copy local all directories/tree to remote ftp server)
#
# If you want to use this script in cron then make sure you have
# file pointed by $AUTHFILE (see below) and add lines to it:
# host ftp.mycorp.com
# user myftpuser
# pass mypassword
# 
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2005 nixCraft
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
FTP="/usr/bin/ncftpput"
CMD=""
AUTHFILE="/root/.myupload"
 
if [ -f $AUTHFILE ] ; then 
  # use the file for auth
  CMD="$FTP -m -R -f $AUTHFILE $myf $remotedir $localdir"
else
  echo "*** To terminate at any point hit [ CTRL + C ] ***"
  read -p "Enter ftpserver name : " myf
  read -p "Enter ftp username : " myu
  read -s -p "Enter ftp password : " myp
  echo ""
  read -p "Enter ftp remote directory [/] : " remotedir
  read -p "Enter local directory to upload path [.] : " localdir
  [ "$remotedir" == "" ] && remotedir="/" || :
  [ "$localdir" == "" ] && localdir="." || :
  CMD="$FTP -m -R -u $myu -p $myp $myf $remotedir $localdir"
fi
 
$CMD