FTP scheduling File transfers under DOS / Windows

In order to make a secure backup on a distant server or hosting cloud, The FTP command support the “-s:ftpscript.txt” option. The FTP commands listed in ftpscript.txt will automatically run after FTP starts. The FTP command can be started from a batch file.

Example:

FTP -v -i -s:ftpscript.txt

 

Create ftp script file (ftpscript.txt)

open <your server>
<username>
<password>
lcd  <your folder to upload>
cd <your server folder to hold backup>
binary
mput "*.*"
disconnect
bye

It can be useful to remember those transfer ftp instruction :

FTP Download instructions server -> local

get
get home.html
mget  (multi files instruction)
mget *.html

FTP Upload instructions Transfer from local to server (upload)

put
mput (Multi-files instruction)

Now, you can add as the following line to your regular dumping mysql database batch :

@echo off
echo Running dump...
c:binmysqldump -u[user] -p[password] --result-file="c:backup.%DATE:~0,3%.sql" [database]
ftp -v -i -s:ftpscript.txt
echo Done!

Another way to do a complete batch script can be this way on windows server 2003 :

@echo off

# variable to hold the datestamp of the backup
SET today=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%

# temporary FTP script to upload backup files
set SCRIPT_NAME=ftp_script.ftp

# MySQL database dump
"C:\wamp\bin\mysql\mysql5.5.24\bin\mysqldump" planning -u root > "C:\wamp\sql_backup\%today%_planning.sql"

# connect to FTP server, provide credentials and perform upload
ftp>> %SCRIPT_NAME%
open YOUR_IP>> %SCRIPT_NAME%
YOUR_user>> %SCRIPT_NAME%
YOUR_password>> %SCRIPT_NAME%
cd  YOUR_DIRECTORY>> %SCRIPT_NAME%
binary>> %SCRIPT_NAME%
put %today%_planning.sql>> %SCRIPT_NAME%
disconnect>> %SCRIPT_NAME%
bye>> %SCRIPT_NAME%
ftp -s:%SCRIPT_NAME%

# always clean behind
@del %SCRIPT_NAME% /q
#@del %today%_planning.sql (You can delete local backups after upload)

Cheers,

extradrmtech

Since 30 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions and medias protecting solutions. I am experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. Besides my work, I like to work freelance only on some wordpress projects because it is relaxing and delightful CMS for me. When not working, I like to dance salsa and swing and to have fun with my little family.

You may also like...

Leave a Reply