Shell script to remove whole ftp directory structure

by Vivek Gite on April 9, 2008 · 2 comments · [ vivek@nixcraft.com ]

#!/bin/bash
# Shell script to remove whole (nuke) ftp directory structure
# See url for more info:
# http://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
4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

spielen August 23, 2009

nice script

Reply

Diego Siqueira October 19, 2010

thx
this will help me a lot to study Shell Scritps

Reply

Leave a Comment

You can use these HTML tags and attributes for UNIX commands or shell scripts: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 10 + 8 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a script.



Tagged as: , , , , , , , , , , ,