b = syncfile(direction,from_path『,to_path』);
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
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 parameter may contain the wildcard characters "*" and "?" to specify a group of files to transfer. In this case, the to_path parameter 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.
The function returns a logical value of 1 (true) if the transfer was successful and 0 (false) otherwise.
if syncconnect(CSWeb,"https://www.myserver.org/api") then
// get the latest versions of the application files from the server
// upload all images in images directory to the images directory on the server