Synchronizing Files and Folders
To facilitate file-syncing workflows, the sync operation can be used.
This sync uses rules very similar to Files.com's Remote Server Sync feature, using only filename and size to determine whether a file needs to be synced. It does not currently use information such as modified date or checksum for this purpose. Due to the wide variety of remote server types supported (and our plans to support hundreds more via an open integration platform coming soon), this is the only methodology we've been able to design that works 100% consistently across all files on Files.com, including files that may potentially be stored on a remote server.
Here is a push (upload) example for syncing files from a local Documents
folder to a Files.com folder of the same name:
Here is a pull (download) example for syncing files to a local Documents
folder from a Files.com folder of the same name:
The sync operation also provides some useful options.
Delete Source File After Successful Sync
To configure the sync so that the source file will be deleted after it has been successfully transferred to its destination, use the --delete-source-files
flag.
If deleting the source files would result in an empty folder that you want to dispose of, you can also use the --delete-source-empty-folders
flag. For example, a sync that might use these flags is one that pulls data from a folder that is created every day by an external process. Since the folder is created each day, using --delete-source-empty-folders
cleans up the source filesystem, which prevents performance issues.
Move Source File After Successful Sync
You can configure the sync so that the source file will be moved after it has been successfully transferred to its destination, using the --move-source
flag. The move will occur in the source location.
For a sync push, the source location for the move will be the local system where you are running the files-cli:
For a sync pull, the source location for the move will be the Files.com platform:
Ignore Certain Files or Folders
You can configure the sync to ignore certain files or folders using the --ignore
flag. Place the file and folder name patterns to be ignored into a comma separated string:
Include Only Specified Files or Folders
You can configure the sync to include only specified files or folders patterns using the --include
flag. Place the file and folder name patterns to be included into a comma separated string:
Preserve File Times
Files that are uploaded or downloaded, including those that were transferred using a sync
operation, typically gain an updated timestamp when they arrive at their destination, reflecting the date and time of when the file arrived on the destination system.
You can preserve the original timestamp by using the --times
flag. When using the --times
flag, the files will arrive at their destination with the same timestamp as they possessed at their source location. This is useful when archiving, or backing up, data so that you can determine if a file at the source location has been modified or updated when compared to the copy at the destination location.
Preservation of file times will only occur if your site is configured to allow file modification times to be set. If file times are not preserved, check your site's data governance settings.
Dry Run
Before attempting a sync operation, you might want to observe the actions that will be taken without any actual data being transferred. The --dry-run
flag can be used to show you which files would have been affected by the operation.