ChilkatSFtp ActiveX Reference

ChilkatSFtp

SFTP implementation for file transfer and remote file management over SSH.

Object Creation

(Visual Basic 6.0)
Dim obj As New ChilkatSFtp
(ASP)
set obj = Server.CreateObject("Chilkat.SFtp")
(VBScript)
set obj = CreateObject("Chilkat.SFtp")
(Delphi)
obj := TChilkatSFtp.Create(Self);
(FoxPro)
loObject = CreateObject('Chilkat.SFtp')
(SQL Server)
EXEC @hr = sp_OACreate 'Chilkat.SFtp', @obj OUT
(Javascript)
var obj = new ActiveXObject("Chilkat.SFtp");

Properties

AccumulateBuffer As Variant (read-only)

Contains the bytes downloaded from a remote file via the AccumulateBytes method call. Each call to AccumulateBytes appends to this buffer. To clear this buffer, call the ClearAccumulateBuffer method.

ClientIdentifier As String

The client-identifier string to be used when connecting to an SSH/SFTP server. Defaults to "SSH-2.0-PuTTY_Local:_Jun_27_2008_16:28:58". (This string is used to mimic PuTTY because some servers are known to disconnect from clients with unknown client identifiers.)

ClientIpAddress As String

The IP address to use for computers with multiple network interfaces or IP addresses. For computers with a single network interface (i.e. most computers), this property should not be set. For multihoming computers, the default IP address is automatically used if this property is not set.

The IP address is a string such as in dotted notation using numbers, not domain names, such as "165.164.55.124".

ConnectTimeoutMs As Long

Maximum number of milliseconds to wait when connecting to an SSH server.

DebugLogFilePath As String

Used for debugging in cases where a Chilkat method call hangs and never returns. This should generally never happen. The only causes for this are (1) a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired, (2) the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or (3) there is an internal problem (bug) in the Chilkat code that causes the hang.

This property allows one to specifiy a debug file path that will be created (or appended if it already exists) and information will be logged to it as the Chilkat methods are called. If a hang occurs, the log file may be viewed to get information about what happened.

DisconnectCode As Long (read-only)

If the SSH/SFTP server sent a DISCONNECT message when closing the connection, this property contains the "reason code" as specified in RFC 4253:

           Symbolic name                                reason code
           -------------                                -----------
      SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT             1
      SSH_DISCONNECT_PROTOCOL_ERROR                          2
      SSH_DISCONNECT_KEY_EXCHANGE_FAILED                     3
      SSH_DISCONNECT_RESERVED                                4
      SSH_DISCONNECT_MAC_ERROR                               5
      SSH_DISCONNECT_COMPRESSION_ERROR                       6
      SSH_DISCONNECT_SERVICE_NOT_AVAILABLE                   7
      SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED          8
      SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE                 9
      SSH_DISCONNECT_CONNECTION_LOST                        10
      SSH_DISCONNECT_BY_APPLICATION                         11
      SSH_DISCONNECT_TOO_MANY_CONNECTIONS                   12
      SSH_DISCONNECT_AUTH_CANCELLED_BY_USER                 13
      SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE         14
      SSH_DISCONNECT_ILLEGAL_USER_NAME                      15

DisconnectReason As String (read-only)

If the SSH/SFTP server sent a DISCONNECT message when closing the connection, this property contains a descriptive string for the "reason code" as specified in RFC 4253.

EnableCache As Long

Controls whether the component keeps an internal file size & attribute cache. The cache affects the following methods: GetFileSize32, GetFileSize64, GetFileSizeStr, GetFileCreateTime, GetFileLastAccess, GetFileLastModified, GetFileOwner, GetFileGroup, and GetFilePermissions.

The file attribute cache exists to minimize communications with the SFTP server. If the cache is enabled, then a request for any single attribute will cause all of the attributes to be cached. A subsequent request for a different attribute of the same file will be fulfilled from cache, eliminating the need for a message to be sent to the SFTP server.

Note: Caching only occurs when filenames are used, not handles.

FilenameCharset As String

Automatically set during the InitializeSftp method if the server sends a filename-charset name-value extension. Otherwise, may be set directly to the name of a charset, such as "utf-8", "iso-8859-1", "windows-1252", etc. ("ansi" is also a valid choice.) Incoming filenames are interpreted as utf-8 if no FilenameCharset is set. Outgoing filenames are sent using utf-8 by default. Otherwise, incoming and outgoing filenames use the charset specified by this property.

ForceCipher As String

Set to one of the following encryption algorithms to force that cipher to be used. By default, the component will automatically choose the first cipher supported by the server in the order listed here: "aes256-cbc", "aes128-cbc", "twofish256-cbc", "twofish128-cbc", "blowfish-cbc", "3des-cbc", "arcfour128", "arcfour256". (If blowfish is chosen, the encryption strength is 128 bits.)

Important: If this is property is set and the server does NOT support then encryption algorithm, then the Connect will fail.

ForceV3 As Long

If set to 1, forces the client to choose version 3 of the SFTP protocol, even if the server supports a higher version. The default value of this property is 0.

HeartbeatMs As Long

This is the number of milliseconds between each AbortCheck event callback. The AbortCheck callback allows an application to abort any SFTP operation prior to completion. If HeartbeatMs is 0 (the default), no AbortCheck event callbacks will fire.

HostKeyFingerprint As String (read-only)

Set after connecting to an SSH/SFTP server. The format of the fingerprint looks like this: "ssh-rsa 1024 68:ff:d1:4e:6c:ff:d7:b0:d6:58:73:85:07:bc:2e:d5"

HttpProxyAuthMethod As String

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy authentication method name. Valid choices are "LOGIN" or "NTLM".

HttpProxyHostname As String

If an HTTP proxy is to be used, set this property to the HTTP proxy hostname or IPv4 address (in dotted decimal notation).

HttpProxyPassword As String

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy password.

HttpProxyPort As Long

If an HTTP proxy is to be used, set this property to the HTTP proxy port number. (Two commonly used HTTP proxy ports are 8080 and 3128.)

HttpProxyUsername As String

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy login name.

IdleTimeoutMs As Long

Causes SFTP operations to fail when progress for sending or receiving data halts for more than this number of milliseconds. Setting IdleTimeoutMs = 0 allows the application to wait indefinitely. The default value of this property is 30000 (which equals 30 seconds).

InitializeFailCode As Long (read-only)

The InitializeSftp method call opens a channel for the SFTP session. If the request to open a channel fails, this property contains a code that identifies the reason for failure. The reason codes are defined in RFC 4254 and are reproduced here:

             Symbolic name                           reason code
             -------------                           -----------
            SSH_OPEN_ADMINISTRATIVELY_PROHIBITED          1
            SSH_OPEN_CONNECT_FAILED                       2
            SSH_OPEN_UNKNOWN_CHANNEL_TYPE                 3
            SSH_OPEN_RESOURCE_SHORTAGE                    4

InitializeFailReason As String (read-only)

The InitializeSftp method call opens a channel for the SFTP session. If the request to open a channel fails, this property contains a description of the reason for failure. (It contains descriptive text matching the InitializeFailCode property.)

IsConnected As Long (read-only)

Returns 1 if connected to the SSH server. Note: This does not mean authentication has happened or InitializeSftp has already succeeded. It only means that the connection has been established by calling Connect.

KeepSessionLog As Long

Controls whether communications to/from the SFTP server are saved to the SessionLog property. The default value is 0. If this property is set to 1, the contents of the SessionLog property will continuously grow as SFTP activity transpires. The purpose of the KeepSessionLog / SessionLog properties is to help in debugging any future problems that may arise.

LastErrorHtml As String (read-only)

Error information in HTML format for the last method called.

LastErrorText As String (read-only)

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

LastErrorXml As String (read-only)

Error information in XML format for the last method called.

MaxPacketSize As Long

The maximum packet length to be used in the underlying SSH transport protocol. The default value is 32768. (This should generally be left unchanged.)

PasswordChangeRequested As Long (read-only)

Set by the AuthenticatePw and AuthenticatePwPk methods. If the authenticate method returns a failed status, and this property is set to 1, then it indicates the server requested a password change. In this case, re-call the authenticate method, but provide both the old and new passwords in the following format, where vertical bar characters encapsulate the old and new passwords:

|oldPassword|newPassword|

PreserveDate As Long

If 1, then the file last-modified and create date/time will be preserved for downloaded files. The default value is 0.

ProtocolVersion As Long (read-only)

The negotiated SFTP protocol version, which should be a value between 3 and 6 inclusive. When the InitializeSftp method is called, the Chilkat SFTP client sends it's highest supported protocol version to the server, and the server sends it's SFTP protocol version in response. The negotiated protocol (i.e. the protocol version used for the session) is the lower of the two numbers. If the SFTP server's protocol version is lower than 6, some file date/attributes are not supported because they are not supported by the earlier protocol version. These exceptions are noted throughout the reference documentation.

SessionLog As String (read-only)

Contains a log of the messages sent to/from the SFTP server. To enable session logging, set the KeepSessionLog property = 1. Note: This property is not a filename -- it is a string property that contains the session log data.

SocksHostname As String

The SOCKS4/SOCKS5 hostname or IPv4 address (in dotted decimal notation). This property is only used if the SocksVersion property is set to 4 or 5).

SocksPassword As String

The SOCKS5 password (if required). The SOCKS4 protocol does not include the use of a password, so this does not apply to SOCKS4.

SocksPort As Long

The SOCKS4/SOCKS5 proxy port. The default value is 1080. This property only applies if a SOCKS proxy is used (if the SocksVersion property is set to 4 or 5).

SocksUsername As String

The SOCKS4/SOCKS5 proxy username. This property is only used if the SocksVersion property is set to 4 or 5).

SocksVersion As Long

SocksVersion May be set to one of the following integer values:

0 - No SOCKS proxy is used. This is the default.
4 - Connect via a SOCKS4 proxy.
5 - Connect via a SOCKS5 proxy.

TcpNoDelay As Long

This property controls the use of the internal TCP_NODELAY socket option (which disables the Nagle algorithm). The default value of this property is 0. Setting this value to 1 disables the delay of sending successive small packets on the network.

UtcMode As Long

If 1, then date/times are returned as UTC times. If 0 (the default) then date/times are returned as local times.

VerboseLogging As Long

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0.

Version As String (read-only)

The version of the SFTP component, such as "2.3.0".

Methods

AccumulateBytes(handle As String, maxBytes As Long) As Long

Downloads bytes from an open file and appends them to the AccumulateBuffer. The handle is a file handle returned by the OpenFile method. The maxBytes is the maximum number of bytes to read. If the end-of-file is reached prior to reading the number of requested bytes, then fewer bytes may be returned.

Returns the number of bytes downloaded and appended to AccumulateBuffer. Returns -1 on error.

Add64(n1 As String, n2 As String) As String

Convenience method for 64-bit addition. Allows for two 64-bit integers to be passed as decimal strings and returns the sum in a decimal sting.

Returns a null on failure

AuthenticatePk(username As String, privateKey As ChilkatSshKey) As Long

Authenticates with the SSH server using public-key authentication. The corresponding public key must have been installed on the SSH server for the username. Authentication will succeed if the matching privateKey is provided.

Important: When reporting problems, please send the full contents of the LastErrorText property to support@chilkatsoft.com.

Returns 1 for success, 0 for failure.

AuthenticatePw(login As String, password As String) As Long

Authenticates with the SSH server using a login and password.

An SFTP session always begins by first calling Connect to connect to the SSH server, then calling either AuthenticatePw or AuthenticatePk to login, and finally calling InitializeSftp.

Important: When reporting problems, please send the full contents of the LastErrorText property to support@chilkatsoft.com.

Note: To learn about how to handle password change requests, see the PasswordChangeRequested property (above).

Returns 1 for success, 0 for failure.

AuthenticatePwPk(username As String, password As String, privateKey As ChilkatSshKey) As Long

Authentication for SSH servers that require both a password and private key. (Most SSH servers are configured to require one or the other, but not both.)

Important: When reporting problems, please send the full contents of the LastErrorText property to support@chilkatsoft.com.

Returns 1 for success, 0 for failure.

ClearAccumulateBuffer()

Clears the contents of the AccumulateBuffer property.

ClearCache()

Clears the internal file attribute cache. (Please refer to the EnableCache property for more information about the file attribute cache.)

ClearSessionLog()

Clears the contents of the SessionLog property.

CloseHandle(handle As String) As Long

Closes a file on the SSH/SFTP server. handle is a file handle returned from a previous call to OpenFile.

Returns 1 for success, 0 for failure.

Connect(domainName As String, port As Long) As Long

Connects to an SSH/SFTP server. The domainName may be a domain name or an IP address (example: 192.168.1.10). Both IPv4 and IPv6 addresses are supported. The port is typically 22, which is the standard port for SSH servers.

An SFTP session always begins by first calling Connect to connect to the SSH server, then calling either AuthenticatePw or AuthenticatePk to login, and finally calling InitializeSftp.

Important: When reporting problems, please send the full contents of the LastErrorText property to support@chilkatsoft.com.

Returns 1 for success, 0 for failure.

CopyFileAttr(localFilename As String, remoteFilename As String, isHandle As Long) As Long

Sets the date/time and other attributes of a remote file to be equal to that of a local file.

The attributes copied depend on the SFTP version of the server:

SFTP v3 (and below)
    Last-Modified Date/Time
    Last-Access Date/Time

SFTP v4, v5
    Last-Modified Date/Time
    Last-Access Date/Time
    Create Date/Time

SFTP v6 (and above)
    Last-Modified Date/Time
    Last-Access Date/Time
    Create Date/Time
    Read-Only Flag
    Hidden Flag
    Archive Flag
    Compressed Flag
    Encrypted Flag

Notes:
(1) The Last-Access date/time may or may not be set. Chilkat has found that the Last-Access time is set to the current date/time, which is probably a result of the operating system setting it based on when the SFTP server is touching the file.
(2) At the time of this writing, it is unknown whether the compressed/encryption settings for a local file are transferred to the remote file. For example, does the remote file become compressed and/or encrypted just by setting the flags? It may depend on the SFTP server and/or the remote filesystem.
(3) Dates/times are sent in GMT. SFTP servers should convert GMT times to local time zones.

Returns 1 for success, 0 for failure.

CreateDir(path As String) As Long

Creates a directory on the SFTP server.

Returns 1 for success, 0 for failure.

Disconnect()

Disconnects from the SSH server.

DownloadFile(handle As String, toFilename As String) As Long

Downloads a file from the SSH server to the local filesystem. There are no limitations on file size and the data is streamed from SSH server to the local file. handle is a file handle returned by a previous call to OpenFile.

Returns 1 for success, 0 for failure.

DownloadFileByName(remoteFilePath As String, localFilePath As String) As Long

Simplified method for downloading files.

Returns 1 for success, 0 for failure.

Understanding SFTP Absolute FilePaths

Eof(handle As String) As Long

Returns 1 if the last read operation for a handle reached the end of file. Otherwise returns 0. If an invalid handle is passed, a value of 1 is returned.

GetFileCreateTime(filenameOrHandle As String, bFollowLinks As Long, bIsHandle As Long) As Date

Returns the create date/time for a file. filenameOrHandle may be a remote filepath or an open handle string as returned by OpenFile. If filenameOrHandle is a handle, then bIsHandle must be set to 1, otherwise it should be 0. If bFollowLinks is 1, then symbolic links will be followed on the server.

Note: Servers running the SFTP v3 protocol or lower do not have the ability to return a file's creation date/time.

GetFileGroup(filenameOrHandle As String, bFollowLinks As Long, bIsHandle As Long) As String

Returns the group of a file. filenameOrHandle may be a remote filepath or an open handle string as returned by OpenFile. If filenameOrHandle is a handle, then bIsHandle must be set to 1, otherwise it should be 0. If bFollowLinks is 1, then symbolic links will be followed on the server.

Note: Servers running the SFTP v3 protocol or lower do not have the ability to return a file's group name. Instead, the decimal GID of the file is returned.

Returns a null on failure

GetFileLastAccess(filenameOrHandle As String, bFollowLinks As Long, bIsHandle As Long) As Date

Returns the last-access date/time for a file. filenameOrHandle may be a remote filepath or an open handle string as returned by OpenFile. If filenameOrHandle is a handle, then bIsHandle must be set to 1, otherwise it should be 0. If bFollowLinks is 1, then symbolic links will be followed on the server.

GetFileLastModified(filenameOrHandle As String, bFollowLinks As Long, bIsHandle As Long) As Date

Returns the last-modified date/time for a file. filenameOrHandle may be a remote filepath or an open handle string as returned by OpenFile. If filenameOrHandle is a handle, then bIsHandle must be set to 1, otherwise it should be 0. If bFollowLinks is 1, then symbolic links will be followed on the server.

GetFileOwner(filenameOrHandle As String, bFollowLinks As Long, bIsHandle As Long) As String

Returns the owner of a file. filenameOrHandle may be a remote filepath or an open handle string as returned by OpenFile. If filenameOrHandle is a handle, then bIsHandle must be set to 1, otherwise it should be 0. If bFollowLinks is 1, then symbolic links will be followed on the server.

Note: Servers running the SFTP v3 protocol or lower do not have the ability to return a file's owner name. Instead, the decimal UID of the file is returned.

Returns a null on failure

GetFilePermissions(filenameOrHandle As String, bFollowLinks As Long, bIsHandle As Long) As Long

Returns the access permisssions flags of a file. filenameOrHandle may be a remote filepath or an open handle string as returned by OpenFile. If filenameOrHandle is a handle, then bIsHandle must be set to 1, otherwise it should be 0. If bFollowLinks is 1, then symbolic links will be followed on the server.

GetFileSize32(filenameOrHandle As String, bFollowLinks As Long, bIsHandle As Long) As Long

Returns the size in bytes of a file on the SSH server. If the file size exceeds what can be represented in 32-bits, a value of -1 is returned. filenameOrHandle may be a remote filepath or an open handle string as returned by OpenFile. If filenameOrHandle is a handle, then bIsHandle must be set to 1, otherwise it should be 0. If bFollowLinks is 1, then symbolic links will be followed on the server.

GetFileSizeStr(filenameOrHandle As String, bFollowLinks As Long, bIsHandle As Long) As String

Returns the size in bytes (in decimal string form) of a file on the SSH server. filenameOrHandle may be a remote filepath or an open handle string as returned by OpenFile. If filenameOrHandle is a handle, then bIsHandle must be set to 1, otherwise it should be 0. If bFollowLinks is 1, then symbolic links will be followed on the server.

Note: This method exists for environments that do not have 64-bit integer support. The Add64 method is provided for 64-bit addition, and other methods such as ReadFileBytes64s allow for 64-bit values to be passed as strings.

Returns a null on failure

InitializeSftp() As Long

Intializes the SFTP subsystem. This should be called after connecting and authenticating. An SFTP session always begins by first calling Connect to connect to the SSH server, then calling either AuthenticatePw or AuthenticatePk to login, and finally calling InitializeSftp.

Important: When reporting problems, please send the full contents of the LastErrorText property to support@chilkatsoft.com.

If this method fails, the reason may be present in the InitializeFailCode and InitializeFailReason properties (assuming the failure occurred when trying to open the SFTP session channel).

The CkStringArray object is found in ChilkatUtil.dll This blog post provides a mapping of objects (by name) to DLL: ActiveX Object to DLL Mapping.

Returns 1 for success, 0 for failure.

Error Explained: Received FAILURE response to subsystem request.

LastReadFailed(handle As String) As Long

Returns 1 if the last read on the specified handle failed. Otherwise returns 0.

LastReadNumBytes(handle As String) As Long

Returns the number of bytes received by the last read on a specified channel.

OpenDir(path As String) As String

Opens a directory for reading. To get a directory listing, first open the directory by calling this method, then call ReadDir to read the directory, and finally call CloseHandle to close the directory.

The SFTP protocol represents file names as strings. File names are assumed to use the slash ('/') character as a directory separator.

File names starting with a slash are "absolute", and are relative to the root of the file system. Names starting with any other character are relative to the user's default directory (home directory). Note that identifying the user is assumed to take place outside of this protocol.

Servers SHOULD interpret a path name component ".." as referring to the parent directory, and "." as referring to the current directory.

An empty path name is valid, and it refers to the user's default directory (usually the user's home directory).

Returns a null on failure

Understanding SFTP Absolute FilePaths

OpenFile(remotePath As String, access As String, createDisposition As String) As String

Opens or creates a file on the remote system. Returns a handle which may be passed to methods for reading and/or writing the file.

access should be one of the following strings: "readOnly", "writeOnly", or "readWrite".

createDisposition is a comma-separated list of keywords to provide more control over how the file is opened or created. One of the following keywords must be present: "createNew", "createTruncate", "openExisting", "openOrCreate", or "truncateExisting". All other keywords are optional. The list of keywords and their meanings are shown here:

createNew
A new file is created; if the file already exists the method fails.

createTruncate
A new file is created; if the file already exists, it is opened and truncated.

openExisting
An existing file is opened. If the file does not exist the method fails.

openOrCreate
If the file exists, it is opened. If the file does not exist, it is created.

truncateExisting
An existing file is opened and truncated. If the file does not exist the method fails.

appendData
Data is always written at the end of the file. Data is not required to be appended atomically. This means that if multiple writers attempt to append data simultaneously, data from the first may be lost.

appendDataAtomic
Data is always written at the end of the file. Data MUST be written atomically so that there is no chance that multiple appenders can collide and result in data being lost.

textMode
Indicates that the server should treat the file as text and convert it to the canonical newline convention in use. When a file is opened with this flag, data is always appended to the end of the file. Servers MUST process multiple, parallel reads and writes correctly in this mode.

blockRead
The server MUST guarantee that no other handle has been opened with read access, and that no other handle will be opened with read access until the client closes the handle. (This MUST apply both to other clients and to other processes on the server.) In a nutshell, this opens the file in non-sharing mode.

blockWrite
The server MUST guarantee that no other handle has been opened with write access, and that no other handle will be opened with write access until the client closes the handle. (This MUST apply both to other clients and to other processes on the server.) In a nutshell, this opens the file in non-sharing mode.

blockDelete
The server MUST guarantee that the file itself is not deleted in any other way until the client closes the handle. No other client or process is allowed to open the file with delete access.

blockAdvisory
If set, the above "block" modes are advisory. In advisory mode, only other accesses that specify a "block" mode need be considered when determining whether the "block" can be granted, and the server need not prevent I/O operations that violate the block mode. The server MAY perform mandatory locking even if the blockAdvisory flag is set.

noFollow
If the final component of the path is a symlink, then the open MUST fail.

deleteOnClose
The file should be deleted when the last handle to it is closed. (The last handle may not be an sftp-handle.) This MAY be emulated by a server if the OS doesn't support it by deleting the file when this handle is closed.

accessAuditAlarmInfo
The client wishes the server to enable any privileges or extra capabilities that the user may have in to allow the reading and writing of AUDIT or ALARM access control entries.

accessBackup
The client wishes the server to enable any privileges or extra capabilities that the user may have in order to bypass normal access checks for the purpose of backing up or restoring files.

backupStream
This flag indicates that the client wishes to read or write a backup stream. A backup stream is a system dependent structured data stream that encodes all the information that must be preserved in order to restore the file from backup medium. The only well defined use for backup stream data read in this fashion is to write it to the same server to a file also opened using the backupStream flag. However, if the server has a well defined backup stream format, there may be other uses for this data outside the scope of this protocol.

IMPORANT: If remotePath is a filename with no path, such as "test.txt", and the server responds with a "Folder not found" error, then try prepending "./" to the remotePath. For example, instead of passing "test.txt", try "./test.txt".

Returns a null on failure

Understanding SFTP Absolute FilePaths

(ASP) SFTP Where Did My Upload Go?

(VB6) SFTP Where Did My Upload Go?

(Delphi) SFTP Where Did My Upload Go?

(FoxPro) SFTP Where Did My Upload Go?

(PHP using ActiveX) SFTP Where Did My Upload Go?

(VBScript) SFTP Where Did My Upload Go?

ReadDir(handle As String) As ChilkatSFtpDir

Reads the contents of a directory and returns the directory listing (as an object). The handle returned by OpenDir should be passed to this method.

ReadFileBytes(handle As String, numBytes As Long) As Variant

Reads file data from a remote file on the SSH server. The handle is a file handle returned by the OpenFile method. The numBytes is the maximum number of bytes to read. If the end-of-file is reached prior to reading the number of requested bytes, then fewer bytes may be returned.

To read an entire file, one may call ReadFileBytes repeatedly until Eof(handle) returns 1.

Returns an empty Variant on failure or EOF. Call Eof(handle) to determine if the end of file was reached.

Returns a zero-length byte array (as a Variant) on failure.
An empty array will have a UBound of -1 meaning 0 elements.

ReadFileBytes32(handle As String, offset As Long, numBytes As Long) As Variant

Reads file data from a remote file on the SSH server. The handle is a file handle returned by the OpenFile method. The offset is measured in bytes relative to the beginning of the file. (64-bit offsets are supported via the ReadFileBytes64 and ReadFileBytes64s methods.) The offset is ignored if the "textMode" flag was specified during the OpenFile. The numBytes is the maximum number of bytes to read. If the end-of-file is reached prior to reading the number of requested bytes, then fewer bytes may be returned.

Returns an empty Variant on failure or EOF. Call Eof(handle) to determine if the end of file was reached.

Returns a zero-length byte array (as a Variant) on failure.
An empty array will have a UBound of -1 meaning 0 elements.

ReadFileBytes64s(handle As String, offset As String, numBytes As Long) As Variant

(This method exists for systems that do not support 64-bit integers. The 64-bit integer offset is passed as a decimal string instead.)

Reads file data from a remote file on the SSH server. The handle is a file handle returned by the OpenFile method. The offset is a 64-bit integer represented as a decimal string. It represents an offset in bytes from the beginning of the file. The offset is ignored if the "textMode" flag was specified during the OpenFile. The numBytes is the maximum number of bytes to read. If the end-of-file is reached prior to reading the number of requested bytes, then fewer bytes may be returned.

Returns an empty Variant on failure or EOF. Call Eof(handle) to determine if the end of file was reached.

Returns a zero-length byte array (as a Variant) on failure.
An empty array will have a UBound of -1 meaning 0 elements.

ReadFileText(handle As String, numBytes As Long, charset As String) As String

This method is identical to ReadFileBytes except for one thing: The bytes are interpreted according to the specified charset (i.e. the character encoding) and returned as a string. A list of supported charset values may be found on this page: Supported Charsets.

Note: If the charset is an encoding where a single character might be represented in multiple bytes (such as utf-8, Shift_JIS, etc.) then there is a risk that the very last character may be partially read. This is because the method specifies the number of bytes to read, not the number of characters. This is never a problem with character encodings that use a single byte per character, such as all of the iso-8859-* encodings, or the Windows-* encodings.

To read an entire file, one may call ReadFileText repeatedly until Eof(handle) returns 1.

Returns a null on failure

ReadFileText32(handle As String, offset As Long, numBytes As Long, charset As String) As String

This method is identical to ReadFileBytes32 except for one thing: The bytes are interpreted according to the specified charset (i.e. the character encoding) and returned as a string. A list of supported charset values may be found on this page: Supported Charsets.

