From 41e742a6167d053efed844d095c3dc90bc12d344 Mon Sep 17 00:00:00 2001 From: mhellmeier Date: Mon, 7 Sep 2020 17:58:56 +0200 Subject: [PATCH] Create beta release - add SSH option (fixes #1) - add folder or content transfer option (fixes #3) - small improvements --- README.md | 9 +-- install.sh | 1 + moveServerFiles.sh | 169 ++++++++++++++++++++++++++------------------- 3 files changed, 103 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 194db67..2b33d28 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ A simple bash script to move files over FTP / SSH from a source to a (different) ## About The Project -**Current version**: 0.0.1 (Alpha Phase) +**Current version**: 0.1 (Beta Phase) There are many cases where people want to transfer files and folders from a source server `A` to a destination server `B` (for example websites or backups). In most of the cases, the only possible solution to migrate a website to a new host is to download all files manually with a FTP client (like FileZilla) on your local computer and upload it to the new server afterwards. Direct transfers over FXP aren't possible in most of the cases due to restrictions in many (shared) webhosting packages. This small bash script will do the job for you! @@ -32,10 +32,11 @@ If there is access to a VPS or Root Server `C`, I suggest executing the script o ### Pre-Requirements -To use the script, these are the only things you need: +To use the script, these are the only things you need (will be installed with the install script): - Linux machine (or Mac or Winodws 10 with Linux Subsystem installed) - `ftp` installed (`sudo apt install ftp`) - `lftp` installed (`sudo apt install lftp`) +- `sshpass` installed (`sudo apt install sshpass`) ### Installation @@ -58,7 +59,7 @@ sh install.sh ### Important Information - The script asks for passwords to connect to the source and destination hosts. Keep in mind that these will be used in the commands (plaintext!) to connect and download / upload content. It can be a security concern if the commands will be stored in the log history -- To get rid of some certificate verifiaction errors, the scripts doesn't make certificate checks +- To get rid of some certificate verification errors, the scripts doesn't make certificate checks - Remember to open FTP / SSH relevant ports in your firewall - Use it at your own risk! @@ -70,7 +71,7 @@ Alle planned features, bugs and discussions can be found in the [open issues](ht ## Contributing -Feel free to fork the project, work in your personal branch and create a pull request your simple interact in the [issue section](https://github.com/mhellmeier/FTP-Move-Server-Files/issues). +Feel free to fork the project, work in your personal branch and create a pull request or you simple interact in the [issue section](https://github.com/mhellmeier/FTP-Move-Server-Files/issues). **This is an open source project! Every contribution is greatly appreciated!** diff --git a/install.sh b/install.sh index 2d6d5fc..a406c39 100644 --- a/install.sh +++ b/install.sh @@ -2,5 +2,6 @@ sudo apt install ftp -y sudo apt install lftp -y +sudo apt install sshpass -y chmod +x moveServerFiles.sh \ No newline at end of file diff --git a/moveServerFiles.sh b/moveServerFiles.sh index d567a61..1560297 100644 --- a/moveServerFiles.sh +++ b/moveServerFiles.sh @@ -4,114 +4,139 @@ # ***** SOURCE ***** # ****************** -read -p "Do you want to use SSH (1) or FTP (2) for the connection to the source host? [1/2]: " sourceConnectionMode +# Collect information and source credentials +read -p "Do you want to use SSH / SFTP (1) or FTP (2) for the connection to the source host? [1/2]: " sourceConnectionMode -# FTP connection -if [[ $sourceConnectionMode == "2" ]]; then - read -p "[Source] Host name / URL / IP: " sourceFtpHostName +read -p "[Source] Host name / URL / IP: " sourceHostName + +read -p "[Source] Username: " sourceUsername + +stty -echo +printf "[Source] Password: " +read sourcePassword +stty echo + +echo +read -p "[Source] Path to download recursively ('/' for current directory): " sourceDownloadPath - read -p "[Source] Username: " sourceFtpUsername +read -p "Do you want to transfer the folder itself (1) or only the content of $sourceDownloadPath (2)? [1/2]: " sourceDownloadMode +echo - stty -echo - printf "[Source] Password: " - read sourceFtpPassword - stty echo - printf "\n" +if [[ $sourceDownloadPath != /* ]]; then + sourceDownloadPath="/"$sourceDownloadPath +fi +if [[ $sourceDownloadPath != */ ]]; then + sourceDownloadPath=$sourceDownloadPath"/" +fi + +# Recreate download directory +rm -rf tmpDownload +mkdir tmpDownload +cd tmpDownload - echo "Trying to connect to source host and display files ..." +echo "Trying to connect to source host ..." + +# FTP connection +if [[ $sourceConnectionMode == "2" ]]; then -ftp -n $sourceFtpHostName <