Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. ##
  2. # Uploads multiple files via FTP using the LFTP command
  3. #
  4. # @usage
  5. # send_files john john123456 20 ftp.foo.com /home/john/remote/dir /tmp/a /tmp/b /tmp/c
  6. # send_files john john123456 20 ftp.foo.com /home/john/remote/dir $file_list
  7. #
  8. # @param $1 Usuário FTP
  9. # @param $2 Senha FTP
  10. # @param $3 Porta FTP
  11. # @param $4 Host FTP
  12. # @param $5 Remote destination directory
  13. # @param $6 Files to upload
  14. function ftp_send_files(){
  15. # we use the 'shift' command to trim up all
  16. # of the parameters until the last one (files)
  17. # so that we could use it as a variadic trailing argument
  18. local user="$1"; shift
  19. local password="$1"; shift
  20. local port="$1"; shift
  21. local host="$1"; shift
  22. local remote_dir="$1"; shift
  23. local files="$@"
  24.  
  25. local ftp_cmd="set ftp:ssl-allow true"
  26. ftp_cmd+=" && set ftp:ssl-force true "
  27. ftp_cmd+=" && set ftp:ssl-protect-data true "
  28. ftp_cmd+=" && set ftp:ssl-protect-list true "
  29. ftp_cmd+=" && set ssl:verify-certificate false "
  30. ftp_cmd+=" && open -u $user,$password -p $port $host "
  31. ftp_cmd+=" && mput -O $remote_dir $files "
  32.  
  33. lftp -c "$ftp_cmd"
  34. }
  35.  
  36. ##
  37. # Mirrors a remote FTP directory to a local directory
  38. # the using LFTP command. In other words, it downloads
  39. # all files from a remote FTP directory to a local directory.
  40. #
  41. # @usage
  42. # send_files john john123456 20 ftp.foo.com /home/john/remote/dir /tmp/john-sync
  43. #
  44. # @param $1 Usuário FTP
  45. # @param $2 Senha FTP
  46. # @param $3 Porta FTP
  47. # @param $4 Host FTP
  48. # @param $5 Remote origin directory
  49. # @param $6 Local destination directory
  50. function ftp_mirror_directory(){
  51. local user="$1"
  52. local password="$2"
  53. local port="$3"
  54. local host="$4"
  55. local remote_dir="$5"
  56. local local_dir="$6"
  57.  
  58. local ftp_cmd="set ftp:ssl-allow true"
  59. ftp_cmd+=" && set ftp:ssl-force true "
  60. ftp_cmd+=" && set ftp:ssl-protect-data true "
  61. ftp_cmd+=" && set ftp:ssl-protect-list true "
  62. ftp_cmd+=" && set ssl:verify-certificate false "
  63. ftp_cmd+=" && open -u $user,$password -p $port $host "
  64. ftp_cmd+=" && mirror -c --parallel=3 $remote_dir $local_dir "
  65.  
  66. lftp -c "$ftp_cmd"
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement