FTP Backup and Restore

in Visual Basic®

by Rick Meyer

Home
Scenario You have decided to use your FTP server to upload your valued files for backup purposes. But it would save time to backup just those files which have been modified or created since the last backup.
Problem The date of the file on the FTP server is the date it was transferred, not the date last modified.
Solution Create and maintain an index file of file names and dates.

Click to download the BacFTP.zip Project (26K)
Operations

A file index is stored in the remote directory to keep track of the file modification dates of the local files as they are transferred. From this data a subsequent FTP upload is performed only for those files that have been modified or newly created.

If a file has been restored then its file date (date of transfer) will be greater than its modification date. To ensure that this restored file will not be uploaded on a subsequent backup, a local index is also maintained with the restore/download date. If there is a local index entry for a local file to be uploaded, then the determination for upload is the comparison of the actual local file date with the local index date rather than with the remote index date.

Also in the local index is the modification date (transferred from the remote index) so there are two dates per item in the local index. For subsequent restore/download if there is an entry for the remote file in the local index, then the comparison is between the remote index date and the local index modification date.

Programming Notes

1. Most FTP servers are case sensitive which means that sample.txt and Sample.txt are two files on the server. In this program all file names are converted to lower case to avoid duplications.

2. Files may be restored/downloaded only if they have been previously backedup/uploaded by this program. The test is the remote files requested are in the remote index file. This means if a file is placed in the remote directory by a means other than an upload from this program it will not be restored/downloaded.

3. This utility may also be used to backup and restore files by copying them to another drive, such as in a network setting or a floppy. To obtain this functionality the FTP transfer API's (bacFTP1.bas) must be replaced with file transfer functions (bacFTP3.bas). This alternate code module was used for development and probably should not be employed in favor of a backup utility that will conserve the file dates (such as with the FileCopy statement).

Main Startup Form
Menu Item Description
Backup/Restore Change between modes of operation. Restore will download previously backed up files.
Settings Enter the information to connect to your FTP server.
Commands Specify the local files you wish to backup with normal file search wildcards and associate those files with a remote directory.
Types Files are transferred either as ASCII or BINARY. Specify your types here.
Automatic/Manual Toggles manner of operation. Manual will pause between commands for your perusal.
FTP Settings Form
Server Address Enter the address of the FTP server that you wish connect to.
An example is: ftp.myserver.com
User Enter your user name on the above specified server.
Password Enter your password for the above specified user.
Index Name The default name for the index file created and maintained in each local and remote directory in which files are transferred. "bacindex" (with no extension) has been suggested by the author of this program.
Command Strings Form

The command strings designate which files you wish to upload (the left textbox) and in which directory on your FTP server you wish to place them (the right textbox).

Enter a complete filespec with path in the left textbox like: "c:\data\myfile.bas" (without the quotes) If you want to upload all the "bas" files in the data directory then your entry would be: "c:\data\*.bas"

To aid in the entry of this filespec you may search for a specific file by clicking Search (then edit the result if wildcards are desired).

Enter the remote (FTP server) directory in the right textbox like: "html_public/backup/data"

Then click AddNew to add your text entries as a new command.

To select a previously entered command string for edit or deletion, merely click on it in the listbox. Then click Delete or Edit (after editing the text).

Clicking Clear just clears the textboxes.

Items are saved when you exit (Clicking OK or X). If you click "Cancel" then nothing you have done will be saved (and you will exit).

Note that processes are reversed for the restore mode moving files from the remote location designated in the right textbox to the local location in the left textbox. With the slight adjustment that files matching your wildcard filespec portion in the left textbox will be searched for in the remote directory and downloaded to the path portion of the local location in the left textbox.

Transfer Types Form

Files may be transferred via FTP either as ASCII (text type) or as BINARY. If the wrong method is choosen your file may be corrupted. Generally FTP utilities will make that determination for you based on file types which is in turn determined by the file extension.

You may enter such extensions in the left textbox and as you press [Enter] they will be added to the listbox below. Enter only the expected ASCII type file extensions he