Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. curl --ftp-ssl -k ftp://user:pass@IP
  2.  
  3. $ curl -s ftp://user:pass@IP/path/to/folder/ |
  4. grep -e '^-' | awk '{ print $9 }' |
  5. while read f; do
  6. curl -O ftp://user:pass@IP/path/to/folder/$f;
  7. done
  8.  
  9. #!/bin/bash
  10. #
  11. # Use cURL to download the files in a given FTPS directory (FTP over SSL)
  12. # eg:
  13. # curl_get_ftp_dir -u myUserName -p myPassword -d ftps://ftpserver.com/dir1/dir2
  14. # Optionally, use:
  15. # -k - to ignore bad SSL certificates
  16. # --config userPassFile - to use the contents of a file including myUserName:myPassword in place of command line arguments
  17. # --silent - to silently download (otherwise cURL will display stats per file)
  18.  
  19. while [[ $# -gt 1 ]]
  20. do
  21. key="$1"
  22.  
  23. case $key in
  24. -u|--username)
  25. user="$2"
  26. shift
  27. ;;
  28. -p|--password)
  29. pass="$2"
  30. shift
  31. ;;
  32. -d|--dir|--directory)
  33. ftpDir="$2"
  34. shift
  35. ;;
  36. -k|--ignoreSSL|--ignoreBadSSLCertificate)
  37. ignoreBadSSLCertificate="-k"
  38. ;;
  39. -s|--silent)
  40. silent="-s"
  41. ;;
  42. -K|--config|--configFile)
  43. config="$2"
  44. shift
  45. ;;
  46. *)
  47. echo "Unknown Option!"
  48. ;;
  49. esac
  50. shift
  51. done
  52.  
  53. if [ -z "${config+x}" ]; then
  54. CURL_OPTS="$silent --ftp-ssl $ignoreBadSSLCertificate -u $user:$pass"
  55. else
  56. #CURL_OPTS="$silent --ftp-ssl $ignoreBadSSLCertificate --config $config"
  57. #Originally intended to be a curl config file - for simplicity, now just a file with username:password in it
  58. #Be sure to chmod this file to either 700, 400, or 500
  59. CURL_OPTS="$silent --ftp-ssl $ignoreBadSSLCertificate -u $(cat $config)"
  60. fi
  61.  
  62. curl $CURL_OPTS $ftpDir |
  63. grep -e '^-' | awk '{ print $9 }' |
  64. while read f; do
  65. curl -O $CURL_OPTS $ftpDir/$f;
  66. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement