Ftp2 C Library Reference

Ftp2

Commercial File Transfer Protocol (FTP) C Library.

Create/Dispose

HCkFtp2 CkFtp2_Create(void);

Creates an instance of the CkFtp2 object and returns a handle (i.e. a "void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkFtp2_Dispose(HCkFtp2 handle);

Objects created by calling CkFtp2_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

C "Properties"

void CkFtp2_getAccount(HCkFtp2 handle, HCkString retval);
void CkFtp2_putAccount(HCkFtp2 handle, const char *newVal);

Some FTP servers require an Account name in addition to login/password. This property can be set for those servers with this requirement.

long CkFtp2_getActivePortRangeEnd(HCkFtp2 handle);
void CkFtp2_putActivePortRangeEnd(HCkFtp2 handle, long newVal);

When Active (i.e. PORT) mode is used (opposite of Passive), the client-side is responsible for choosing a random port for each data connection. (Note: In the FTP protocol, each data transfer occurs on a separate TCP/IP connection. Commands are sent over the control channel (port 21 for non-SSL, port 990 for SSL).)

This property, along with ActivePortRangeStart, allows the client to specify a range of ports for data connections.

more information about FTP port ranges

long CkFtp2_getActivePortRangeStart(HCkFtp2 handle);
void CkFtp2_putActivePortRangeStart(HCkFtp2 handle, long newVal);

This property, along with ActivePortRangeEnd, allows the client to specify a range of ports for data connections when in Active mode.

more information about FTP port ranges

unsigned long CkFtp2_getAllocateSize(HCkFtp2 handle);
void CkFtp2_putAllocateSize(HCkFtp2 handle, unsigned long newVal);

If set to a non-zero value, causes an ALLO command, with this size as the parameter, to be automatically sent when uploading files to an FTP server.

This command could be required by some servers to reserve sufficient storage space to accommodate the new file to be transferred.

unsigned long CkFtp2_getAsyncBytesReceived(HCkFtp2 handle);

The number of bytes received during an asynchronous FTP download. This property is updated in real-time and an application may periodically fetch and display it's value while the download is in progress.

unsigned long CkFtp2_getAsyncBytesSent(HCkFtp2 handle);

The number of bytes sent during an asynchronous FTP upload. This property is updated in real-time and an application may periodically fetch and display it's value while the upload is in progress.

BOOL CkFtp2_getAsyncFinished(HCkFtp2 handle);

Set to true if the asynchronous transfer (download or upload) is finished.

void CkFtp2_getAsyncLog(HCkFtp2 handle, HCkString retval);

The last-error information for an asynchronous (background) file transfer.

BOOL CkFtp2_getAsyncSuccess(HCkFtp2 handle);

Set to true if the asynchronous file transfer succeeded.

BOOL CkFtp2_getAuthSsl(HCkFtp2 handle);
void CkFtp2_putAuthSsl(HCkFtp2 handle, BOOL newVal);

Same as AuthTls, except the command sent to the FTP server is "AUTH SSL" instead of "AUTH TLS". Most FTP servers accept either. AuthTls is more commonly used. If a particular server has trouble with AuthTls, try AuthSsl instead.

BOOL CkFtp2_getAuthTls(HCkFtp2 handle);
void CkFtp2_putAuthTls(HCkFtp2 handle, BOOL newVal);

Set this to true to switch to a TLS 1.0 encrypted channel. This property should be set prior to connecting. If this property is set, the port typically remains at it's default (21) and the Ssl property should *not* be set. When AuthTls is used, all control and data transmissions are encrypted. If your FTP client is behind a network-address-translating router, you may need to call ClearControlChannel after connecting and authenticating (i.e. after calling the Connect method). This keeps all data transmissions encrypted, but clears the control channel so that commands are sent unencrypted, thus allowing the router to translate network IP numbers in FTP commands.

BOOL CkFtp2_getAutoFeat(HCkFtp2 handle);
void CkFtp2_putAutoFeat(HCkFtp2 handle, BOOL newVal);

When true (which is the default value), a "FEAT" command is automatically sent to the FTP server immediately after connecting. This allows the Chilkat FTP2 component to know more about the server's capabilities and automatically adjust any applicable internal settings based on the response. In rare cases, some FTP servers reject the "FEAT" command and close the connection. Usually, if an FTP server does not implement FEAT, a harmless "command not understood" response is returned.

Set this property to false to prevent the FEAT command from being sent.

BOOL CkFtp2_getAutoSyst(HCkFtp2 handle);
void CkFtp2_putAutoSyst(HCkFtp2 handle, BOOL newVal);

When true (which is the default value), a "SYST" command is automatically sent to the FTP server immediately after connecting. This allows the Chilkat FTP2 component to know more about the server and automatically adjust any applicable internal settings based on the response. If the SYST command causes trouble (which is rare), this behavior can be turned off by setting this property equal to false.

BOOL CkFtp2_getAutoXcrc(HCkFtp2 handle);
void CkFtp2_putAutoXcrc(HCkFtp2 handle, BOOL newVal);

Many FTP servers support the XCRC command. The Chilkat FTP component will automatically know if XCRC is supported because it automatically sends a FEAT command to the server immediately after connecting.

If this property is set to true, then all uploads will be automatically verified by sending an XCRC command immediately after the transfer completes. If the CRC is not verified, the upload method (such as PutFile) will return a failed status.

To prevent XCRC checking, set this property to false.

long CkFtp2_getBandwidthThrottleDown(HCkFtp2 handle);
void CkFtp2_putBandwidthThrottleDown(HCkFtp2 handle, long newVal);

If set to a non-zero value, the FTP2 component will bandwidth throttle all downloads to this value.

The default value of this property is 0. The value should be specified in bytes/second.

Note: It is difficult to throttle very small downloads. (For example, how do you bandwidth throttle a 1-byte download???) As the downloaded file size gets larger, the transfer rate will better approximate this property's setting.

long CkFtp2_getBandwidthThrottleUp(HCkFtp2 handle);
void CkFtp2_putBandwidthThrottleUp(HCkFtp2 handle, long newVal);

If set to a non-zero value, the FTP2 component will bandwidth throttle all uploads to this value.

The default value of this property is 0. The value should be specified in bytes/second.

Note: It is difficult to throttle very small uploads. (For example, how do you bandwidth throttle a 1-byte upload???) As the uploaded file size gets larger, the transfer rate will better approximate this property's setting.

long CkFtp2_getConnectFailReason(HCkFtp2 handle);

If the Connect method fails, this property can be checked to determine the reason for failure.

Possible values are:

0 = success
Normal (non-SSL) sockets:
1 = empty hostname
2 = DNS lookup failed
3 = DNS timeout
4 = Aborted by application.
5 = Internal failure.
6 = Connect Timed Out
7 = Connect Rejected (or failed for some other reason)
SSL:
100 = Internal schannel error
101 = Failed to create credentials
102 = Failed to send initial message to proxy.
103 = Handshake failed.
104 = Failed to obtain remote certificate.
Protocol/Component:
300 = asynch op in progress
301 = login failure.

long CkFtp2_getConnectTimeout(HCkFtp2 handle);
void CkFtp2_putConnectTimeout(HCkFtp2 handle, long newVal);

Maximum number of seconds to wait when connecting to an FTP server.

BOOL CkFtp2_getConnectVerified(HCkFtp2 handle);

True if the FTP2 component was able to establish a TCP/IP connection to the FTP server after calling Connect.

long CkFtp2_getCrlfMode(HCkFtp2 handle);
void CkFtp2_putCrlfMode(HCkFtp2 handle, long newVal);

Used to control CRLF line endings when downloading text files in ASCII mode. The default value is 0.

Possible values are:

0 = Do nothing.  The line-endings are not modified as received from the FTP server.
1 = Convert all line-endings to CR+LF
2 = Convert all line-endings to bare LF's
3 = Convert all line-endings to bare CR's

void CkFtp2_getDirListingCharset(HCkFtp2 handle, HCkString retval);
void CkFtp2_putDirListingCharset(HCkFtp2 handle, const char *newVal);

Set to "ansi" by default. If the FTP server sends directory listings with non-English filenames, this property can be set to the appropriate value if necessary.

long CkFtp2_getDownloadRate(HCkFtp2 handle);

The average download rate in bytes/second. This property is updated in real-time during any FTP download (asynchronous or synchronous).

BOOL CkFtp2_getHasModeZ(HCkFtp2 handle);

Chilkat FTP2 supports MODE Z, which is a transfer mode implemented by some FTP servers. It allows for files to be uploaded and downloaded using compressed streams (using the zlib deflate algorithm). This is a read-only property. It will be set to true if the FTP2 component detects that your FTP server supports MODE Z. Otherwise it is set to false.

long CkFtp2_getHeartbeatMs(HCkFtp2 handle);
void CkFtp2_putHeartbeatMs(HCkFtp2 handle, long newVal);

This is the number of milliseconds between each AbortCheck event callback. The AbortCheck callback allows an application to abort any FTP operation prior to completion. If HeartbeatMs is 0, no AbortCheck event callbacks will occur. Also, AbortCheck callbacks do not occur when doing asynchronous transfers.

void CkFtp2_getHostname(HCkFtp2 handle, HCkString retval);
void CkFtp2_putHostname(HCkFtp2 handle, const char *newVal);

The FTP server hostname.

long CkFtp2_getIdleTimeoutMs(HCkFtp2 handle);
void CkFtp2_putIdleTimeoutMs(HCkFtp2 handle, long newVal);

This timeout causes FTP operations to fail when no activity is seen on the control or data socket for this number of milliseconds. Setting IdleTimeoutMs = 0 (the default) allows the application to wait indefinitely.

BOOL CkFtp2_getIsConnected(HCkFtp2 handle);

Returns true if currently connected and logged into an FTP server, otherwise returns false.

Note: Accessing this property may cause a NOOP command to be sent to the FTP server.

BOOL CkFtp2_getKeepSessionLog(HCkFtp2 handle);
void CkFtp2_putKeepSessionLog(HCkFtp2 handle, BOOL newVal);

Turns the in-memory session logging on or off. If on, the session log can be obtained via the SessionLog property.

void CkFtp2_getLastErrorHtml(HCkFtp2 handle, HCkString retval);

The last-error information returned in an HTML formatted string.Error information in HTML format for the last method called.

void CkFtp2_getLastErrorText(HCkFtp2 handle, HCkString retval);

The last-error information returned in a plain-text string with CRLF line-endings.Error information in plain-text format for the last method called.

void CkFtp2_getLastErrorXml(HCkFtp2 handle, HCkString retval);

The last-error information returned in an XML formatted string.Error information in XML format for the last method called.

void CkFtp2_getListPattern(HCkFtp2 handle, HCkString retval);
void CkFtp2_putListPattern(HCkFtp2 handle, const char *newVal);

A wildcard pattern, defaulting to "*" that determines the files and directories included in the following properties and methods: NumFilesAndDirs, GetCreateTime, GetFilename, GetIsDirectory, GetLastAccessTime, GetModifiedTime, GetSize.

BOOL CkFtp2_getLoginVerified(HCkFtp2 handle);

True if the FTP2 component was able to login to the FTP server after calling Connect.

long CkFtp2_getNumFilesAndDirs(HCkFtp2 handle);

The number of files and sub-directories in the current remote directory that match the ListPattern. (The ListPattern defaults to "*", so unless changed, this is the total number of files and sub-directories.)

Special considerations.

BOOL CkFtp2_getPartialTransfer(HCkFtp2 handle);

To be documented soon.

BOOL CkFtp2_getPassive(HCkFtp2 handle);
void CkFtp2_putPassive(HCkFtp2 handle, BOOL newVal);

Set to true for FTP to operate in passive mode, otherwise set to false for non-passive (the default).

BOOL CkFtp2_getPassiveUseHostAddr(HCkFtp2 handle);
void CkFtp2_putPassiveUseHostAddr(HCkFtp2 handle, BOOL newVal);

This can handle problems that may arise when an FTP server is located behind a NAT router. FTP servers respond to the PASV command by sending the IP address and port where it will be listening for the data connection. If the control connection is SSL encrypted, the NAT router is not able to convert from an internal IP address (typically beginning with 192.168) to an external address. When set to true, PassiveUseHostAddr property tells the FTP client to discard the IP address part of the PASV response and replace it with the IP address of the already-established control connection. The default value of this property is false.

void CkFtp2_getPassword(HCkFtp2 handle, HCkString retval);
void CkFtp2_putPassword(HCkFtp2 handle, const char *newVal);

Password for logging into the FTP server.

long CkFtp2_getPort(HCkFtp2 handle);
void CkFtp2_putPort(HCkFtp2 handle, long newVal);

Port number. Automatically defaults to the default port for the FTP service.

long CkFtp2_getProgressMonSize(HCkFtp2 handle);
void CkFtp2_putProgressMonSize(HCkFtp2 handle, long newVal);

Progress monitoring for FTP downloads rely on the FTP server indicating the file size within the RETR response. Some FTP servers however, do not indicate the file size and therefore it is not possible to monitor progress based on percentage completion. This property allows the application to explicitly tell the FTP component the size of the file about to be downloaded for the next GetFile call.

void CkFtp2_getProxyHostname(HCkFtp2 handle, HCkString retval);
void CkFtp2_putProxyHostname(HCkFtp2 handle, const char *newVal);

The hostname of your FTP proxy, if a proxy server is used.

long CkFtp2_getProxyMethod(HCkFtp2 handle);
void CkFtp2_putProxyMethod(HCkFtp2 handle, long newVal);

The proxy scheme used by your FTP proxy server. Valid values are 0 to 6. The default value is 0 which indicates that no proxy server is used. Supported proxy methods are as follows:

Note: The ProxyHostname is the hostname of the firewall, if the proxy is a firewall. Also, the ProxyUsername and ProxyPassword are the firewall username/password (if the proxy is a firewall).

ProxyMethod = 1 (SITE site)

USER ProxyUsername
PASS ProxyPassword
SITE Hostname
USER Username
PASS Password

ProxyMethod = 2 (USER user@site)

USER Username@Hostname:Port
PASS Password

ProxyMethod = 3 (USER with login)

USER ProxyUsername
PASS ProxyPassword
USER Username@Hostname:Port
PASS Password

ProxyMethod = 4 (USER/PASS/ACCT)

USER Username@Hostname:Port ProxyUsername
PASS Password
ACCT ProxyPassword

ProxyMethod = 5 (OPEN site)

USER ProxyUsername
PASS ProxyPassword
OPEN Hostname
USER Username
PASS Password

ProxyMethod = 6 (firewallId@site)

USER ProxyUsername@Hostname
USER Username
PASS Password

void CkFtp2_getProxyPassword(HCkFtp2 handle, HCkString retval);
void CkFtp2_putProxyPassword(HCkFtp2 handle, const char *newVal);

The password for authenticating with the FTP proxy server.

long CkFtp2_getProxyPort(HCkFtp2 handle);
void CkFtp2_putProxyPort(HCkFtp2 handle, long newVal);

If an FTP proxy server is used, this is the port number at which the proxy server is listening for connections.

void CkFtp2_getProxyUsername(HCkFtp2 handle, HCkString retval);
void CkFtp2_putProxyUsername(HCkFtp2 handle, const char *newVal);

The username for authenticating with the FTP proxy server.

long CkFtp2_getReadTimeout(HCkFtp2 handle);
void CkFtp2_putReadTimeout(HCkFtp2 handle, long newVal);

Maximum number of seconds to wait when reading from an FTP server. The ReadTimeout is the amount of time that needs to elapse while no additional data is forthcoming. So during a long download, if the data stream halts for more than this amount, it will timeout. Otherwise, there is no limit on the length of time for the entire download.

BOOL CkFtp2_getRequireSslCertVerify(HCkFtp2 handle);
void CkFtp2_putRequireSslCertVerify(HCkFtp2 handle, BOOL newVal);

If true, then the FTP2 client will verify the server's SSL certificate. The certificate is expired, or if the cert's signature is invalid, the connection is not allowed. The default value of this property is false.

BOOL CkFtp2_getRestartNext(HCkFtp2 handle);
void CkFtp2_putRestartNext(HCkFtp2 handle, BOOL newVal);

Both uploads and downloads may be resumed by simply setting this property = true and re-calling the upload or download method.

void CkFtp2_getSessionLog(HCkFtp2 handle, HCkString retval);

Contains the session log if KeepSessionLog is turned on.

BOOL CkFtp2_getSsl(HCkFtp2 handle);
void CkFtp2_putSsl(HCkFtp2 handle, BOOL newVal);

Use SSL for FTP connections. You would typically set Ssl = true when connecting to port 990 on FTP servers that support SSL mode. Note: It is more common to use AuthTls.

BOOL CkFtp2_getSslServerCertVerified(HCkFtp2 handle);

Read-only property that returns true if the FTP server's digital certificate was verified when connecting via SSL / TLS.

long CkFtp2_getUploadRate(HCkFtp2 handle);

The average upload rate in bytes/second. This property is updated in real-time during any FTP upload (asynchronous or synchronous).

void CkFtp2_getUsername(HCkFtp2 handle, HCkString retval);
void CkFtp2_putUsername(HCkFtp2 handle, const char *newVal);

Username for logging into the FTP server. Defaults to "anonymous".

BOOL CkFtp2_getUtf8(HCkFtp2 handle);
void CkFtp2_putUtf8(HCkFtp2 handle, BOOL newVal);

When set to true, all "const char *" arguments are expected to be utf-8 strings. If set to false, the "const char *" arguments are expected to be ANSI strings.

void CkFtp2_getVersion(HCkFtp2 handle, HCkString retval);

Version of the component, such as "1.0.0"

C "Methods"

BOOL CkFtp2_AppendFile(HCkFtp2 handle, const char *localFilename, const char *remoteFilename);

Same as PutFile but the file on the FTP server is appended.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_AppendFileFromBinaryData(HCkFtp2 handle, const char *remoteFilename, HCkByteData binaryData);

Same as PutFileFromBinaryData, except the file on the FTP server is appended.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_AppendFileFromTextData(HCkFtp2 handle, const char *remoteFilename, const char *textData);

Same as PutFileFromTextData, except the file on the FTP server is appended.

Returns TRUE for success, FALSE for failure.

void CkFtp2_AsyncAbort(HCkFtp2 handle);

Causes an asynchronous Get or Put to abort.

BOOL CkFtp2_AsyncAppendFileStart(HCkFtp2 handle, const char *localFilename, const char *remoteFilename);

Initiates an asynchronous append. The file is uploaded and appended to an existing file on the FTP server. The append happens in a background thread and can be aborted by calling AsyncAbort. The AsyncFinished property can be checked periodically to determine when the background transfer is finished. The status of the transfer is available in the AsyncSuccess property. The last-error information is available in the AsyncLog property. The AsyncBytesSent property is updated in real time to reflect the current number of bytes sent while the transfer is in progress. The UploadRate is also updated with the current upload rate in bytes/second. While a transfer is in progress, a program may periodically read the UploadRate and AsyncBytesSent properties to display progress.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_AsyncGetFileStart(HCkFtp2 handle, const char *remoteFilename, const char *localFilename);

Initiates an asynchronous file download. The download happens in a background thread and can be aborted by calling AsyncAbort. The AsyncFinished property can be checked periodically to determine when the background transfer is finished. The status of the transfer is available in the AsyncSuccess property. The last-error information is available in the AsyncLog property. The AsyncBytesReceived property is updated in real time to reflect the current number of bytes received while the transfer is in progress. The DownloadRate is also updated with the current download rate in bytes/second. While a transfer is in progress, a program may periodically read the DownloadRate and AsyncBytesReceived properties to display progress.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_AsyncPutFileStart(HCkFtp2 handle, const char *localFilename, const char *remoteFilename);

Initiates an asynchronous file upload. The file is uploaded and creates a new file on the FTP server, or overwrites an existing file. The upload happens in a background thread and can be aborted by calling AsyncAbort. The AsyncFinished property can be checked periodically to determine when the background transfer is finished. The status of the transfer is available in the AsyncSuccess property. The last-error information is available in the AsyncLog property. The AsyncBytesSent property is updated in real time to reflect the current number of bytes sent while the transfer is in progress. The UploadRate is also updated with the current upload rate in bytes/second. While a transfer is in progress, a program may periodically read the UploadRate and AsyncBytesSent properties to display progress.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_ChangeRemoteDir(HCkFtp2 handle, const char *relativeDirPath);

Changes the current remote directory.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_ClearControlChannel(HCkFtp2 handle);

Reverts the FTP control channel from SSL/TLS to an unencrypted channel. This may be required when using FTPS with AUTH TLS where the FTP client is behind a DSL or cable-modem router that performs NAT (network address translation). If the control channel is encrypted, the router is unable to translate the IP address sent in the PORT command for data transfers. By clearing the control channel, the data transfers will remain encrypted, but the FTP commands are passed unencrypted. Your program would typically clear the control channel after authenticating.

Returns TRUE for success, FALSE for failure.

void CkFtp2_ClearDirCache(HCkFtp2 handle);

TheNumFilesAndDirs property returns the count of files and sub-directories in the current remote FTP directory, according to the ListPattern property. For example, if ListPattern is set to “*.xml”, then NumFilesAndDirs returns the count of XML files in the remote directory.

The 1st time it is accessed, the component will (behind the scenes) fetch the directory listing from the FTP server. This information is cached in the component until (1) the current remote directory is changed, or (2) the ListPattern is changed, or (3) the this method (ClearDirCache) is called.

void CkFtp2_ClearSessionLog(HCkFtp2 handle);

Clears the in-memory session log.

BOOL CkFtp2_Connect(HCkFtp2 handle);

Connects and logs in to the FTP server using the username/password provided in the component properties. Check the integer value of the ConnectFailReason if this method returns false (indicating failure).

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_ConvertToTls(HCkFtp2 handle);

To be documented soon...

BOOL CkFtp2_CreatePlan(HCkFtp2 handle, const char *localDir, HCkString str);

Creates an "FTP plan" that lists the FTP operations that would be performed when PutTree is called. Additionally, the PutPlan method executes an "FTP plan" and logs each successful operation to a plan log file. If a large-scale upload is interrupted, the PutPlan can be resumed, skipping over the operations already listed in the plan log file.

BOOL CkFtp2_CreateRemoteDir(HCkFtp2 handle, const char *dir);

Creates a directory on the FTP server. If the directory already exists, a new one is not created and false is returned.

Returns TRUE for success, FALSE for failure.

long CkFtp2_DeleteMatching(HCkFtp2 handle, const char *remotePattern);

Deletes all the files in the current remote FTP directory matching the pattern. Returns the number of files deleted, or -1 for failure. The pattern is a string such as "*.txt", where any number of "*" wildcard characters can be used. "*" matches 0 or more of any character.

BOOL CkFtp2_DeleteRemoteFile(HCkFtp2 handle, const char *filename);

Deletes a file on the FTP server.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_DeleteTree(HCkFtp2 handle);

Deletes the entire subtree and all files from the current remote FTP directory. To delete a subtree on the FTP server, your program would first navigate to the root of the subtree to be deleted by calling ChangeRemoteDir, and then call DeleteTree. There are two event callbacks: VerifyDeleteFile and VerifyDeleteDir. Both are called prior to deleting each file or directory. The arguments to the callback include the full filepath of the file or directory, and an output-only "skip" flag. If your application sets the skip flag to true, the file or directory is NOT deleted. If a directory is not deleted, all files and sub-directories will remain. Example programs can be found at http://www.example-code.com/

Returns TRUE for success, FALSE for failure.

int CkFtp2_DetermineProxyMethod(HCkFtp2 handle);

Automatically determines the ProxyMethod that should be used with an FTP proxy server. Tries each of the five possible ProxyMethod settings and returns the value (1-5) of the ProxyMethod that succeeded.

This method may take a minute or two to complete. Returns 0 if no proxy methods were successful. Returns -1 to indicate an error (i.e. it was unable to test all proxy methods.)

BOOL CkFtp2_DetermineSettings(HCkFtp2 handle, HCkString xmlReport);

Discovers which combinations of FTP2 property settings result in successful data transfers.

DetermineSettings tries 13 different combinations of these properties:

Ssl
AuthTls
AuthSsl
Port
Passive
PassiveUseHostAddr
Within the FTP protocol, the process of fetching a directory listing is also considered a “data transfer”. The DetermineSettings method works by checking to see which combinations result in a successful directory listing download. The method takes no arguments and returns a string containing an XML report of the results. It is a blocking call that may take approximately a minute to run. If you are unsure about how to interpret the results, cut-and-paste it into an email and send it to support@chilkatsoft.com.

BOOL CkFtp2_DirTreeXml(HCkFtp2 handle, HCkString strXml);

Recursively downloads the structure of a complete remote directory tree. Returns an XML document with the directory structure. A zero-length string is returned to indicate failure.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_Disconnect(HCkFtp2 handle);

Disconnects from the FTP server, ending the current session.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_DownloadTree(HCkFtp2 handle, const char *localRoot);

Downloads an entire tree from the FTP server and recreates the directory tree on the local filesystem.

This method downloads all the files and subdirectories in the current remote directory. An application would first navigate to the directory to be downloaded via ChangeRemoteDir and then call this method.

There are three event callbacks (for programming languages supporting events): BeginDownloadFile, EndDownloadFile, and VerifyDownloadDir. The 1st argument to each callback is the fully qualified pathname of the file or directory. The BeginDownloadFile event callbacks has a "skip" argument, which is output-only. The application can set it to true to prevent the file from being downloaded. The VerifyDownloadDir also has a "skip" argument where the application can cause an entire sub-tree to be skipped. The EndDownloadFile event includes a "numBytes" argument containing the size of the file in bytes.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_Feat(HCkFtp2 handle, HCkString sOut);

Sends a FEAT command to the FTP server and returns the response. Returns a zero-length string to indicate failure. Here is a typical response:

211-Features:
 MDTM
 REST STREAM
 SIZE
 MLST type*;size*;modify*;
 MLSD
 AUTH SSL
 AUTH TLS
 UTF8
 CLNT
 MFMT
211 End

BOOL CkFtp2_GetCreateTime(HCkFtp2 handle, long index, SYSTEMTIME *sysTime);

Returns the create time for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)

BOOL CkFtp2_GetCreateTimeByName(HCkFtp2 handle, const char *filename, SYSTEMTIME *sysTime);

Returns the file-creation time for a remote file by filename.

BOOL CkFtp2_GetCurrentRemoteDir(HCkFtp2 handle, HCkString str);

Returns the current remote directory.

BOOL CkFtp2_GetFile(HCkFtp2 handle, const char *remoteFilename, const char *localFilename);

Downloads a file from the FTP server to the local filesystem.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_GetFilename(HCkFtp2 handle, long index, HCkString str);

Returns the filename for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)

BOOL CkFtp2_GetIsDirectory(HCkFtp2 handle, long index);

Returns true for a sub-directory and false for a file, for the Nth entry in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)

BOOL CkFtp2_GetIsSymbolicLink(HCkFtp2 handle, long index);

Returns true if the remote file is a symbolic link. (Symbolic links only exist on Unix/Linux systems, not on Windows filesystems.)

BOOL CkFtp2_GetLastAccessTime(HCkFtp2 handle, long index, SYSTEMTIME *sysTime);

Returns the last access time for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)

BOOL CkFtp2_GetLastAccessTimeByName(HCkFtp2 handle, const char *filename, SYSTEMTIME *sysTime);

Returns a remote file's last-access time.

