SyncFTPDir in action
SyncFTPDir from a usage perspective works the same way as SyncDir. From a technical point of view, they have nothing in
common and there are variations in execution behavior. FTP is an old protocol and there are numerous implementations
of FTP servers, which means that (unlike the Windows file system) there are differences in behavior of various FTP servers.
Basic things like time stamps and the ability to handle concurrent connections vary from FTP server to FTP server type.
Because of this, SyncFTPDir (unlike SyncDir) needs an initial run to "learn" the FTP structure of the files.
SyncFTPDir command will therefore always copy all files on the first run, but on subsequent runs with the same source and destination,
SyncFTPDir will copy only changed or new files.
In the movie below, we are creating an offline backup solution over FTP. When it is executed on the admin computer, there are 532 files in the
"My Documents" folder and 18 megabytes of data. On the initial run, there are no files in the destination. But if there
were, the initial run would still have taken the same amount of time, as the command needs to "learn" about the destination
files. But when the script is executed again, it drops from 14 seconds to 4 seconds, because none of the files have changed on the second run
at either end.
The CopyFPTDir command will also work as a synchronization, but the difference is that SyncFTPDir will also delete files
that no longer exist in the source.
We could expand the script in the movie a little and compile it into an exe file. We could give this exe
file to offline users to whom we would not want to give full VPN access. Note that this is completely safe, as the
credentials are within the exe file and the password is also encrypted in the script.
The script will check that the user does not have more than 500MB of data to upload.
You can insert this example in the script editor by selecting "FTP Backup" in the "New Script" window.
If Ask Do you want to backup your documents? Then
If [DirSizeMB [UserDocumentsDir]]>500 Then
ShowErrorMessage Backup is not allowed for over 500 megabytes of data.
Else
SyncFTPDir [UserDocumentsDir],ftp://10.10.10.10/Backups/[ComputerName],ftpuser,79dOu1Mu5dcNCMMWnIA64A==
If Not LastFTPWasCancelled Then ShowMessage The backup
is complete.
End If
End If
Factoring in limitations of FTP
SyncFTPDir does not use the fancy performance features of SyncDir, such as
multithreading, because the limitations would primarily be bandwidth and secondarily
the relatively poor performance of the FTP protocol in general, where SyncDir use
would be a matter of sheer I/O performance. When working with FTP, you should always
use your common sense. For example - if we wanted to create the above backup solution,
depending on the bandwidth and FTP server performance, it could actually prove
quicker to simply compress all the user's files into a single zip file and upload
the entire zip file. Such a script could look like the one below.
Note that the zip file includes a password for additional security.
You can insert this example in the script editor by selecting "FTP Zip Backup" in the "New Script" window.
If Ask Do you want to run a backup? Then
SmallSplash Packing files....hang on
Zip [UserDocumentsDir],[TempDir]\Backup.Zip,yHULrIV6BMkM7OsOiMgfdw==
RemoveSmallSplash
If [FileSizeMB [TempDir]\Backup.Zip]>500 Then
ShowErrorMessage Backup is not allowed for over 500 megabytes of data.
Else
CopyFTPFile [TempDir]\Backup.Zip,ftp://10.10.10.10/Backups/[ComputerName].Zip,ftpuser,79dOu1Mu5dcNCMMWnIA64A==
End If
DeleteFile [TempDir]\Backup.Zip
End If
Cancellation
A cancellation button is shown by default on the user interface, when you use the SyncFTPDir, CopyFTPDir or CopyFTPFile commands.
If you do not want a user interface, there are versions of these appended by "Hidden" in the command name. If you want the user inferface,
but not the option to cancel, you can remove the button by using the DisableFTPCancel command.
If you need to detect that a cancellation has happened in your script, you can check this with the LastFTPWasCancelled condition.
SyncFTPFile with cancel button
SyncFTPFile without cancel button