Note: If the charset is an encoding where a single character might be represented in multiple bytes (such as utf-8, Shift_JIS, etc.) then there is a risk that the very last character may be partially read. This is because the method specifies the number of bytes to read, not the number of characters. This is never a problem with character encodings that use a single byte per character, such as all of the iso-8859-* encodings, or the Windows-* encodings.

Returns a null on failure

ReadFileText64s(handle As String, offset As String, numBytes As Long, charset As String) As String

This method is identical to ReadFileBytes64s except for one thing: The bytes are interpreted according to the specified charset (i.e. the character encoding) and returned as a string. A list of supported charset values may be found on this page: Supported Charsets.

Note: If the charset is an encoding where a single character might be represented in multiple bytes (such as utf-8, Shift_JIS, etc.) then there is a risk that the very last character may be partially read. This is because the method specifies the number of bytes to read, not the number of characters. This is never a problem with character encodings that use a single byte per character, such as all of the iso-8859-* encodings, or the Windows-* encodings.

Returns a null on failure

RealPath(originalPath As String, composePath As String) As String

This method can be used to have the server canonicalize any given path name to an absolute path. This is useful for converting path names containing ".." components or relative pathnames without a leading slash into absolute paths. The absolute path is returned by this method.

originalPath is the first component of the path which the client wishes resolved into a absolute canonical path. This may be the entire path.

The composePath is a path which the client wishes the server to compose with the original path to form the new path. This field is optional and may be set to a zero-length string.

The server will take the originalPath and apply the composePath as a modification to it. composePath may be relative to originalPath or may be an absolute path, in which case originalPath will be discarded. The composePath may be zero length.

Note: Servers running SFTP v4 and below do not support composePath.

Returns a null on failure

RemoveDir(path As String) As Long

Deletes a directory on the remote server. Most (if not all) SFTP servers require that the directorybe empty of files before it may be deleted.

Returns 1 for success, 0 for failure.

RemoveFile(filename As String) As Long

Deletes a file on the SFTP server.

Returns 1 for success, 0 for failure.

Understanding SFTP Absolute FilePaths

RenameFileOrDir(oldPath As String, newPath As String) As Long

Renames a file or directory on the SFTP server.

Returns 1 for success, 0 for failure.

ResumeDownloadFileByName(remoteFilePath As String, localFilePath As String) As Long

Resumes an SFTP download. The size of the localFilePath is checked and the download begins at the appropriate position in the remoteFilePath. If localFilePath is empty or non-existent, then this method is identical to DownloadFileByName. If the localFilePath is already fully downloaded, then no additional data is downloaded and the method will return 1.

Returns 1 for success, 0 for failure.

(ASP) SFTP Resume Download Example

(VB6) SFTP Resume Download Example

(Delphi) SFTP Resume Download Example

(FoxPro) SFTP Resume Download Example

(PHP using ActiveX) SFTP Resume Download Example

(VBScript) SFTP Resume Download Example

ResumeUploadFileByName(remoteFilePath As String, localFilePath As String) As Long

Resumes a file upload to the SFTP/SSH server. The size of the remoteFilePath is first checked to determine the starting offset for the upload. If remoteFilePath is empty or does not exist, this method is equivalent to UploadFileByName. If remoteFilePath is already fully uploaded (i.e. it's size is equal to localFilePath), then no additional bytes are uploaded and 1 is returned.

Returns 1 for success, 0 for failure.

(ASP) SFTP Resume Upload Example

(VB6) SFTP Resume Upload Example

(Delphi) SFTP Resume Upload Example

(FoxPro) SFTP Resume Upload Example

(PHP using ActiveX) SFTP Resume Upload Example

(VBScript) SFTP Resume Upload Example

SaveLastError(logFilename As String) As Long

Saves the last error information to an XML formatted file.

SetCreateTime(pathOrHandle As String, isHandle As Long, createDateTime As Date) As Long

Sets the create date/time for a file on the server. The pathOrHandle may be a filepath or the handle of a currently open file. isHandle should be set to 1 if the pathOrHandle is a handle, otherwise set isHandle to 0.

Note: Servers running version 3 or lower of the SFTP protocol do not support setting the create date/time.

Returns 1 for success, 0 for failure.

SetLastAccessTime(pathOrHandle As String, isHandle As Long, accessDateTime As Date) As Long

Sets the last-access date/time for a file on the server. The pathOrHandle may be a filepath or the handle of a currently open file. isHandle should be set to 1 if the pathOrHandle is a handle, otherwise set isHandle to 0.

Returns 1 for success, 0 for failure.

SetLastModifiedTime(pathOrHandle As String, isHandle As Long, modifiedDateTime As Date) As Long

Sets the last-modified date/time for a file on the server. The pathOrHandle may be a filepath or the handle of a currently open file. isHandle should be set to 1 if the pathOrHandle is a handle, otherwise set isHandle to 0.

Returns 1 for success, 0 for failure.

SetOwnerAndGroup(pathOrHandle As String, isHandle As Long, owner As String, group As String) As Long

Sets the owner and group for a file on the server. The pathOrHandle may be a filepath or the handle of a currently open file. isHandle should be set to 1 if the pathOrHandle is a handle, otherwise set isHandle to 0.

Note: Servers running version 3 or lower of the SFTP protocol do not support setting the owner and group.

Returns 1 for success, 0 for failure.

SetPermissions(pathOrHandle As String, isHandle As Long, permissions As Long) As Long

Sets the permissions for a file on the server. The pathOrHandle may be a filepath or the handle of a currently open file. isHandle should be set to 1 if the pathOrHandle is a handle, otherwise set isHandle to 0.

Returns 1 for success, 0 for failure.

UnlockComponent(unlockCode As String) As Long

Unlocks the component. This must be called once prior to calling any other method. A fully-functional 30-day trial is automatically started when an arbitrary string is passed to this method. For example, passing "Hello", or "abc123" will unlock the component for the 1st thirty days after the initial install.

A permanent unlock code for SFTP should contain the substring "SSH" because SFTP is the Secure File Transfer protocol over SSH. It is a sub-system of the SSH protocol. It is not the FTP protocol. If the Chilkat FTP2 component/library should be used for the FTP protocol.

Returns 1 for success, 0 for failure.

Diagnosing UnlockComponent Problems

UnlockComponent LastErrorText shows exact string passed to it.

Verify UnlockComponent Success w/ Permanent Unlock Code

LastErrorText Standard Information

How UnlockComponent Works

UploadFile(handle As String, fromFilename As String) As Long

Uploads a file from the local filesystem to the SFTP server. handle is a handle of a currently open file (obtained by calling the OpenFile method).

Returns 1 for success, 0 for failure.

UploadFileByName(remoteFilePath As String, localFilePath As String) As Long

Simplified method for uploading a file to the SFTP/SSH server.

Returns 1 for success, 0 for failure.

(ASP) SFTP Simplified Upload Example

(VB6) SFTP Simplified Upload Example

(Delphi) SFTP Simplified Upload Example

(FoxPro) SFTP Simplified Upload Example

(PHP using ActiveX) SFTP Simplified Upload Example

(VBScript) SFTP Simplified Upload Example

WriteFileBytes(handle As String, byteData As Variant) As Long

Appends byte data to an open file. The handle is a file handle returned by the OpenFile method.

Returns 1 for success, 0 for failure.

WriteFileBytes32(handle As String, offset As Long, data As Variant) As Long

Writes data to an open file at a specific offset from the beginning of the file. The handle is a file handle returned by the OpenFile method. The offset is an offset from the beginning of the file.

Returns 1 for success, 0 for failure.

WriteFileBytes64s(handle As String, offset64 As String, data As Variant) As Long

Writes data to an open file at a specific offset from the beginning of the file. The handle is a file handle returned by the OpenFile method. The offset64 is an offset (in decimal string format) from the beginning of the file.

Returns 1 for success, 0 for failure.

WriteFileText(handle As String, charset As String, textData As String) As Long

Appends character data to an open file. The handle is a file handle returned by the OpenFile method. charset is a character encoding and is typically set to values such as "ansi", "utf-8", "windows-1252", etc. A list of supported character encodings is found on this page: Supported Charsets.

Note: It is necessary to specify the character encoding because in many programming languages, strings are represented as Unicode (2 bytes/char) and in most cases one does not wish to write Unicode chars to a text file (although it is possible by setting charset = "Unicode").

Returns 1 for success, 0 for failure.

WriteFileText32(handle As String, offset32 As Long, charset As String, textData As String) As Long

Writes character data to an open file at a specific offset from the beginning of the file. The handle is a file handle returned by the OpenFile method. charset is a character encoding and is typically set to values such as "ansi", "utf-8", "windows-1252", etc. A list of supported character encodings is found on this page: Supported Charsets.

Returns 1 for success, 0 for failure.

WriteFileText64s(handle As String, offset64 As String, charset As String, textData As String) As Long

Writes character data to an open file at a specific offset from the beginning of the file. The handle is a file handle returned by the OpenFile method. The offset64 is an offset (in decimal string format) from the beginning of the file. charset is a character encoding and is typically set to values such as "ansi", "utf-8", "windows-1252", etc. A list of supported character encodings is found on this page: Supported Charsets.

Returns 1 for success, 0 for failure.