BOOL CkFtp2_GetLastModifiedTime(HCkFtp2 handle, long index, SYSTEMTIME *sysTime);

Returns the last modified time for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)

BOOL CkFtp2_GetLastModifiedTimeByName(HCkFtp2 handle, const char *filename, SYSTEMTIME *sysTime);

Returns the last-modified date/time for a remote file.

BOOL CkFtp2_GetRemoteFileBinaryData(HCkFtp2 handle, const char *remoteFilename, HCkByteData data);

Downloads the contents of a remote file into a byte array.

BOOL CkFtp2_GetRemoteFileTextC(HCkFtp2 handle, const char *remoteFilename, const char *charset, HCkString str);

Downloads a text file directly into a string variable. The character encoding of the text file is specified by the charset argument, which is a value such as utf-8, iso-8859-1, Shift_JIS, etc.

BOOL CkFtp2_GetRemoteFileTextData(HCkFtp2 handle, const char *remoteFilename, HCkString str);

Downloads the content of a remote text file directly into an in-memory string.

Note: If the remote text file does not use the ANSI character encoding, call GetRemoteFileTextC instead, which allows for the character encoding to be specified so that characters are properly interpreted.

long CkFtp2_GetSize(HCkFtp2 handle, long index);

Returns the size of the Nth remote file in the current directory.

long CkFtp2_GetSizeByName(HCkFtp2 handle, const char *filname);

Returns a remote file's size in bytes.

BOOL CkFtp2_GetSizeStr(HCkFtp2 handle, long index, HCkString str);

Returns the size of a remote filename as a string. This is helpful for file sizes that are greater then 2GB.

BOOL CkFtp2_GetSizeStrByName(HCkFtp2 handle, const char *filename, HCkString outStr);

To be documented soon...

HCkCert CkFtp2_GetSslServerCert(HCkFtp2 handle);

Returns the FTP server's digital certificate (for SSL / TLS connections).

BOOL CkFtp2_GetTextDirListing(HCkFtp2 handle, const char *pattern, HCkString strRawListing);

Returns a listing of the files and directories in the current directory matching the pattern. Passing "*.*" will return all the files and directories.

BOOL CkFtp2_GetXmlDirListing(HCkFtp2 handle, const char *pattern, HCkString strXmlListing);

Returns (in XML format) the files and directories in the current directory matching the pattern. Passing "*.*" will return all the files and directories.

BOOL CkFtp2_IsUnlocked(HCkFtp2 handle);

Return true if the component is already unlocked.

long CkFtp2_MGetFiles(HCkFtp2 handle, const char *remotePattern, const char *localDir);

Copies all the files in the current remote FTP directory to a local directory. To copy all the files in a remote directory, set remotePattern to "*.*" The pattern can contain any number of "*"characters where "*" matches 0 or more of any character. The return value is the number of files transferred, and on error, a value of -1 is returned. Detailed information about the transfer can be obtained from the last-error information (LastErrorText/LastErrorHtml/LastErrorXml/SaveLastError).

long CkFtp2_MPutFiles(HCkFtp2 handle, const char *pattern);

Uploads all the files matching pattern on the local computer to the current remote FTP directory. The pattern parameter can include directory information, such as "C:/my_dir/*.txt" or it can simply be a pattern such as "*.*" that matches the files in the application's current directory. Subdirectories are not recursed. The return value is the number of files copied, with a value of -1 returned for errors. Detailed information about the transfer can be obtained from the XML log.[

BOOL CkFtp2_Noop(HCkFtp2 handle);

Issues a no-op command to the FTP server.

BOOL CkFtp2_PutFile(HCkFtp2 handle, const char *localFilename, const char *remoteFilename);

Uploads a local file to the current directory on the FTP server.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_PutFileFromBinaryData(HCkFtp2 handle, const char *remoteFilename, HCkByteData binaryData);

Creates a file on the remote server containing the data passed in a byte array.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_PutFileFromTextData(HCkFtp2 handle, const char *remoteFilename, const char *textData);

Creates a file on the remote server containing the data passed in a string. Returns true for success, false for failure.[

BOOL CkFtp2_PutPlan(HCkFtp2 handle, const char *planUtf8, const char *planLogFilename);

Executes an "FTP plan" (created by the CreatePlan method) and logs each successful operation to a plan log file. If a large-scale upload is interrupted, the PutPlan can be resumed, skipping over the operations already listed in the plan log file. When resuming an interrupted PutPlan method, use the same log file. All completed operations found in the already-existing log will automatically be skipped.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_PutTree(HCkFtp2 handle, const char *localDir);

Uploads an entire directory tree from the local filesystem to the remote FTP server, recreating the directory tree on the server. The PutTree method copies a directory tree to the current remote directory on the FTP server.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_Quote(HCkFtp2 handle, const char *cmd);

Sends an arbitrary (raw) command to the FTP server and returns the raw response.

BOOL CkFtp2_RemoveRemoteDir(HCkFtp2 handle, const char *dir);

Removes a directory from the FTP server.

BOOL CkFtp2_RenameRemoteFile(HCkFtp2 handle, const char *existingFilename, const char *newFilename);

Renames a file or directory on the FTP server. To move a file from one directory to another on a remote FTP server, call this method and include the source and destination directory filepath.

BOOL CkFtp2_SaveLastError(HCkFtp2 handle, const char *filename);

Saves the last error information to an XML formatted file.

BOOL CkFtp2_SendCommand(HCkFtp2 handle, const char *cmd, HCkString reply);

Sends an raw command to the FTP server and returns the raw response.

BOOL CkFtp2_SetModeZ(HCkFtp2 handle);

Chilkat FTP2 supports MODE Z, which is a transfer mode implemented by some FTP servers. It allows for files to be uploaded and downloaded using compressed streams (using the zlib deflate algorithm).

Call this method after connecting to enable Mode Z. Once enabled, all transfers (uploads, downloads, and directory listings) are compressed.

Returns TRUE for success, FALSE for failure.

void CkFtp2_SetOldestDate(HCkFtp2 handle, SYSTEMTIME *oldestDateTime);

Used in conjunction with the DownloadTree method. Call this method prior to calling DownloadTree to set the oldest date for a file to be downloaded. When DownloadTree is called, any file older than this date will not be downloaded.

void CkFtp2_SetSslCertRequirement(HCkFtp2 handle, const char *name, const char *value);

Enforces a requirement on the FTP server's certificate. The reqName can be "SubjectDN", "SubjectCN", "IssuerDN", or "IssuerCN". The reqName specifies the part of the certificate, and the reqValue is the value that it must match (exactly). If the FTP server's certificate does not match, the SSL / TLS connection is aborted.

void CkFtp2_SetSslClientCert(HCkFtp2 handle, HCkCert cert);

Allows for a client-side certificate to be used for the SSL / TLS connection.

BOOL CkFtp2_SetTypeAscii(HCkFtp2 handle);

Set the FTP transfer mode to us-ascii.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_SetTypeBinary(HCkFtp2 handle);

Set the FTP transfer mode to binary.

Returns TRUE for success, FALSE for failure.

BOOL CkFtp2_Site(HCkFtp2 handle, const char *params);

Sends an arbitrary "site" command to the FTP server. The params argument should contain the parameters to the site command as they would appear on a command line. For example: "recfm=fb lrecl=600".

Returns TRUE for success, FALSE for failure.

void CkFtp2_SleepMs(HCkFtp2 handle, int millisec);

Causes the calling process to sleep for a number of milliseconds.

BOOL CkFtp2_Stat(HCkFtp2 handle, HCkString sOut);

Sends a STAT command to the FTP server and returns the server's reply.

BOOL CkFtp2_SyncLocalTree(HCkFtp2 handle, const char *localRoot, int mode);

Downloads files from the FTP 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.

BOOL CkFtp2_SyncRemoteTree(HCkFtp2 handle, const char *localRoot, int mode);

Uploads a directory tree from the local filesystem to the FTP 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.

BOOL CkFtp2_Syst(HCkFtp2 handle, HCkString sOut);

Sends a SYST command to the FTP server to find out the type of operating system at the server. The method returns the FTP server's response string. Refer to RFC 959 for details.

BOOL CkFtp2_UnlockComponent(HCkFtp2 handle, const char *code);

Unlocks the component. This must be called once prior to calling any other method.

const char *CkFtp2_account(HCkFtp2 handle);

Some FTP servers require an Account name in addition to login/password. This property can be set for those servers with this requirement.

const char *CkFtp2_asyncLog(HCkFtp2 handle);

The last-error information for an asynchronous (background) file transfer.

const char *CkFtp2_ck_stat(HCkFtp2 handle);

To be documented soon...

const char *CkFtp2_createPlan(HCkFtp2 handle, const char *localDir);

Creates an "FTP plan" that lists the FTP operations that would be performed when PutTree is called. Additionally, the PutPlan method executes an "FTP plan" and logs each successful operation to a plan log file. If a large-scale upload is interrupted, the PutPlan can be resumed, skipping over the operations already listed in the plan log file.

const char *CkFtp2_determineSettings(HCkFtp2 handle);

Discovers which combinations of FTP2 property settings result in successful data transfers.

DetermineSettings tries 13 different combinations of these properties:

Ssl
AuthTls
AuthSsl
Port
Passive
PassiveUseHostAddr
Within the FTP protocol, the process of fetching a directory listing is also considered a “data transfer”. The DetermineSettings method works by checking to see which combinations result in a successful directory listing download. The method takes no arguments and returns a string containing an XML report of the results. It is a blocking call that may take approximately a minute to run. If you are unsure about how to interpret the results, cut-and-paste it into an email and send it to support@chilkatsoft.com.

const char *CkFtp2_dirListingCharset(HCkFtp2 handle);

Set to "ansi" by default. If the FTP server sends directory listings with non-English filenames, this property can be set to the appropriate value if necessary.

const char *CkFtp2_dirTreeXml(HCkFtp2 handle);

Recursively downloads the structure of a complete remote directory tree. Returns an XML document with the directory structure. A zero-length string is returned to indicate failure.

Returns TRUE for success, FALSE for failure.

const char *CkFtp2_feat(HCkFtp2 handle);

Sends a FEAT command to the FTP server and returns the response. Returns a zero-length string to indicate failure. Here is a typical response:

211-Features:
 MDTM
 REST STREAM
 SIZE
 MLST type*;size*;modify*;
 MLSD
 AUTH SSL
 AUTH TLS
 UTF8
 CLNT
 MFMT
211 End

const char *CkFtp2_getCurrentRemoteDir(HCkFtp2 handle);

Returns the current remote directory.

const char *CkFtp2_getFilename(HCkFtp2 handle, long index);

Returns the filename for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)

const char *CkFtp2_getRemoteFileTextC(HCkFtp2 handle, const char *remoteFilename, const char *charset);

Downloads a text file directly into a string variable. The character encoding of the text file is specified by the charset argument, which is a value such as utf-8, iso-8859-1, Shift_JIS, etc.

const char *CkFtp2_getRemoteFileTextData(HCkFtp2 handle, const char *remoteFilename);

Downloads the content of a remote text file directly into an in-memory string.

Note: If the remote text file does not use the ANSI character encoding, call GetRemoteFileTextC instead, which allows for the character encoding to be specified so that characters are properly interpreted.

const char *CkFtp2_getSizeStr(HCkFtp2 handle, long index);

Returns the size of a remote filename as a string. This is helpful for file sizes that are greater then 2GB.

const char *CkFtp2_getSizeStrByName(HCkFtp2 handle, const char *filename);

To be documented soon...

const char *CkFtp2_getTextDirListing(HCkFtp2 handle, const char *pattern);

Returns a listing of the files and directories in the current directory matching the pattern. Passing "*.*" will return all the files and directories.

const char *CkFtp2_getXmlDirListing(HCkFtp2 handle, const char *pattern);

Returns (in XML format) the files and directories in the current directory matching the pattern. Passing "*.*" will return all the files and directories.

