Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.58 KB | None | 0 0
  1. #!/bin/bash
  2. #The following script will look at the folder you specify
  3. #Determine what files are in that folder
  4. #How much space that they will take up
  5. #And copy them to a remote location of your choosing
  6. #TITLE="SFTP File Transfer"
  7. #Print the string variable on the screen
  8. echo $TITLE
  9. echoPS3='Choose how you would like to transfer files:'
  10. options=("SFTP Push" "SFTP Get" "Quit")
  11. quit=false
  12. until $quit; do       
  13. select opt in "${options[@]}"; do               
  14. case $opt in                       
  15. "SFTP Push")                               
  16. clear;                               
  17. #SFTP Push                               
  18. echo "Use this option to move files from a local folder"                               
  19. echo "to a remote folder"                               
  20. echo                               
  21. #                               
  22. echo -e "What is the server IP?"                               
  23. read ipaddress                               
  24. #                               
  25. echo -e "What is the username?"                               
  26. read user                               
  27. #                               
  28. echo -e "What is the password?"                               
  29. read pass                               
  30. #                               
  31. echo -e "What is the local folder location?"                               
  32. read local                               
  33. #                               
  34. echo -e "What is the remote folder location?"                               
  35. read remote                               
  36. #                               
  37. #Place files in the remote folder                               
  38. #Since we are using sftp, I set a variable of port                               
  39. #to hard code port 22.                               
  40. #                               
  41. #The find command will locate                               
  42. #all files in the folder stated in variable $local                               
  43. #and place them into a file called filelist.                               
  44. #                               
  45. #Now for the meat of this script. We need to make sure                               
  46. #that "expect" is installed as it will help us to send                               
  47. #what sftp is needing from us automate the process.                               
  48. #                               
  49. #sftp will launch and with the variables collected above                               
  50. #to get the files copied from local to remote locations.                               
  51. #                               
  52. PORT=22                               
  53. find $local -type f > filelist
  54. /usr/bin/expect <<EOD                               
  55. spawn /usr/bin/sftp -o Port=$PORT $user@$ipaddress                               
  56. expect "password:"                               
  57. send "$pass\r"                               
  58. expect "sftp>"                               
  59. send "put -r $local/* $remote\r"                               
  60. expect "sftp>"                               
  61. send "bye\r"
  62. EOD                               
  63. break                               
  64. ;;                       
  65. "SFTP Get")                               
  66. clear;                               
  67. #SFTP Get                               
  68. echo "Use this option to move files from a Remote folder"                               
  69. echo "to a local folder"                               
  70. echo                               
  71. #                               
  72. echo -e "What is the server IP?"                               
  73. read ipaddress                               
  74. #                               
  75. echo -e "What is the username?"                               
  76. read user                               
  77. #                               
  78. echo -e "What is the password?"                               
  79. read pass                               
  80. #                               
  81. echo -e "What is the local folder location?"                               
  82. read local                               
  83. #                               
  84. echo -e "What is the remote folder location?"                               
  85. read remote                               
  86. #                               
  87. #Place files in the local folder                               
  88. #Since we are using sftp, I set a variable of port                               
  89. #to hard code port 22.                               
  90. #                               
  91. #The find command will locate                               
  92. #all files in the folder stated in variable $remote                               
  93. #and place them into a file called filelist.                               
  94. #                               
  95. #Now for the meat of this script. We need to make sure                               
  96. #that "expect" is installed as it will help us to send                               
  97. #what sftp is needing from us automate the process.                               
  98. #                               
  99. #sftp will launch and with the variables collected above                               
  100. #to get the files copied from local to remote locations.                               
  101. #                               
  102. PORT=22                               
  103. find $remote -type f > filelist
  104. /usr/bin/expect <<EOD                               
  105. spawn /usr/bin/sftp -o Port=$PORT $user@$ipaddress                               
  106. expect "password:"                               
  107. send "$pass\r"                               
  108. expect "sftp>"                               
  109. send "put -r $remote/* $local\r"                               
  110. expect "sftp>"                               
  111. send "bye\r"
  112. EOD                               
  113. break                               
  114. ;;                       
  115. "Quit")                               
  116. quit=true                               
  117. break                               
  118. ;;                       
  119. *) echo invalid option
  120. ;;               
  121. esac       
  122. done
  123. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement