Scp C++ Reference Documentation
CkScp
Current Version: 11.1.0
An API for SCP over SSH. (SCP is the Secure Copy Protocol.) It is for transferring files or directory trees to or from remote servers. SCP is a simpler protocol than SFTP, and thus the functionality is more limited. However, SCP does not require that an SSH server support the SFTP subsystem. In cases where a server does not allow for SFTP, then SCP is a good choice for file transfer.
Object Creation
// Local variable on the stack CkScp obj; // Dynamically allocate/delete CkScp *pObj = new CkScp(); // ... delete pObj;
Properties
AbortCurrent
void put_AbortCurrent(bool newVal);
When set to true
, causes the currently running method to abort. Methods that always finish quickly (i.e.have no length file operations or network communications) are not affected. If no method is running, then this property is automatically reset to false
when the next method is called. When the abort occurs, this property is reset to false
. Both synchronous and asynchronous method calls can be aborted. (A synchronous method call could be aborted by setting this property from a separate thread.)
DebugLogFilePath
const char *debugLogFilePath(void);
void put_DebugLogFilePath(const char *ansiOrUtf8Str);
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
HeartbeatMs
void put_HeartbeatMs(int newVal);
The interval in milliseconds between each AbortCheck
event callback, which enables an application to abort certain method calls before they complete. By default, HeartbeatMs is set to 0
, meaning no AbortCheck event callbacks will trigger.
LastErrorHtml
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
void put_LastMethodSuccess(bool newVal);
Indicates the success or failure of the most recent method call: true
means success, false
means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages.
PercentDoneScale
void put_PercentDoneScale(int newVal);
This property is only valid in programming environment and languages that allow for event callbacks.
Sets the value to be defined as 100% complete for the purpose of PercentDone event callbacks. The defaut value of 100 means that at most 100 event PercentDone callbacks will occur in a method that (1) is event enabled and (2) is such that it is possible to measure progress as a percentage completed. This property may be set to larger numbers to get more fine-grained PercentDone callbacks. For example, setting this property equal to 1000 will provide callbacks with .1 percent granularity. For example, a value of 453 would indicate 45.3% competed. This property is clamped to a minimum value of 10, and a maximum value of 100000.
topSendEnv
const char *sendEnv(void);
void put_SendEnv(const char *ansiOrUtf8Str);
A JSON string specifying environment variables that are to be set for each SCP upload or download. For example:
{ "LCS_PASSWORD": "myPassword", "SOME_ENV_VAR": "some_value", ... }
SyncedFiles
const char *syncedFiles(void);
void put_SyncedFiles(const char *ansiOrUtf8Str);
The paths of the files uploaded or downloaded in the last call to SyncUploadTree or SyncDownloadTree. The paths are listed one per line. In both cases (for upload and download) each line contains the full local file path (not the remote path).
SyncMustMatch
const char *syncMustMatch(void);
void put_SyncMustMatch(const char *ansiOrUtf8Str);
Can contain a wildcarded list of filename patterns separated by semicolons. For example, *.xml; *.txt; *.csv
. If set, the SyncTreeUpload and SyncTreeDownload methods will only transfer files having a filename that matches any one of these patterns.
SyncMustMatchDir
const char *syncMustMatchDir(void);
void put_SyncMustMatchDir(const char *ansiOrUtf8Str);
Can contain a wildcarded list of directory name patterns separated by semicolons. For example, a*; b*; c*
. If set, the SyncTreeUpload and SyncTreeDownload methods will only traverse into a directory that matches any one of these patterns.
SyncMustNotMatch
const char *syncMustNotMatch(void);
void put_SyncMustNotMatch(const char *ansiOrUtf8Str);
Can contain a wildcarded list of filename patterns separated by semicolons. For example, *.xml; *.txt; *.csv
. If set, the SyncTreeUpload and SyncTreeDownload methods will not transfer files having a filename that matches any one of these patterns.
SyncMustNotMatchDir
const char *syncMustNotMatchDir(void);
void put_SyncMustNotMatchDir(const char *ansiOrUtf8Str);
Can contain a wildcarded list of directory name patterns separated by semicolons. For example, a*; b*; c*
. If set, the SyncTreeUpload and SyncTreeDownload methods will not traverse into a directory that matches any one of these patterns.
UncommonOptions
const char *uncommonOptions(void);
void put_UncommonOptions(const char *ansiOrUtf8Str);
This is a catch-all property to be used for uncommon needs. The default value is the empty string.
Can be set to a list of the following comma separated keywords:
-
FilenameOnly - Introduced in v9.5.0.77. Set this property to the keyword
FilenameOnly
if only the filename should be used in thescp -t
command. (LANCOM routers using SCP seem to need it.) - ProtectFromVpn - Introduced in v9.5.0.80. On Android systems, will bypass any VPN that may be installed or active.
UnixPermOverride
const char *unixPermOverride(void);
void put_UnixPermOverride(const char *ansiOrUtf8Str);
When Chilkat uploads a file by SCP, the UNIX permissions of the remote file are set based on the permissions of the local file being uploaded. Usually this is OK, but in some cases the access permissions of the local file are not what is wanted for the remote file. This property can be set to an octal permissions string, such as 0644
, to force the remote file permissions to this value.
The default value of this property is the empty string (remote files permissions mirror the permissions of the local file being uploaded).
topUtf8
void put_Utf8(bool newVal);
When set to true
, all const char *
arguments and return values are interpreted as UTF-8 strings. When set to false
, they are interpreted as ANSI strings.
In Chilkat v11.0.0 and later, the default value is true
. Before v11.0.0, it was false
.
VerboseLogging
void put_VerboseLogging(bool newVal);
If set to true
, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false
. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
Methods
DownloadBd
Downloads a binary file from the SSH server and appends to the contents of bd.
Returns true for success, false for failure.
topDownloadBdAsync (1)
Creates an asynchronous task to call the DownloadBd method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
DownloadBinaryEncoded
const char *downloadBinaryEncoded(const char *remotePath, const char *encoding);
Downloads a file from the SSH server returns the contents in an encoded string (using an encoding such as base64).
Returns true for success, false for failure.
DownloadBinaryEncodedAsync (1)
Creates an asynchronous task to call the DownloadBinaryEncoded method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
DownloadFile
Downloads a file from the remote SSH server to the local filesystem.
Returns true for success, false for failure.
DownloadFileAsync (1)
Creates an asynchronous task to call the DownloadFile method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
DownloadString
const char *downloadString(const char *remotePath, const char *charset);
Downloads a text file from the SSH server and returns the contents as a string.
Returns true for success, false for failure.
DownloadStringAsync (1)
Creates an asynchronous task to call the DownloadString method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
LoadTaskCaller
SyncTreeDownload
Downloads files from the SSH server to a local directory tree. Synchronization modes include:
mode=0: Download all files
mode=1: Download all files that do not exist on the local filesystem.
mode=2: Download newer or non-existant files.
mode=3: Download only newer files. If a file does not already exist on the local filesystem, it is not downloaded from the server.
mode=5: Download only missing files or files with size differences.
mode=6: Same as mode 5, but also download newer files.
Returns true for success, false for failure.
SyncTreeDownloadAsync (1)
Creates an asynchronous task to call the SyncTreeDownload method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
SyncTreeUpload
Uploads a directory tree from the local filesystem to the SSH server. Synchronization modes include:
mode=0: Upload all files
mode=1: Upload all files that do not exist on the FTP server.
mode=2: Upload newer or non-existant files.
mode=3: Upload only newer files. If a file does not already exist on the FTP server, it is not uploaded.
mode=4: transfer missing files or files with size differences.
mode=5: same as mode 4, but also newer files.
Returns true for success, false for failure.
topSyncTreeUploadAsync (1)
Creates an asynchronous task to call the SyncTreeUpload method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
UploadBd
Uploads the contents of bd to a file on the SSH server.
Returns true for success, false for failure.
topUploadBdAsync (1)
Creates an asynchronous task to call the UploadBd method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
UploadBinaryEncoded
Uploads the binary data to a file on the remote SSH server. The binary data is passed in encoded string representation (such as base64, or hex).
Returns true for success, false for failure.
UploadBinaryEncodedAsync (1)
Creates an asynchronous task to call the UploadBinaryEncoded method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
UploadFile
Uploads a file from the local filesystem to the remote SSH server.
Returns true for success, false for failure.
UploadFileAsync (1)
Creates an asynchronous task to call the UploadFile method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
UploadString
Uploads the contents of a string to a file on the remote SSH server.
Returns true for success, false for failure.
UploadStringAsync (1)
Creates an asynchronous task to call the UploadString method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
UseSsh
Uses the SSH connection of sshConnection for the SCP transfers. All of the connection and socket related properties, proxy properites, timeout properties, session log, etc. set on the SSH object apply to the SCP methods (because internally it is the SSH object that is used to do the work of the file transfers).
Returns true for success, false for failure.
topEvents
To implement an event callback, your application would define and implement a class that inherits from CkBaseProgress. Your application can implement methods to override some or all of the default/empty method implementations of the CkBaseProgress base class.
For example:
CkScp scp; MyScpProgress callbackObj; scp.put_EventCallbackObject(&callbackObj);
MyScpProgress example:
#include "CkBaseProgress.h" class MyScpProgress : public CkBaseProgress { public: MyScpProgress(); virtual ~MyScpProgress(); void AbortCheck(bool *abort); void PercentDone(int pctDone, bool *abort); void ProgressInfo(const char *name, const char *value); void TaskCompleted(CkTask &task); };
AbortCheck
Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs
property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.
PercentDone
This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).
The PercentDone callback also acts as an AbortCheck
event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.
To abort the operation, set the abort output argument to true
. This will cause the method to terminate and return a failure status or corresponding failure value.
ProgressInfo
This event callback provides tag name
/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.
TaskCompleted
Called from the background thread when an asynchronous task completes.
Deprecated
DownloadBinary Deprecated
Downloads a binary file from the SSH server and returns the contents.
Returns true for success, false for failure.
topDownloadBinaryAsync Deprecated (1)
Creates an asynchronous task to call the DownloadBinary method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure
UploadBinary Deprecated
UploadBinaryAsync Deprecated (1)
Creates an asynchronous task to call the UploadBinary method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL
on failure