-
Notifications
You must be signed in to change notification settings - Fork 31
Syncing Files
One of the commands available in the SDK is the Sync-SfItem command. This command implements all of the features of our older SFCLI tool.
Options:
-ShareFilePath – ShareFile Path to sync to or from
-LocalPath – local path to sync to or from
-Upload – upload to ShareFile
-Download – download to local
-Synchronize – syncs the folders
-Recursive – allows you to sync entire folder structures
-Move – deletes local files or cloud files after sync
-KeepFolders – when combined with move keeps the folder structure and deletes the files
-Strict – deletes files and directories before sync so that only exact copies exist
-OverWrite – when syncing this parameter will force the existing files to be overwritten
-CreateRoot – this parameter will create the source folder as a new subfolder of the destination folder
###Creating a PSDrive In order to use the Sync-SfItem, you must first authenticate into the ShareFile account you wish to use, and create a PowerShell Drive to sync to. The command will use this drive in order to upload or download the files. You can establish this connection using the command
$sfc = New-SfClient
The most important new command that must be performed is the New-PSDrive command. This creates a temporary drive that links PowerShell to your ShareFile account and allows syncing or copying of files. In order to create a PSDrive to your account, you can use the command below.
New-PSDrive -Name sfdrive -PSProvider ShareFile -Root "/" -Client $sfc
###Using PowerShell Sync-SfItem Once you have the PSDrive, you may use the Sync-SfItem command however you wish. In order to simplify this process, I will show you what the old SFCLI commands look like with the new PowerShell command.
SFCLI:
sfcli -l "c:\Clients\*.pdf" -up -sf "/Clients/Acrobat Files" -u bob@widgetco.com -pw BoBsP4Ss -s widgetco –o
PowerShell:
Sync-SfItem –LocalPath "c:\Clients\*.pdf" -Upload -ShareFilePath "/Clients/Acrobat Files" –OverWrite
This will upload every pdf file in the c:\Clients directory to /Clients/Acrobat Files on ShareFile, overwriting any duplicates. Any subfolders of c:\Clients and their contents will NOT be uploaded, because -deep is not set.
SFCLI:
sfcli -l "c:\Clients\Jimbo" -up -sf "/Clients/" -u bob@widgetco.com -pw BoBsP4Ss -s widgetco -deep –cr
PowerShell:
Sync-SfItem -LocalPath "c:\Clients\Jimbo" -Upload -ShareFilePath "/Clients/" -Recursive -CreateRoot
This will upload the entire c:\Clients\Jimbo directory to ShareFile, including any subfolders and their contents. Since -cr is specified, Jimbo would be created as a subfolder of /Clients/ if it did not already exist. If /Clients/Jimbo/ already exists in ShareFile, any duplicate files it has will NOT get overwritten because -o is not specified.
SFCLI:
sfcli -sf "/Clients/" -sync -down -l "c:\Clients" -u bob@widgetco.com -pw {MNq9SdDMiOZR4iXm} -s widgetco –deep
PowerShell:
Sync-SfItem -ShareFilePath "/Clients/" -Synchronize -Download -LocalPath "c:\Clients" -Recursive
This would download every file present in /Clients/ (including any in subfolders as -deep is set) that does not exist in or differs from one existing in c:\Clients. Any extra files in c:\Clients that are not present in /Clients/ will NOT get deleted because -strict is not set. This is also example of how to use an encrypted password.
SFCLI:
sfcli -sf "/Clients/Jimbo" -down -l "c:\Clients\Jimbo" -u bob@widgetco.com -pw BoBsP4Ss -s widgetco -deep –move
PowerShell:
Sync-SfItem -ShareFilePath "/Clients/Jimbo" -Download -LocalPath "c:\Clients\Jimbo" -Recursive -Move
This would download every file present in /Clients/Jimbo/ to the local folder c:\Clients\Jimbo, including any subfolders as -deep is set. Duplicate files that exist in c:\Clients\Jimbo will NOT get overwritten as -o is not set. After a successful download, the entire /Clients/Jimbo/ folder will get deleted from ShareFile, as -move is specified and they have been “moved”.
SFCLI:
sfcli -sf "/" -sync -down -l "c:\ShareFile Backup" -u bob@widgetco.com -pw BoBsP4Ss -s widgetco -deep –strict
PowerShell:
Sync-SfItem -ShareFilePath "/" -Synchronize -Download -LocalPath "c:\ShareFile Backup" -Recursive -Strict
This would download your entire ShareFile account (or at least, all of the files you have access to) to the directory c:\ShareFile Backup. Subsequent invocations of this command would download only files that have been updated in ShareFile since the last sync. Including the -strict flag will cause your backup to exactly match your ShareFile account, i.e., files that are deleted from ShareFile would get deleted from the local backup upon sync. Omitting the -strict flag would cause SFCLI only to download new and changed files, but never to delete files from C:\ShareFile Backup.