Download file from remote ftp

Scenario: Create a script to download the zipped database files from remote ftp server and import those database files to remote database server. Also do not forget to inflate the zipped files and remove them after import.

Solution:


############ Download the zipped database files ###############

/usr/bin/ncftpget -R -v -u "ftpuser" -p "password" ftp.someserver.com /home/localuser  /home/ftpuser/database.sql.zip
/usr/bin/ncftpget -R -v -u "ftpuser" -p "password" ftp.someserver.com /home/localuser  /home/ftpuser/database1.sql.zip

############ Inflate the all zip files #################3

/usr/bin/unzip /home/localuser/database.sql.zip -d /home/localuser/
/usr/bin/unzip /home/localuser/database1.sql.zip -d /home/localuser/

##### Import the sql files in database named 'database' and 'database1' on mysql server named 'mysql-server' #####

cd /var/www/html
/usr/bin/mysql -h mysql-server -u root -pPassword database < /home/localuser/database.sql
/usr/bin/mysql -h mysql-server -u root -pPassword database1 < /home/localuser/database1.sql

############# Finally Delete All zipped files from download folder ################

/bin/rm -rf /home/localuser/\*.zip

You can leave a response, or trackback from your own site.

Leave a Reply