The motivation for writing this script came from buying a virtual hosting plan during Black Friday that had no restrictions at all, but the hosting provider absolutely refused to provide an
SSH Access account, which meant I couldn’t use download tools like wget or axel
to download files. Fortunately, virtual hosting plans usually come with FTP
enabled, so files can be uploaded via FTP,
and since I was too lazy to type commands line by line, I wrote this lazy-person script.
Next, let me introduce this FTP upload one-click script, ftp_upload.sh.
Summary of ftp_upload.sh features:
1. Supports batch uploading files to a specified FTP directory;
2. That’s it.
1. Download the script and grant execute permission
Download the script to the directory containing the files to be uploaded locally, for example: /data/www/default
cd /data/www/default wget --no-check-certificate https://github.com/teddysun/across/raw/master/ftp_upload.sh chmod +x ftp_upload.sh
2. Modify and configure the script
Please use tools such as vim or nano to edit it.
Notes on some variable names:
LOCALDIR (the current directory where the script is located)
LOGFILE (the path to the log file generated when the script runs)
FTP_HOST (the FTP domain name or IP address to connect to)
FTP_USER (the FTP username used for the connection)
FTP_PASS (the password for the FTP user used for the connection)
FTP_DIR (the remote FTP directory to connect to, for example: public_html)
Notes on some important points:
1) The script requires the ftp command, so please install it in advance;
2) Do not change the path of the log file generated when the script runs carelessly;
3) The script must be run in the directory containing the files to be uploaded;
4) When passing arguments containing wildcards to the script, be sure to wrap them in double quotes.
3. Script execution examples
The script will display the list of files to be uploaded and report the required time at the end.
1) Upload the file filename.tgz in the current directory
./ftp_upload.sh filename.tgz
2) Upload multiple files in the current directory:
filename1.tgz, filename2.tgz, filename3.tgz
./ftp_upload.sh filename1.tgz filename2.tgz filename3.tgz
3) Upload wildcard-matched files in the current directory:
*.tgz (note: the following argument must be enclosed in double quotes)
./ftp_upload.sh "*.tgz"
4) Upload multiple wildcard-matched files in the current directory:
*.tgz, *.gz (note: the following arguments must be enclosed in double quotes)
./ftp_upload.sh "*.tgz" "*.gz"
Finally, feedback and suggestions are welcome.