const char *CkFtp2_hostname(HCkFtp2 handle);

The FTP server hostname.

const char *CkFtp2_lastErrorHtml(HCkFtp2 handle);

Error information in HTML format for the last method called.

const char *CkFtp2_lastErrorText(HCkFtp2 handle);

Error information in plain-text format for the last method called.

const char *CkFtp2_lastErrorXml(HCkFtp2 handle);

Error information in XML format for the last method called.

const char *CkFtp2_listPattern(HCkFtp2 handle);

A wildcard pattern, defaulting to "*" that determines the files and directories included in the following properties and methods: NumFilesAndDirs, GetCreateTime, GetFilename, GetIsDirectory, GetLastAccessTime, GetModifiedTime, GetSize.

const char *CkFtp2_password(HCkFtp2 handle);

Password for logging into the FTP server.

const char *CkFtp2_proxyHostname(HCkFtp2 handle);

The hostname of your FTP proxy, if a proxy server is used.

const char *CkFtp2_proxyPassword(HCkFtp2 handle);

The password for authenticating with the FTP proxy server.

const char *CkFtp2_proxyUsername(HCkFtp2 handle);

The username for authenticating with the FTP proxy server.

const char *CkFtp2_sendCommand(HCkFtp2 handle, const char *cmd);

Sends an raw command to the FTP server and returns the raw response.

const char *CkFtp2_sessionLog(HCkFtp2 handle);

Contains the session log if KeepSessionLog is turned on.

const char *CkFtp2_syst(HCkFtp2 handle);

Sends a SYST command to the FTP server to find out the type of operating system at the server. The method returns the FTP server's response string. Refer to RFC 959 for details.

const char *CkFtp2_username(HCkFtp2 handle);

Username for logging into the FTP server. Defaults to "anonymous".

const char *CkFtp2_version(HCkFtp2 handle);

Version of the component, such as "1.0.0"