Shell script to remove whole ftp directory structure

by on April 9, 2008 · 2 comments

  1. #!/bin/bash
  2. # Shell script to remove whole (nuke) ftp directory structure
  3. # See url for more info:
  4. # http://www.cyberciti.biz/tips/how-to-nuke-a-ftp-server.html
  5. # -----------------------------------------------
  6. # Copyright (c) 2006 nixCraft project <http://cyberciti.biz/fb/>
  7. # This script is licensed under GNU GPL version 2.0 or above
  8. # -------------------------------------------------------------------------
  9. # This script is part of nixCraft shell script collection (NSSC)
  10. # Visit http://bash.cyberciti.biz/ for more information.
  11. # -------------------------------------------------------------------------
  12. # NOTE: Requires ncftp/ncftlls ftp clients/commands
  13. # =========================================================================
  14. # Ftp server settings
  15.  
  16. ### change me ###############################
  17. # ftp login user
  18. FUSER='vivek'
  19.  
  20. # ftp password
  21. FPASSWD='password'
  22.  
  23. # ftp server ip/name
  24. FTPS='array05.wan.nixcraft.co.in'
  25.  
  26. # ftp dirs to nuke Separate multiple dirs using
  27. # a blank/white space i.e. /dir1 /dir2)
  28. FTPDIRS='/dir1 /dir2'
  29. ##############################################
  30. for d in $FTPDIRS
  31. do
  32. subdires="$(ncftpls -u $FUSER -p $FPASSWD ftp://${FTPS}/${d}/)"
  33. for dir in $subdires
  34. do
  35. rdir="${d}/${dir}"
  36. ncftp -u"$FUSER" -p"$FPASSWD" $FTPS<<EOF
  37. cd $rdir
  38. rm *
  39. rmdir $rdir
  40. quit
  41. EOF
  42. done
  43. done
  44. # end of script


4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • spielen

    nice script

  • Diego Siqueira

    thx
    this will help me a lot to study Shell Scritps

Previous Script:

Next Script: