• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization Functions
        • SyncConnect Function
        • SyncConnect Function (CSWeb)
        • SyncConnect Function (Bluetooth)
        • SyncConnect Function (Dropbox)
        • SyncConnect Function (LocalDropbox)
        • SyncConnect Function (LocalFiles)
        • SyncConnect Function (FTP)
        • SyncServer Function
        • SyncDisconnect Function
        • SyncData Function
        • SyncFile Function
        • SyncMessage Function
        • SyncParadata Function
        • SyncApp Function
        • SyncTime Function
        • GetBluetoothName Function
        • SetBluetoothName Function
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

SyncFile Function

Format
b = syncfile(direction, from_pathʃ, to_pathʅ);
Description
The syncfile function transfers files between a device and a synchronization server. Files may be of any type: application files, images, text files, etc. However, for transferring CSPro data files it is more efficient to use the function syncdata. Before calling syncfile, you must first connect to a server by calling syncconnect.
The syncfile function uploads or downloads one or more files from the server. Unlike syncdata, this sends or retrieves an entire file, not individual cases. It is therefore useful for transferring files that are not data files such as images or new versions of an application.
The function can upload files from the local device (client) to the server as well as download files from the server. The direction argument determines which of these operations is performed. It must be one of the following values:
  • GET: Download files from the server and save them on the client.
  • PUT: Upload files from the client to the server.
The from_path argument is a string expression that specifies the path of the file to transfer. If the direction is GET then this is the path of the file on the server to download. If the direction is PUT then this is the full path to the file name on the client to upload.
The optional to_path argument is a string expression that specifies the destination path for the file. If the direction is GET then this is the full path of the destination file name on the client device. If the direction is PUT then this is the path of the destination file or folder on the server. If to_path is not specified, then the file will have the same name as the file in the from_path and will be saved to the application directory on the client (for GET) or the server root directory (for PUT).
The from_path argument may contain the wildcard characters "*" and "?" to specify a group of files to transfer. In this case, the to_path argument should be the name of a folder to copy all files that match the wildcard pattern into.
When downloading files using GET, syncfile first looks to see if the file already exists on the client device. If it does, it only downloads the file if the server has a different version. It uses the file signature (MD5) to determine if the version of the file on the server is different. This reduces the bandwidth used when downloading large files.
Return Value
The function returns a logical value of 1 (true) if the transfer was successful and 0 (false) otherwise.
Example
if syncconnect(CSWeb, "https://www.myserver.org/api") then

   
// upload all images in images directory to the images directory on the server
    syncfile(PUT, "Images/*.jpg", "/Images/");

   
syncdisconnect();

endif;
See also: Synchronization Overview, SyncConnect Function, SyncData Function, SyncParadata Function, SyncApp Function, SyncDisconnect Function, SyncServer Function