Chilkat VB.NET SFtp Class Reference

SFtp

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

Object Creation

(C#)
Chilkat.SFtp obj = new Chilkat.SFtp();
(VB.NET)
Dim obj As New Chilkat.SFtp()

Properties

AccumulateBuffer As Byte() (ReadOnly)

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.)

ConnectTimeoutMs As Integer

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

DisconnectCode As Integer (ReadOnly)

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 (ReadOnly)

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 Boolean

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.

EnableEvents As Boolean

This property must be set to true to enable events. By default, it is false.

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.

ForceV3 As Boolean

If set to true, 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 false.

HeartbeatMs As Integer

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.

HeartbeatMs and the AbortCheck Event

HostKeyFingerprint As String (ReadOnly)

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 Integer

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 Integer

Causes SFTP operations to fail when progress for sending or receiving data halts for more than this number of milliseconds. Setting IdleTimeoutMs = 0 (the default) allows the application to wait indefinitely.

InitializeFailCode As Integer (ReadOnly)

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 (ReadOnly)

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 Boolean (ReadOnly)

Returns true 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 Boolean

Controls whether communications to/from the SFTP server are saved to the SessionLog property. The default value is false. If this property is set to true, 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 (ReadOnly)

Error information in HTML format for the last method called.

LastErrorText As String (ReadOnly)

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

LastErrorXml As String (ReadOnly)

Error information in XML format for the last method called.

MaxPacketSize As Integer

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

PreserveDate As Boolean

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

ProtocolVersion As Integer (ReadOnly)

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 (ReadOnly)

Contains a log of the messages sent to/from the SFTP server. To enable session logging, set the KeepSessionLog property = true. 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 Integer

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 Integer

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 Boolean

To be documented soon...

UtcMode As Boolean

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

VerboseLogging As Boolean

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

Version As String (ReadOnly)

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

Methods

Function AccumulateBytes(ByVal handle As String, ByVal maxBytes As Integer) As Integer

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.

Function Add64(ByVal n1 As String, ByVal 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 Nothing on failure

Function AuthenticatePk(ByVal username As String, ByVal privateKey As SshKey) As Boolean

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 true for success, false for failure.

Function AuthenticatePw(ByVal login As String, ByVal password As String) As Boolean

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.

Returns true for success, false for failure.

Sub ClearAccumulateBuffer()

Clears the contents of the AccumulateBuffer property.

Sub ClearCache()

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

Sub ClearSessionLog()

Clears the contents of the SessionLog property.

Function CloseHandle(ByVal handle As String) As Boolean

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

Returns true for success, false for failure.

Function Connect(ByVal hostname As String, ByVal port As Integer) As Boolean

Connects to an SSH/SFTP server. The hostname may be a hostname or an IP address (example: 192.168.1.10). 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 true for success, false for failure.

Function CopyFileAttr(ByVal localFilename As String, ByVal remoteFilename As String, ByVal isHandle As Boolean) As Boolean

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 true for success, false for failure.

Function CreateDir(ByVal path As String) As Boolean

Creates a directory on the SFTP server.

Returns true for success, false for failure.

Sub Disconnect()

Disconnects from the SSH server.

Function DownloadFile(ByVal handle As String, ByVal toFilename As String) As Boolean

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 true for success, false for failure.

Function DownloadFileByName(ByVal remoteFilePath As String, ByVal localFilePath As String) As Boolean

Simplified method for downloading files.

Returns true for success, false for failure.

Understanding SFTP Absolute FilePaths

Function Eof(ByVal handle As String) As Boolean

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

Function GetFileCreateTime(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) 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 true, otherwise it should be false. If bFollowLinks is true, 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.

Function GetFileGroup(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) 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 true, otherwise it should be false. If bFollowLinks is true, 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 Nothing on failure

Function GetFileLastAccess(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) 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 true, otherwise it should be false. If bFollowLinks is true, then symbolic links will be followed on the server.

Function GetFileLastModified(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) 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 true, otherwise it should be false. If bFollowLinks is true, then symbolic links will be followed on the server.

Function GetFileOwner(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) 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 true, otherwise it should be false. If bFollowLinks is true, 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 Nothing on failure

Function GetFilePermissions(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) As Integer

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 true, otherwise it should be false. If bFollowLinks is true, then symbolic links will be followed on the server.

Function GetFileSize32(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) As Integer

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 true, otherwise it should be false. If bFollowLinks is true, then symbolic links will be followed on the server.

Function GetFileSize64(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) As Int64

Returns a 64-bit integer containing the size (in bytes) 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 true, otherwise it should be false. If bFollowLinks is true, then symbolic links will be followed on the server.

Function GetFileSizeStr(ByVal filenameOrHandle As String, ByVal bFollowLinks As Boolean, ByVal bIsHandle As Boolean) 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 true, otherwise it should be false. If bFollowLinks is true, 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 Nothing on failure

Function InitializeSftp() As Boolean

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).

Returns true for success, false for failure.

Error Explained: Received FAILURE response to subsystem request.

Function LastReadFailed(ByVal handle As String) As Boolean

Returns true if the last read on the specified handle failed. Otherwise returns false.

Function LastReadNumBytes(ByVal handle As String) As Integer

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

Function OpenDir(ByVal 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 Nothing on failure

Understanding SFTP Absolute FilePaths

Function OpenFile(ByVal filename As String, ByVal access As String, ByVal 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.

Returns Nothing on failure

Understanding SFTP Absolute FilePaths

SFTP Where Did My Upload Go?

Function ReadDir(ByVal handle As String) As SFtpDir

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.

Function ReadFileBytes(ByVal handle As String, ByVal numBytes As Integer) As Byte()

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 true.

Returns a null reference on failure.

Returns Nothing on failure

Function ReadFileBytes32(ByVal handle As String, ByVal offset As Integer, ByVal numBytes As Integer) As Byte()

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 a null reference on failure.

Returns Nothing on failure

Function ReadFileBytes64(ByVal handle As String, ByVal offset As Int64, ByVal numBytes As Integer) As Byte()

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 measured in bytes relative to 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 a null reference on failure.

Returns Nothing on failure

Function ReadFileBytes64s(ByVal handle As String, ByVal offset As String, ByVal numBytes As Integer) As Byte()

(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 a null reference on failure.

Returns Nothing on failure

Function ReadFileText(ByVal handle As String, ByVal numBytes As Integer, ByVal 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 true.

Returns Nothing on failure

Function ReadFileText32(ByVal handle As String, ByVal offset As Integer, ByVal numBytes As Integer, ByVal 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 Nothing on failure

Function ReadFileText64(ByVal handle As String, ByVal offset As Int64, ByVal numBytes As Integer, ByVal charset As String) As String

This method is identical to ReadFileBytes64 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 Nothing on failure

Function ReadFileText64s(ByVal handle As String, ByVal offset As String, ByVal numBytes As Integer, ByVal 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 Nothing on failure

Function RealPath(ByVal originalPath As String, ByVal 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 Nothing on failure

Function RemoveDir(ByVal path As String) As Boolean

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 true for success, false for failure.

Function RemoveFile(ByVal filename As String) As Boolean

Deletes a file on the SFTP server.

Returns true for success, false for failure.

Understanding SFTP Absolute FilePaths

Function RenameFileOrDir(ByVal oldPath As String, ByVal newPath As String) As Boolean

Renames a file or directory on the SFTP server.

Returns true for success, false for failure.

Function ResumeDownloadFileByName(ByVal remoteFilePath As String, ByVal localFilePath As String) As Boolean

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 true.

Returns true for success, false for failure.

SFTP Resume Download Example

Function ResumeUploadFileByName(ByVal remoteFilePath As String, ByVal localFilePath As String) As Boolean

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 true is returned.

Returns true for success, false for failure.

SFTP Resume Upload Example

Function SaveLastError(ByVal filename As String) As Boolean

Saves the last error information to an XML formatted file.

Function SetCreateTime(ByVal pathOrHandle As String, ByVal isHandle As Boolean, ByVal createDateTime As Date) As Boolean

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 true if the pathOrHandle is a handle, otherwise set isHandle to false.

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

Returns true for success, false for failure.

Function SetLastAccessTime(ByVal pathOrHandle As String, ByVal isHandle As Boolean, ByVal accessDateTime As Date) As Boolean

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 true if the pathOrHandle is a handle, otherwise set isHandle to false.

Returns true for success, false for failure.

Function SetLastModifiedTime(ByVal pathOrHandle As String, ByVal isHandle As Boolean, ByVal modifiedDateTime As Date) As Boolean

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 true if the pathOrHandle is a handle, otherwise set isHandle to false.

Returns true for success, false for failure.

Function SetOwnerAndGroup(ByVal pathOrHandle As String, ByVal isHandle As Boolean, ByVal owner As String, ByVal group As String) As Boolean

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 true if the pathOrHandle is a handle, otherwise set isHandle to false.

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

Returns true for success, false for failure.

Function SetPermissions(ByVal pathOrHandle As String, ByVal isHandle As Boolean, ByVal permissions As Integer) As Boolean

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 true if the pathOrHandle is a handle, otherwise set isHandle to false.

Returns true for success, false for failure.

Function UnlockComponent(ByVal unlockCode As String) As Boolean

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.

Returns true for success, false for failure.

Function UploadFile(ByVal handle As String, ByVal fromFilename As String) As Boolean

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 true for success, false for failure.

Function UploadFileByName(ByVal remoteFilePath As String, ByVal localFilePath As String) As Boolean

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

Returns true for success, false for failure.

SFTP Simplified Upload Example

Function WriteFileBytes(ByVal handle As String, ByVal byteData As Byte()) As Boolean

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

Returns true for success, false for failure.

Function WriteFileBytes32(ByVal handle As String, ByVal offset As Integer, ByVal data As Byte()) As Boolean

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 true for success, false for failure.

Function WriteFileBytes64(ByVal handle As String, ByVal offset64 As Int64, ByVal data As Byte()) As Boolean

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 from the beginning of the file.

Returns true for success, false for failure.

Function WriteFileBytes64s(ByVal handle As String, ByVal offset64 As String, ByVal data As Byte()) As Boolean

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 true for success, false for failure.

Function WriteFileText(ByVal handle As String, ByVal charset As String, ByVal textData As String) As Boolean

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 true for success, false for failure.

Function WriteFileText32(ByVal handle As String, ByVal offset32 As Integer, ByVal charset As String, ByVal textData As String) As Boolean

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 true for success, false for failure.

Function WriteFileText64(ByVal handle As String, ByVal offset64 As Int64, ByVal charset As String, ByVal textData As String) As Boolean

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 true for success, false for failure.

Function WriteFileText64s(ByVal handle As String, ByVal offset64 As String, ByVal charset As String, ByVal textData As String) As Boolean

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 true for success, false for failure.