SSHPlex Class
Properties Methods Events Config Settings Errors
SSHPlex is a multiplexed class that operates over a single Secure Shell (SSH) connection and allows file transfers using Secure File Transfer Protocol (SFTP) or Secure Copy Protocol (SCP). It can remotely execute commands using SExec or SShell.
Syntax
ipworksssh.SSHPlex
Remarks
The SSHPlex class combines the functionality of the Secure Copy Protocol (SCP) class, the Secure File Transfer Protocol (SFTP) class, the SExec class, and the SShell class. All operations are performed over a single Secure Shell (SSH) connection.
The asynchronous design of the class allows multiple operations to be performed simultaneously. For example, several SFTP file transfers may be started, and while the files are still transferring, commands may be executed over SExec. This is accomplished through the use of operation Ids to track ongoing and complete operations, and ChannelType, which allows switching between SFTP, SCP, SExec, and SShell usage.
After establishing a connection, set ChannelType to the desired protocol and set any relevant properties for the operation. Calling the desired method will return an operation Id (string) that identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection.
When the operation completes, a corresponding event will fire indicating the success or failure of the operation. Examine the event parameters for further details. For instance, after calling Upload, the UploadComplete event will fire.
Ongoing operations may be canceled at any time by passing the operation Id to the CancelOperation method.
Note: The DoEvents method must be called frequently to process outstanding events. This is particularly important for SCP and SFTP operations. Call DoEvents in a loop for best results.
Authentication
The SSHHost and SSHPort properties specify which Secure Shell (SSH) server to use. The SSHUser and SSHPassword properties allow the client to authenticate itself with the server. The SSHServerAuthentication event or SSHAcceptServerHostKey property allow you to check the server identity. Finally, the SSHStatus event provides information about the SSH handshake.Example. Logging On:
SSHPlexControl.SSHUser = "username"
SSHPlexControl.SSHPassword = "password"
SSHPlexControl.SSHLogon("sshHost", sshPort)
Channel Types
The ChannelType property determines the protocol used by the component and therefore the applicable methods and properties for each channel. Valid values are:ChannelType | Description | Applicable Methods | Applicable Properties |
0 (cstSShell - default) | An interactive shell for command execution | ||
1 (cstSExec) | Command execution using SExec | ||
2 (cstScp) | SCP File Transfer |
| |
3 (cstSftp) | SFTP File Transfer |
|
Note that CancelOperation and other methods not explicitly listed above are applicable to all channel types.
Listing Files and Folders
ListDirectory lists files and folders from the path specified by RemotePath.
The directory entries are provided through the DirList event and also via the DirList property.
SSHPlexControl.RemoteFile = ""; //Clear filemask
SSHPlexControl.RemotePath = "MyFolder";
string opId = SSHPlexControl.ListDirectory();
// ListDirectory operates async so we must wait for it to finish
while (SSHPlexControl.Operations.Keys.Contains(opId)) {
SSHPlexControl.DoEvents();
}
for (int i = 0; i < SSHPlexControl.DirList.Count; i++)
{
Console.WriteLine(SSHPlexControl.DirList[i].FileName);
Console.WriteLine(SSHPlexControl.DirList[i].FileSize);
Console.WriteLine(SSHPlexControl.DirList[i].FileTime);
Console.WriteLine(SSHPlexControl.DirList[i].IsDir);
}
The RemoteFile property may also be used as a filemask when listing files. For instance:
SSHPlexControl.RemoteFile = "*.txt";
SSHPlexControl.ListDirectory();
Note: Since RemoteFile is used as a filemask be sure to clear or reset this value before calling ListDirectory
Downloading Files
The Download method downloads a specific file.
Set RemoteFile to the name of the file to download before calling this method. If RemoteFile only specifies a filename it will be downloaded from the path specified by RemotePath. RemoteFile may also be set to an absolute path.
The file will be downloaded to the stream specified (if any) by SetDownloadStream. If a stream is not specified and LocalFile is set the file will be saved to the specified location.
Code Example
SSHPlexControl.Localfile = "C:\localfile.txt";
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Download();
// Use Path in RemoteFile
SSHPlexControl.Localfile = "C:\localfile2.txt";
SSHPlexControl.RemoteFile = "folder/remotefile2.txt";
string operationId = SSHPlexControl.Download();
Resuming Downloads
The class also supports resuming failed downloads by using the StartByte property. If a download is interrupted or canceled, set StartByte to the appropriate offset before calling this method to resume the download.
string localFile = "C:\localfile.txt";
SSHPlexControl.Localfile = localFile;
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Download();
// Cancel Download using the CancelOperation method
SSHPlexControl.CancelOperation(operationId);
// Get the size of the partially downloaded temp file and set StartByte
SSHPlexControl.StartByte = new FileInfo(localFile).Length;
// Resume download
string operationId = SSHPlexControl.Download();
Uploading Files
The Upload method is used to upload files. Set LocalFile to the name of the file to upload before calling this method. If SetUploadStream is used to set an upload stream the data to upload is taken from the stream instead.
RemoteFile should be set to either a relative or absolute path. If RemoteFile is not an absolute path it will be uploaded relative to RemotePath.
Code Example
SSHPlexControl.Localfile = "C:\localfile.txt";
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Upload();
// Use Path in RemoteFile
SSHPlexControl.Localfile = "C:\localfile2.txt";
SSHPlexControl.RemoteFile = "folder/remotefile2.txt";
string operationId = SSHPlexControl.Upload();
Resuming Uploads
The class also supports resuming failed uploads by using the StartByte property. If an upload is interrupted or canceled, set StartByte to the appropriate offset before calling this method to resume the upload.
string localFile = "C:\localfile.txt";
SSHPlexControl.Localfile = localFile;
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Upload();
// Cancel Upload using the CancelOperation method
SSHPlexControl.CancelOperation(operationId);
// Get the size of the partially uploaded temp file and set StartByte
SSHPlexControl.StartByte = SSHPlexControl.FileAttributes.Size;
// Resume upload
string operationId = SSHPlexControl.Upload();
Remote Execution
Executing commands on a remote host is done by using the cstSExec or cstSShell ChannelType.
To execute a command, simply call the Execute method with the command you wish to execute.
The output of the command is returned through the Stdout event. Errors during command execution (the stderr stream) are given by the Stderr event.
Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
ChannelType | Specifies the Channel Type to be used by the class. |
Connected | Whether the class is connected. |
DirList | Collection of entries resulting in the last directory listing. |
FileAttributes | The attributes of the RemoteFile . |
FilePermissions | The file permissions for the RemoteFile . |
Firewall | A set of properties related to firewall access. |
LocalFile | The path to a local file for upload/download. |
LocalHost | The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
LocalPort | The TCP port in the local host where the class binds. |
Operations | This collection contains all running operations. |
Overwrite | Whether or not the class should overwrite files during transfer. |
RemoteFile | The name of the remote file for uploading, downloading, etc. |
SSHAcceptServerHostKey | Instructs the class to accept the server host key that matches the supplied key. |
SSHAuthMode | The authentication method to be used with the class when calling SSHLogon . |
SSHCert | A certificate to be used for authenticating the SSHUser . |
SSHCompressionAlgorithms | The comma-separated list containing all allowable compression algorithms. |
SSHEncryptionAlgorithms | The comma-separated list containing all allowable encryption algorithms. |
SSHHost | The address of the Secure Shell (SSH) host. |
SSHPassword | The password for Secure Shell (SSH) password-based authentication. |
SSHPort | The port on the Secure Shell (SSH) server where the SSH service is running; by default, 22. |
SSHUser | The username for Secure Shell (SSH) authentication. |
StartByte | The offset in bytes at which to begin the upload or download. |
Timeout | This property includes the timeout for the class. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
Append | Append data from a local file; to a remote file using SFTP. |
CancelOperation | Cancels the operation specified by OperationId . |
ChangeRemotePath | This method changes the current path on the FTP server. |
CheckFileExists | Returns if the file specified by RemoteFile exists on the remote server. |
Config | Sets or retrieves a configuration setting. |
Connect | Connects to the SSH host without logging in. |
CreateFile | Creates a file on the remote server using SFTP. |
DeleteFile | Deletes a file on the remote server using SFTP. |
Disconnect | This method disconnects from the server without first logging off. |
DoEvents | This method processes events from the internal message queue. |
Download | Download a RemoteFile using SFTP or SCP. |
Execute | Execute a specified command on the remote host. |
Interrupt | This method interrupts the current method. |
ListDirectory | List the current directory specified by RemotePath on an server using SFTP. |
MakeDirectory | Creates a directory on the remote server using SFTP. |
QueryFileAttributes | Queries the server for the attributes of RemoteFile . |
QueryRemotePath | This queries the server for the current path. |
RemoveDirectory | Removes a directory on the remote server using SFTP. |
RenameFile | Changes the name of a file on the remote server using SFTP. |
SendCommand | Sends the specified command to the remote host. |
SendStdinBytes | This method sends binary data to the remote host. |
SendStdinText | This method sends text to the remote host. |
SetDownloadStream | Sets the stream to which the downloaded data from the server will be written. |
SetUploadStream | Sets the stream from which the class will read data to upload to the server. |
SSHLogoff | Logoff from the SSH server. |
SSHLogon | Logon to the SSHHost using the current SSHUser and SSHPassword . |
UpdateFileAttributes | Instructs the class to send the FileAttributes to the server using SFTP. |
Upload | Upload a file specified by LocalFile using SCP or SFTP. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
AppendComplete | Fired when an Append operation completes. |
Connected | Fired immediately after a connection completes (or fails). |
ConnectionStatus | Fired to indicate changes in the connection state. |
CreateFileComplete | Fired when a CreateFile operation completes (or fails). |
DeleteFileComplete | Fired when a DeleteFile operation completes (or fails). |
DirList | Fired when a directory entry is received. |
Disconnected | Fired when a connection is closed. |
DownloadComplete | Fired when a Download operation completes (or fails). |
EndTransfer | Fired when a file completes downloading/uploading. |
Error | Information about errors during data delivery. |
ExecuteComplete | Fired when an Execute operation completes (or fails). |
ListDirectoryComplete | Fired when a ListDirectory operation completes (or fails). |
Log | Fired once for each log message. |
MakeDirectoryComplete | Fired when a MakeDirectory operation completes (or fails). |
RemoveDirectoryComplete | Fired when a RemoveDirectory operation completes (or fails). |
RenameFileComplete | Fired when a RenameFile operation completes (or fails). |
SSHCustomAuth | Fired when the class is doing a custom authentication. |
SSHKeyboardInteractive | Fired when the class receives a request for user input from the server. |
SSHServerAuthentication | Fired after the server presents its public key to the client. |
SSHStatus | Fired to track the progress of the secure connection. |
StartTransfer | Fired when a file starts downloading/uploading. |
Stderr | Fired when data (complete lines) come in through stderr. |
Stdout | Fired when data (complete lines) come in through stdout. |
Transfer | Fired during file download/upload. |
UpdateFileAttributesComplete | Fired when a UpdateFileAttributes operation completes (or fails). |
UploadComplete | Fired when an Upload operation completes (or fails). |
Config Settings
The following is a list of config settings for the class with short descriptions. Click on the links for further details.
AllowBackslashInName | Whether backslashes are allowed in folder and file names. |
AsyncTransfer | Controls whether simultatenous requests are made to read or write files. |
AttrAccessTime | Can be queried for the AccessTime file attribute during the DirList event. |
AttrCreationTime | Can be queried for the CreationTime file attribute during the DirList event. |
AttrFileType | Can be queried for the FileType file attribute during the DirList event. |
AttrGroupId | Can be queried for the GroupId file attribute during the DirList event. |
AttrLinkCount | Can be queried for the LinkCount file attribute during the DirList event. |
AttrOwnerId | Can be queried for the OwnerId file attribute during the DirList event. |
AttrPermission | Can be queried for the Permissions file attribute during the DirList event. |
CheckFileHash | Compares a server-computed hash with a hash calculated locally. |
CopyRemoteData | Copies a specified range of bytes in one file to another. |
CopyRemoteFile | Copies a file from one location to another directly on the server. |
DisableRealPath | Controls whether or not the SSH_FXP_REALPATH request is sent. |
ExcludeFileMask | Specifies a file mask for excluding files in directory listings. |
FileMaskDelimiter | Specifies a delimiter to use for setting multiple file masks in the RemoteFile property. |
FiletimeFormat | Specifies the format to use when returning filetime strings. |
FreeSpace | The free space on the remote server in bytes. |
GetSpaceInfo | Queries the server for drive usage information. |
GetSymlinkAttrs | Whether to get the attributes of the symbolic link, or the resource pointed to by the link. |
IgnoreFileMaskCasing | Controls whether or not the file mask is case sensitive. |
LocalEOL | When TransferMode is set, this specifies the line ending for the local system. |
LogSFTPFileData | Whether SFTP file data is present in Debug logs. |
MaskSensitiveData | Masks passwords in logs. |
MaxFileData | Specifies the maximum payload size of an SFTP packet. |
MaxOutstandingPackets | Sets the maximum number of simultaneous read or write requests allowed. |
NegotiatedProtocolVersion | The negotiated SFTP version. |
NormalizeRemotePath | Whether to normalize the RemotePath. |
PreserveFileTime | Preserves the file's timestamps during transfer. |
ProtocolVersion | The highest allowable SFTP version to use. |
ReadLink | This settings returns the target of a specified symbolic link. |
RealPathControlFlag | Specifies the control-byte field sent in the SSH_FXP_REALPATH request. |
RealTimeUpload | Enables real time uploading. |
RealTimeUploadAgeLimit | The age limit in seconds when using RealTimeUpload. |
ServerEOL | When TransferMode is set, this specifies the line ending for the remote system. |
SimultaneousTransferLimit | The maximum number of simultaneous file transfers. |
TotalSpace | The total space on the remote server in bytes. |
TransferMode | The transfer mode (ASCII or Binary). |
TransferredDataLimit | Specifies the maximum number of bytes to download from the remote file. |
UseFxpStat | Whether SSH_FXP_STAT is sent. |
DirectoryPermissions | The permissions of folders created on the remote host. |
LastAccessedTime | The last accessed time of the remote file. |
LastModifiedTime | The last modified time of the remote file. |
PreserveFileTime | Preserves the file's modified time during transfer. |
RecursiveMode | If set to true the class will recursively upload or download files. |
ServerResponseWindow | The time to wait for a server response in milliseconds. |
DisconnectOnChannelClose | Whether to automatically close the connection when a channel is closed. |
EncodedTerminalModes | The terminal mode to set when communicating with the SSH host. |
FallbackKeyboardAuth | Whether to attempt keyboard authorization after another authorization method has failed. |
ShellPrompt | The character sequence of the prompt on the SSH host to wait for. |
StdInFile | The file to use as Stdin data. |
StripANSI | Whether to remove ANSI escape sequences. |
TerminalHeight | The height of the terminal display. |
TerminalModes | The terminal mode to set when communicating with the SSH host. |
TerminalType | The terminal type the class will use when connecting to a server. |
TerminalUsePixel | Whether the terminal's dimensions are in columns/rows or pixels. |
TerminalWidth | The width of the terminal display. |
UpdateTerminalSize | Used to update the terminal size. |
DisconnectOnChannelClose | Whether to automatically close the connection when a channel is closed. |
EncodedTerminalModes | The terminal mode to set when communicating with the SSH host. |
StdInFile | The file to use as Stdin data. |
TerminalHeight | The height of the terminal display. |
TerminalModes | The terminal mode to set when communicating with the SSH host. |
TerminalUsePixel | Whether the terminal's dimensions are in columns/rows or pixels. |
TerminalWidth | The width of the terminal display. |
UseTerminal | Whether to executes commands within a pseudo-terminal. |
ChannelDataEOL[ChannelId] | Used to break the incoming data stream into chunks. |
ChannelDataEOLFound[ChannelId] | Determines if ChannelDataEOL was found. |
ClientSSHVersionString | The SSH version string used by the class. |
DoNotRepeatAuthMethods | Whether the class will repeat authentication methods during multifactor authentication. |
EnablePageantAuth | Whether to use a key stored in Pageant to perform client authentication. |
KerberosDelegation | If true, asks for credentials with delegation enabled during authentication. |
KerberosRealm | The fully qualified domain name of the Kerberos Realm to use for GSSAPI authentication. |
KerberosSPN | The Kerberos Service Principal Name of the SSH host. |
KeyRenegotiationThreshold | Sets the threshold for the SSH Key Renegotiation. |
LogLevel | Specifies the level of detail that is logged. |
MaxChannelDataLength[ChannelId] | The maximum amount of data to accumulate when no ChannelDataEOL is found. |
MaxPacketSize | The maximum packet size of the channel, in bytes. |
MaxWindowSize | The maximum window size allowed for the channel, in bytes. |
NegotiatedStrictKex | Returns whether strict key exchange was negotiated to be used. |
PasswordPrompt | The text of the password prompt used in keyboard-interactive authentication. |
PreferredDHGroupBits | The size (in bits) of the preferred modulus (p) to request from the server. |
RecordLength | The length of received data records. |
ServerSSHVersionString | The remote host's SSH version string. |
SignedSSHCert | The CA signed client public key used when authenticating. |
SSHAcceptAnyServerHostKey | If set the class will accept any key presented by the server. |
SSHAcceptServerCAKey | The CA public key that signed the server's host key. |
SSHAcceptServerHostKeyFingerPrint | The fingerprint of the server key to accept. |
SSHFingerprintHashAlgorithm | The algorithm used to calculate the fingerprint. |
SSHFingerprintMD5 | The server hostkey's MD5 fingerprint. |
SSHFingerprintSHA1 | The server hostkey's SHA1 fingerprint. |
SSHFingerprintSHA256 | The server hostkey's SHA256 fingerprint. |
SSHKeepAliveCountMax | The maximum number of keep alive packets to send without a response. |
SSHKeepAliveInterval | The interval between keep alive packets. |
SSHKeyExchangeAlgorithms | Specifies the supported key exchange algorithms. |
SSHKeyRenegotiate | Causes the class to renegotiate the SSH keys. |
SSHMacAlgorithms | Specifies the supported Mac algorithms. |
SSHPubKeyAuthSigAlgorithms | Specifies the enabled signature algorithms that may be used when attempting public key authentication. |
SSHPublicKeyAlgorithms | Specifies the supported public key algorithms for the server's public key. |
SSHVersionPattern | The pattern used to match the remote host's version string. |
TryAllAvailableAuthMethods | If set to true, the class will try all available authentication methods. |
UseStrictKeyExchange | Specifies how strict key exchange is supported. |
WaitForChannelClose | Whether to wait for channels to be closed before disconnected. |
WaitForServerDisconnect | Whether to wait for the server to close the connection. |
CloseStreamAfterTransfer | If true, the class will close the upload or download stream after the transfer. |
ConnectionTimeout | Sets a separate timeout value for establishing a connection. |
FirewallAutoDetect | Tells the class whether or not to automatically detect and use firewall system settings, if available. |
FirewallHost | Name or IP address of firewall (optional). |
FirewallListener | If true, the class binds to a SOCKS firewall as a server (TCPClient only). |
FirewallPassword | Password to be used if authentication is to be used when connecting through the firewall. |
FirewallPort | The TCP port for the FirewallHost;. |
FirewallType | Determines the type of firewall to connect through. |
FirewallUser | A user name if authentication is to be used connecting through a firewall. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
Linger | When set to True, connections are terminated gracefully. |
LingerTime | Time in seconds to have the connection linger. |
LocalHost | The name of the local host through which connections are initiated or accepted. |
LocalPort | The port in the local host where the class binds. |
MaxLineLength | The maximum amount of data to accumulate when no EOL is found. |
MaxTransferRate | The transfer rate limit in bytes per second. |
ProxyExceptionsList | A semicolon separated list of hosts and IPs to bypass when using a proxy. |
TCPKeepAlive | Determines whether or not the keep alive socket option is enabled. |
TcpNoDelay | Whether or not to delay when sending packets. |
UseIPv6 | Whether to use IPv6. |
UseNTLMv2 | Whether to use NTLM V2. |
AbsoluteTimeout | Determines whether timeouts are inactivity timeouts or absolute timeouts. |
FirewallData | Used to send extra data to the firewall. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
BuildInfo | Information about the product's build. |
GUIAvailable | Whether or not a message loop is available for processing events. |
LicenseInfo | Information about the current license. |
MaskSensitiveData | Whether sensitive data is masked in log messages. |
UseDaemonThreads | Whether threads created by the class are daemon threads. |
UseFIPSCompliantAPI | Tells the class whether or not to use FIPS certified APIs. |
UseInternalSecurityAPI | Whether or not to use the system security libraries or an internal implementation. |
ChannelType Property (SSHPlex Class)
Specifies the Channel Type to be used by the class.
Syntax
public int getChannelType(); public void setChannelType(int channelType); Enumerated values: public final static int cstSShell = 0; public final static int cstSExec = 1; public final static int cstScp = 2; public final static int cstSftp = 3;
Default Value
0
Remarks
The ChannelType property determines the protocol used by the component and therefore the applicable methods and properties for each channel. Valid values are:
ChannelType | Description | Applicable Methods | Applicable Properties |
0 (cstSShell - default) | An interactive shell for command execution | ||
1 (cstSExec) | Command execution using SExec | ||
2 (cstScp) | SCP File Transfer |
| |
3 (cstSftp) | SFTP File Transfer |
|
Note that CancelOperation and other methods not explicitly listed above are applicable to all channel types.
Connected Property (SSHPlex Class)
Whether the class is connected.
Syntax
public boolean isConnected();
Default Value
False
Remarks
This property is used to determine whether or not the class is connected to the remote host. Use the Connect and Disconnect methods to manage the connection.
This property is read-only and not available at design time.
DirList Property (SSHPlex Class)
Collection of entries resulting in the last directory listing.
Syntax
public DirEntryList getDirList();
Remarks
This collection of entries is returned after a response is received from the server after a call to ListDirectory. The collection is made up of entries for each listing in the current directory, which is specified by the RemotePath property.
MaxDirEntries can be used to control the number of directory listings saved.
This collection is indexed from 0 to size -1.
This property is read-only and not available at design time.
Please refer to the DirEntry type for a complete list of fields.FileAttributes Property (SSHPlex Class)
The attributes of the RemoteFile .
Syntax
public SFTPFileAttributes getFileAttributes(); public void setFileAttributes(SFTPFileAttributes fileAttributes);
Remarks
This property holds the attributes for the file specified by RemoteFile. Before querying this property first call QueryFileAttributes to retrieve the attributes from the server.
To modify the attributes of the file, you may set FileAttributes then call UpdateFileAttributes.
This property is not available at design time.
Please refer to the SFTPFileAttributes type for a complete list of fields.FilePermissions Property (SSHPlex Class)
The file permissions for the RemoteFile .
Syntax
public String getFilePermissions(); public void setFilePermissions(String filePermissions);
Default Value
"0600"
Remarks
This property defines the permissions that will be assigned to the RemoteFile after an upload. The value is a four-digit octal value. This is the same format that is used with the Unix chmod command. The default value of "0600" gives read/write permissions to the file's owner.
The last three octal digits are the most significant and represent, in order, the file access capabilities of the file's owner, the owner's group, and other users. Each of these octal digits is, on its own, a 3-bit bitmask with the following possible values:
1 (001) | Execute |
2 (010) | Write |
4 (100) | Read |
An octal permission digit of 7 would have all three values set and would mean that the file can be read, written, and executed by that user class. For example, the octal permissions "100644" would have a value "6" for the owner, "4" for the group, and "4" for other users. This would be interpreted to mean that all users can read the file, no users can execute it, and only the owner can write it. The permissions "40755" would mean that all users can read and execute the file, but only the owner can write it.
The previous octal digit is another bitmask with the following values:
1 (001) | Sticky Bit - retain the file in memory for performance |
2 (010) | Set GID - sets the group Id of the process to the file's group Id upon execution (only for executable files) |
4 (100) | Set UID - sets the user Id of the process to the file's user Id upon execution (only for executable files) |
Note: Not all servers support setting permissions after an upload.
Firewall Property (SSHPlex Class)
A set of properties related to firewall access.
Syntax
public Firewall getFirewall(); public void setFirewall(Firewall firewall);
Remarks
This is a Firewall-type property, which contains fields describing the firewall through which the class will attempt to connect.
Please refer to the Firewall type for a complete list of fields.LocalFile Property (SSHPlex Class)
The path to a local file for upload/download.
Syntax
public String getLocalFile(); public void setLocalFile(String localFile);
Default Value
""
Remarks
The LocalFile property is used by the Upload and Download methods. The file will only be overwritten if the Overwrite property is set to True.
Example (Setting LocalFile)
SSHPlexControl.Localfile = "C:\localfile.txt"
SSHPlexControl.RemoteFile = "remotefile.txt"
string operationId = SSHPlexControl.Download()
SSHPlexControl.Localfile = "C:\localfile2.txt"
SSHPlexControl.RemoteFile = "folder/remotefile2.txt"
string operationId = SSHPlexControl.Download()
LocalHost Property (SSHPlex Class)
The name of the local host or user-assigned IP interface through which connections are initiated or accepted.
Syntax
public String getLocalHost(); public void setLocalHost(String localHost);
Default Value
""
Remarks
This property contains the name of the local host as obtained by the gethostname() system call, or if the user has assigned an IP address, the value of that address.
In multihomed hosts (machines with more than one IP interface) setting LocalHost to the IP address of an interface will make the class initiate connections (or accept in the case of server classs) only through that interface. It is recommended to provide an IP address rather than a hostname when setting this property to ensure the desired interface is used.
If the class is connected, the LocalHost property shows the IP address of the interface through which the connection is made in internet dotted format (aaa.bbb.ccc.ddd). In most cases, this is the address of the local host, except for multihomed hosts (machines with more than one IP interface).
Note: LocalHost is not persistent. You must always set it in code, and never in the property window.
LocalPort Property (SSHPlex Class)
The TCP port in the local host where the class binds.
Syntax
public int getLocalPort(); public void setLocalPort(int localPort);
Default Value
0
Remarks
This property must be set before a connection is attempted. It instructs the class to bind to a specific port (or communication endpoint) in the local machine.
Setting this property to 0 (default) enables the system to choose an open port at random. The chosen port will be returned by the LocalPort property after the connection is established.
LocalPort cannot be changed once a connection is made. Any attempt to set this property when a connection is active will generate an error.
This property is useful when trying to connect to services that require a trusted port on the client side.
Operations Property (SSHPlex Class)
This collection contains all running operations.
Syntax
public SSHPlexOperationMap getOperations();
Remarks
Each SSHPlexOperation in the collection contains information about the currently running operations.
This property is read-only and not available at design time.
Please refer to the SSHPlexOperation type for a complete list of fields.Overwrite Property (SSHPlex Class)
Whether or not the class should overwrite files during transfer.
Syntax
public boolean isOverwrite(); public void setOverwrite(boolean overwrite);
Default Value
False
Remarks
When ChannelType is set to cstSFTP this property is a value indicating whether or not the class should overwrite LocalFile when downloading, and RemoteFile when uploading. If Overwrite is false, an error will be thrown whenever LocalFile exists before a download operation.
When ChannelType is set to cstSCP this property is a value indicating whether or not the class should overwrite LocalFile when downloading. If Overwrite is false, an error will be thrown whenever LocalFile exists before a download operation.
RemoteFile Property (SSHPlex Class)
The name of the remote file for uploading, downloading, etc.
Syntax
public String getRemoteFile(); public void setRemoteFile(String remoteFile);
Default Value
""
Remarks
The RemoteFile is either an absolute file path, or a relative path based on RemotePath.
A number of methods use RemoteFile as an argument.
Example (Setting RemoteFile)
SSHPlexControl.Localfile = "C:\localfile.txt"
SSHPlexControl.RemoteFile = "remotefile.txt"
string operationId = SSHPlexControl.Download()
SSHPlexControl.Localfile = "C:\localfile2.txt"
SSHPlexControl.RemoteFile = "folder/remotefile2.txt"
string operationId = SSHPlexControl.Download()
Note: This property will also act as a file mask when performing ListDirectory.
Example (Using RemoteFile as a file mask):
SSHPlexControl.RemoteFile = "*.txt"
SSHPlexControl.ListDirectory()
The following special characters are supported for pattern matching:
? | Any single character. |
* | Any characters or no characters (e.g., C*t matches Cat, Cot, Coast, Ct). |
[,-] | A range of characters (e.g., [a-z], [a], [0-9], [0-9,a-d,f,r-z]). |
\ | The slash is ignored and exact matching is performed on the next character. |
If these characters need to be used as a literal in a pattern, then they must be escaped by surrounding them with brackets []. Note: "]" and "-" do not need to be escaped. See below for the escape sequences:
Character | Escape Sequence |
? | [?] |
* | [*] |
[ | [[] |
\ | [\] |
For example, to match the value [Something].txt, specify the pattern [[]Something].txt.
SSHAcceptServerHostKey Property (SSHPlex Class)
Instructs the class to accept the server host key that matches the supplied key.
Syntax
public Certificate getSSHAcceptServerHostKey(); public void setSSHAcceptServerHostKey(Certificate SSHAcceptServerHostKey);
Remarks
If the host key that will be used by the server is known in advance, this property may be set to accept the expected key. Otherwise, the SSHServerAuthentication event should be trapped, and the key should be accepted or refused in the event.
If this property is not set and the SSHServerAuthentication event is not trapped, the server will not be authenticated and the connection will be terminated by the client.
Please refer to the Certificate type for a complete list of fields.SSHAuthMode Property (SSHPlex Class)
The authentication method to be used with the class when calling SSHLogon .
Syntax
public int getSSHAuthMode(); public void setSSHAuthMode(int SSHAuthMode); Enumerated values: public final static int amNone = 0; public final static int amMultiFactor = 1; public final static int amPassword = 2; public final static int amPublicKey = 3; public final static int amKeyboardInteractive = 4; public final static int amGSSAPIWithMic = 5; public final static int amGSSAPIKeyex = 6; public final static int amCustom = 99;
Default Value
2
Remarks
The Secure Shell (SSH) Authentication specification (RFC 4252) specifies multiple methods by which a user can be authenticated by an SSH server. When a call is made to SSHLogon, the class will connect to the SSH server and establish the security layer. After the connection has been secured, the client will send an authentication request to the SSHHost containing the SSHUser. The server will respond containing a list of methods by which that user may be authenticated.
The class will attempt to authenticate the user by one of those methods based on the value of SSHAuthMode and other property values supplied by the user. Currently, the class supports the following authentication methods:
amNone (0) | No authentication will be performed. The current SSHUser value is ignored, and the connection will be logged as anonymous. |
amMultiFactor (1) | This allows the class to attempt a multistep authentication process. The class will send authentication data to the server based on the list of methods allowed for the current user and the authentication property values supplied. The class will continue to send authentication data until the server acknowledges authentication success. If the server rejects an authentication step, the class throws an exception. |
amPassword (2) | The class will use the values of SSHUser and SSHPassword to authenticate the user. |
amPublicKey (3) | The class will use the values of SSHUser and SSHCert to authenticate the user. SSHCert must have a private key available for this authentication method to succeed. |
amKeyboardInteractive (4) | At the time of authentication, the class will fire the SSHKeyboardInteractive event containing instructions on how to complete the authentication step.
Note: amKeyboardInteractive is not supported in SSHTunnel. |
amGSSAPIWithMic (5) | This allows the class to attempt Kerberos authentication using the GSSAPI-WITH-MIC scheme. The client will try Kerberos authentication using the value of SSHUser (single sign-on), or if SSHPassword is specified as well, it will try Kerberos authentication with alternate credentials. This is currently supported only on Windows, unless using the Java edition, which also provides support for Linux and macOS. |
amGSSAPIKeyex (6) | This allows the class to attempt Kerberos authentication using the GSSAPIKeyex scheme. The client will try Kerberos authentication using the value of SSHUser (single sign-on), or if SSHPassword is specified as well, it will try Kerberos authentication with alternate credentials. This is currently supported only on Windows, unless using the Java edition, which also provides support for Linux and macOS. |
amCustom (99) | This allows the class caller to take over the authentication process completely. When amCustom is set, the class will fire the SSHCustomAuth event as necessary to complete the authentication process. |
Example 1. User/Password Authentication:
Control.SSHAuthMode = SftpSSHAuthModes.amPassword
Control.SSHUser = "username"
Control.SSHPassword = "password"
Control.SSHLogon("server", 22)
Example 2. Public Key Authentication:
Control.SSHAuthMode = SftpSSHAuthModes.amPublicKey
Control.SSHUser = "username"
Control.SSHCert = New Certificate(CertStoreTypes.cstPFXFile, "cert.pfx", "certpassword", "*")
Control.SSHLogon("server", 22)
SSHCert Property (SSHPlex Class)
A certificate to be used for authenticating the SSHUser .
Syntax
public Certificate getSSHCert(); public void setSSHCert(Certificate SSHCert);
Remarks
To use public key authentication, SSHCert must contain a Certificate with a valid private key. The certificate's public key value is sent to the server along with a signature produced using the private key. The server will first check to see if the public key values match what is known for the user, and then it will attempt to use those values to verify the signature.
Example 1. User/Password Authentication:
Control.SSHAuthMode = SftpSSHAuthModes.amPassword
Control.SSHUser = "username"
Control.SSHPassword = "password"
Control.SSHLogon("server", 22)
Example 2. Public Key Authentication:
Control.SSHAuthMode = SftpSSHAuthModes.amPublicKey
Control.SSHUser = "username"
Control.SSHCert = New Certificate(CertStoreTypes.cstPFXFile, "cert.pfx", "certpassword", "*")
Control.SSHLogon("server", 22)
SSHCompressionAlgorithms Property (SSHPlex Class)
The comma-separated list containing all allowable compression algorithms.
Syntax
public String getSSHCompressionAlgorithms(); public void setSSHCompressionAlgorithms(String SSHCompressionAlgorithms);
Default Value
"none,zlib"
Remarks
During the Secure Shell (SSH) handshake, this list will be used to negotiate the compression algorithm to be used between the client and server. This list is used for both directions: client to server and server to client. When negotiating algorithms, each side sends a list of all algorithms it supports or allows. The algorithm chosen for each direction is the first algorithm to appear in the sender's list that the receiver supports. Therefore, it is important to list multiple algorithms in preferential order. If no algorithm can be agreed on, the class will raise an error and the connection will be aborted.
At least one supported algorithm must appear in this list. The following compression algorithms are supported by the class:
- zlib
- zlib@openssh.com
- none
SSHEncryptionAlgorithms Property (SSHPlex Class)
The comma-separated list containing all allowable encryption algorithms.
Syntax
public String getSSHEncryptionAlgorithms(); public void setSSHEncryptionAlgorithms(String SSHEncryptionAlgorithms);
Default Value
"aes256-ctr,aes192-ctr,aes128-ctr,3des-ctr,arcfour256,arcfour128,arcfour,aes256-gcm@openssh.com,aes128-gcm@openssh.com,chacha20-poly1305@openssh.com"
Remarks
During the Secure Shell (SSH) handshake, this list will be used to negotiate the encryption algorithm to be used between the client and server. This list is used for both directions: client to server and server to client. When negotiating algorithms, each side sends a list of all algorithms it supports or allows. The algorithm chosen for each direction is the first algorithm to appear in the sender's list that the receiver supports. Therefore, it is important to list multiple algorithms in preferential order. If no algorithm can be agreed on, the class will raise an error and the connection will be aborted.
At least one supported algorithm must appear in this list. The following encryption algorithms are supported by the class:
aes256-ctr | 256-bit AES encryption in CTR mode. |
aes256-cbc | 256-bit AES encryption in CBC mode. |
aes192-ctr | 192-bit AES encryption in CTR mode. |
aes192-cbc | 192-bit AES encryption in CBC mode. |
aes128-ctr | 128-bit AES encryption in CTR mode. |
aes128-cbc | 128-bit AES encryption in CBC mode. |
3des-ctr | 192-bit (3-key) triple DES encryption in CTR mode. |
3des-cbc | 192-bit (3-key) triple DES encryption in CBC mode. |
cast128-cbc | CAST-128 encryption. |
blowfish-cbc | Blowfish encryption. |
arcfour | ARC4 encryption. |
arcfour128 | 128-bit ARC4 encryption. |
arcfour256 | 256-bit ARC4 encryption. |
aes256-gcm@openssh.com | 256-bit AES encryption in GCM mode. |
aes128-gcm@openssh.com | 128-bit AES encryption in GCM mode. |
chacha20-poly1305@openssh.com | ChaCha20 with Poly1305-AES encryption. |
SSHHost Property (SSHPlex Class)
The address of the Secure Shell (SSH) host.
Syntax
public String getSSHHost(); public void setSSHHost(String SSHHost);
Default Value
""
Remarks
The SSHHost property specifies the IP address (IP number in dotted internet format) or domain name of the remote host. It is set before a connection is attempted and cannot be changed once a connection is established.
If the SSHHost property is set to a domain name, a DNS request is initiated, and upon successful termination of the request, the SSHHost property is set to the corresponding address. If the search is not successful, an error is returned.
The SSHHost must be the same host that will be assumed for SSH as for the remote service being connected to.
SSHPassword Property (SSHPlex Class)
The password for Secure Shell (SSH) password-based authentication.
Syntax
public String getSSHPassword(); public void setSSHPassword(String SSHPassword);
Default Value
""
Remarks
SSHPassword specifies the password that is used to authenticate the client to the SSH server.
SSHPort Property (SSHPlex Class)
The port on the Secure Shell (SSH) server where the SSH service is running; by default, 22.
Syntax
public int getSSHPort(); public void setSSHPort(int SSHPort);
Default Value
22
Remarks
The SSHPort specifies a service port on the SSH host to connect to.
A valid port number (a value between 1 and 65535) is required for the connection to take place. The property must be set before a connection is attempted and cannot be changed once a connection is established. Any attempt to change this property while connected will fail with an error.
SSHUser Property (SSHPlex Class)
The username for Secure Shell (SSH) authentication.
Syntax
public String getSSHUser(); public void setSSHUser(String SSHUser);
Default Value
""
Remarks
SSHUser specifies the username that is used to authenticate the client to the SSH server. This property is required.
Example 1. User/Password Authentication:
Control.SSHAuthMode = SftpSSHAuthModes.amPassword
Control.SSHUser = "username"
Control.SSHPassword = "password"
Control.SSHLogon("server", 22)
Example 2. Public Key Authentication:
Control.SSHAuthMode = SftpSSHAuthModes.amPublicKey
Control.SSHUser = "username"
Control.SSHCert = New Certificate(CertStoreTypes.cstPFXFile, "cert.pfx", "certpassword", "*")
Control.SSHLogon("server", 22)
StartByte Property (SSHPlex Class)
The offset in bytes at which to begin the upload or download.
Syntax
public long getStartByte(); public void setStartByte(long startByte);
Default Value
0
Remarks
The StartByte property is used by the Upload and Download methods to determine at what offset to begin the transfer. This allows for resuming both uploads and downloads. The value of this property is reset to 0 after a successful transfer. StartByte is not valid for use with Append.
When downloading, this property can be used in conjunction with the TransferredDataLimit configuration setting to download only a specific range of data from the current RemoteFile.
Timeout Property (SSHPlex Class)
This property includes the timeout for the class.
Syntax
public int getTimeout(); public void setTimeout(int timeout);
Default Value
60
Remarks
If the Timeout property is set to 0, all operations will run uninterrupted until successful completion or an error condition is encountered.
If Timeout is set to a positive value, the class will wait for the operation to complete before returning control.
The class will use DoEvents to enter an efficient wait loop during any potential waiting period, making sure that all system events are processed immediately as they arrive. This ensures that the host application does not freeze and remains responsive.
If Timeout expires, and the operation is not yet complete, the class throws an exception.
Note: By default, all timeouts are inactivity timeouts, that is, the timeout period is extended by Timeout seconds when any amount of data is successfully sent or received.
The default value for the Timeout property is 60 seconds.
Append Method (SSHPlex Class)
Append data from a local file; to a remote file using SFTP.
Syntax
public String append();
Remarks
This method Appends the data from LocalFile to the RemoteFile. The StartTransfer, Transfer, and EndTransfer events provide details about the individual file transfers. If the LocalFile property is "" (empty string) then the file data will be available through the Transfer event.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the AppendComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the AppendComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp.
Code Example
SSHPlexControl.Localfile = "C:\localfile.txt";
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Append();
// Use Path in RemoteFile
SSHPlexControl.Localfile = "C:\localfile2.txt";
SSHPlexControl.RemoteFile = "folder/remotefile2.txt";
string operationId = SSHPlexControl.Append();
CancelOperation Method (SSHPlex Class)
Cancels the operation specified by OperationId .
Syntax
public void cancelOperation(String operationId);
Remarks
When this method is called the Error event will fire and the associated operation's completion event will fire.
For example, if CancelOperation is called for an upload that is in progress, both the Error event and the UploadComplete event will fire.
The SSHPlexOperation associated with the OperationId will be removed from the Operations collection.
ChangeRemotePath Method (SSHPlex Class)
This method changes the current path on the FTP server.
Syntax
public void changeRemotePath(String remotePath);
Remarks
This method changes the current path on the FTP server to the specified RemotePath. When called, the class will issue a command to the server to change the directory. The RemotePath parameter may hold an absolute or relative path.
Absolute Paths
If the path begins with a /, it is considered an absolute path and must specify the entire path from the root of the server. For instance:
component.ChangeRemotePath("/home/testuser/myfolder");
Relative Paths
If the path does not begin with a /, it is considered a relative path and is resolved in relation to the current directory. For instance, a value of myfolder will indicate a subfolder of the current directory. The special value .. refers to the parent directory of the current path. For instance:
//Change to the 'myfolder' sub-directory
component.ChangeRemotePath("myfolder");
//Navigate up two levels and then into the 'another/folder' path.
component.ChangeRemotePath("../../another/folder");
CheckFileExists Method (SSHPlex Class)
Returns if the file specified by RemoteFile exists on the remote server.
Syntax
public boolean checkFileExists();
Remarks
This property returns true if the file exists on the remote server. It returns false if the file does not exist. You must specify the file you wish to check by setting the RemoteFile before calling this method.
If no session is in place, the value of this property will always be false.
Config Method (SSHPlex Class)
Sets or retrieves a configuration setting.
Syntax
public String config(String configurationString);
Remarks
Config is a generic method available in every class. It is used to set and retrieve configuration settings for the class.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.
To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.
Connect Method (SSHPlex Class)
Connects to the SSH host without logging in.
Syntax
public void connect();
Remarks
This method establishes a connection with the SSHHost but does not log in. In most cases it is recommended to use the SSHLogon method which will both establish a connection and log in to the server.
This method may be useful in cases where it is desirable to separate the connection and logon operations, for instance confirming a host is available by first creating the connection.
CreateFile Method (SSHPlex Class)
Creates a file on the remote server using SFTP.
Syntax
public String createFile(String fileName);
Remarks
This method creates an empty file on the server with the name specified by the FileName parameter. FileName is either and absolute path on the server, or a path relative to RemotePath.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the CreateFileComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the CreateFileComplete event to determine the result.
To upload a file with content use Upload instead.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp.
DeleteFile Method (SSHPlex Class)
Deletes a file on the remote server using SFTP.
Syntax
public String deleteFile(String fileName);
Remarks
This method deletes a file on the server with the name specified by the FileName parameter. FileName is either and absolute path on the server, or a path relative to RemotePath.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the DeleteFileComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the DeleteFileComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp.
Disconnect Method (SSHPlex Class)
This method disconnects from the server without first logging off.
Syntax
public void disconnect();
Remarks
This method immediately disconnects from the server without first logging off.
In most cases the SSHLogoff method should be used to logoff and disconnect from the server. Call the Disconnect method in cases where it is desirable to immediately disconnect without first logging off.
DoEvents Method (SSHPlex Class)
This method processes events from the internal message queue.
Syntax
public void doEvents();
Remarks
When DoEvents is called, the class processes any available events. If no events are available, it waits for a preset period of time, and then returns.
Download Method (SSHPlex Class)
Download a RemoteFile using SFTP or SCP.
Syntax
public String download();
Remarks
This method downloads the remote file specified by RemoteFile to the local file specified by LocalFile. The StartTransfer, Transfer, and EndTransfer events provide details about the individual file transfers. If the LocalFile property is "" (empty string) then the file data will be available through the Transfer event.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the DownloadComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the DownloadComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp or cstScp.
Set RemoteFile to the name of the file to download before calling this method. If RemoteFile only specifies a filename it will be downloaded from the path specified by RemotePath. RemoteFile may also be set to an absolute path.
The file will be downloaded to the stream specified (if any) by SetDownloadStream. If a stream is not specified and LocalFile is set the file will be saved to the specified location.
Code Example
SSHPlexControl.Localfile = "C:\localfile.txt";
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Download();
// Use Path in RemoteFile
SSHPlexControl.Localfile = "C:\localfile2.txt";
SSHPlexControl.RemoteFile = "folder/remotefile2.txt";
string operationId = SSHPlexControl.Download();
Resuming Downloads
The class also supports resuming failed downloads by using the StartByte property. If a download is interrupted or canceled, set StartByte to the appropriate offset before calling this method to resume the download.
string localFile = "C:\localfile.txt";
SSHPlexControl.Localfile = localFile;
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Download();
// Cancel Download using the CancelOperation method
SSHPlexControl.CancelOperation(operationId);
// Get the size of the partially downloaded temp file and set StartByte
SSHPlexControl.StartByte = new FileInfo(localFile).Length;
// Resume download
string operationId = SSHPlexControl.Download();
Downloading Multiple Files Using a Filemask
Note: Using a filemask for downloads is only applicable when ChannelType is set to cstScp. To download files matching a filemask set RemoteFile to a filemask. The path may be specified as part of the value in RemoteFile or may be set separately in RemotePath. LocalFile should be set to a local directory where files will be downloaded. When Download is called all matching files are downloaded. See RemoteFile for more information.
Execute Method (SSHPlex Class)
Execute a specified command on the remote host.
Syntax
public String execute(String command);
Remarks
This method executes the specified Command on the remote host.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the ExecuteComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the ExecuteComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSExec or cstSShell.
Interrupt Method (SSHPlex Class)
This method interrupts the current method.
Syntax
public void interrupt();
Remarks
If there is no method in progress, Interrupt simply returns, doing nothing.
ListDirectory Method (SSHPlex Class)
List the current directory specified by RemotePath on an server using SFTP.
Syntax
public String listDirectory();
Remarks
This method lists the directory specified by RemotePath. RemoteFile may also be set to a filemask to list associated files. The file listing is received through the DirList event.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the ListDirectoryComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the ListDirectoryComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp.
The directory entries are provided through the DirList event and also via the DirList property.
SSHPlexControl.RemoteFile = ""; //Clear filemask
SSHPlexControl.RemotePath = "MyFolder";
string opId = SSHPlexControl.ListDirectory();
// ListDirectory operates async so we must wait for it to finish
while (SSHPlexControl.Operations.Keys.Contains(opId)) {
SSHPlexControl.DoEvents();
}
for (int i = 0; i < SSHPlexControl.DirList.Count; i++)
{
Console.WriteLine(SSHPlexControl.DirList[i].FileName);
Console.WriteLine(SSHPlexControl.DirList[i].FileSize);
Console.WriteLine(SSHPlexControl.DirList[i].FileTime);
Console.WriteLine(SSHPlexControl.DirList[i].IsDir);
}
The RemoteFile property may also be used as a filemask when listing files. For instance:
SSHPlexControl.RemoteFile = "*.txt";
SSHPlexControl.ListDirectory();
Note: Since RemoteFile is used as a filemask be sure to clear or reset this value before calling ListDirectory
MakeDirectory Method (SSHPlex Class)
Creates a directory on the remote server using SFTP.
Syntax
public String makeDirectory(String newDir);
Remarks
This method creates an empty directory on the server with the name specified by the NewDir parameter. NewDir is either an absolute path on the server, or a path relative to RemotePath.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the MakeDirectoryComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the MakeDirectoryComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp.
QueryFileAttributes Method (SSHPlex Class)
Queries the server for the attributes of RemoteFile .
Syntax
public void queryFileAttributes();
Remarks
This method queries the server for attributes of RemoteFile. After calling this method, FileAttributes will be populated with the values returned by the server.
To update attributes, modify the desired values in FileAttributes and call UpdateFileAttributes.
QueryRemotePath Method (SSHPlex Class)
This queries the server for the current path.
Syntax
public String queryRemotePath();
Remarks
This method queries the server for the current path. When called, the class will issue a command to the server to retrieve the current path value. The return value of this method is the path returned by the server. For instance:
string remotePath = component.QueryRemotePath();
RemoveDirectory Method (SSHPlex Class)
Removes a directory on the remote server using SFTP.
Syntax
public String removeDirectory(String dirName);
Remarks
This method deletes a directory on the server with the name specified by the DirName parameter. DirName is either and absolute path on the server, or a path relative to RemotePath.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the RemoveDirectoryComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the RemoveDirectoryComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp.
RenameFile Method (SSHPlex Class)
Changes the name of a file on the remote server using SFTP.
Syntax
public String renameFile(String newName);
Remarks
This method renames the file on the server specified by RemoteFile to the name specified by the NewName parameter. RemoteFile and NewName are either absolute paths on the server, or a path relative to RemotePath.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the RenameFileComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the RenameFileComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp.
SendCommand Method (SSHPlex Class)
Sends the specified command to the remote host.
Syntax
public void sendCommand(String command);
Remarks
This method sends the Command to the SSHHost. The command is executed in the user's shell.
It is not necessary to append an end-of-line character to the command. All output from the remote execution will be returned through the Stdout event.
This method sends the Command to the SSHHost. The command is executed in the user's shell.
There is no need to append an end-of-line character to the command. All output from the remote execution will be returned through the Stdout event.
SendStdinBytes Method (SSHPlex Class)
This method sends binary data to the remote host.
Syntax
public void sendStdinBytes(byte[] data);
Remarks
This method sends the specified binary data to the remote host. The data provided are used as input for the process on the remote host. To send text, use the SendStdinText method instead.
If you are sending data to the remote host faster than it can process it, or faster than the network bandwidth allows, the outgoing queue might fill up. When this happens the class fails with exception 10035: "[10035] Operation would block" (WSAEWOULDBLOCK). You can check this error, and then try to send the data again. .
This method sends the specified binary data to the remote host. The data provided are used as input for the process on the remote host. To send text, use the SendStdinText method instead.
If you are sending data to the remote host faster than it can process it, or faster than the network bandwidth allows, the outgoing queue might fill up. When this happens the class fails with exception 10035: "[10035] Operation would block" (WSAEWOULDBLOCK). You can check this error, and then try to send the data again. .
SendStdinText Method (SSHPlex Class)
This method sends text to the remote host.
Syntax
public void sendStdinText(String text);
Remarks
This method sends the specified text to the remote host. The text provided is used as an input for the process on the remote host. To send binary data, use the SendStdinBytes method instead.
If you are sending data to the remote host faster than it can process it, or faster than the network bandwidth allows, the outgoing queue might fill up. When this happens the class fails with exception 10035: "[10035] Operation would block" (WSAEWOULDBLOCK). You can check this error, and then try to send the data again. .
This method sends the specified text to the remote host. The text provided is used as an input for the process on the remote host. To send binary data, use the SendStdinBytes method instead.
If you are sending data to the remote host faster than it can process it, or faster than the network bandwidth allows, the outgoing queue might fill up. When this happens the class fails with exception 10035: "[10035] Operation would block" (WSAEWOULDBLOCK). You can check this error, and then try to send the data again. .
SetDownloadStream Method (SSHPlex Class)
Sets the stream to which the downloaded data from the server will be written.
Syntax
public void setDownloadStream(java.io.OutputStream downloadStream);
Remarks
If a download stream is set before the Download method is called, the downloaded data will be written to the stream. The stream should be open and normally set to position 0.
The class will automatically close this stream if CloseStreamAfterTransfer is True (default). If the stream is closed, you will need to call SetDownloadStream again before calling Download again.
The downloaded content will be written starting at the current position in the stream.
Note: SetDownloadStream and LocalFile will reset the other.
SetUploadStream Method (SSHPlex Class)
Sets the stream from which the class will read data to upload to the server.
Syntax
public void setUploadStream(java.io.InputStream uploadStream);
Remarks
If an upload stream is set before the Upload method is called, the content of the stream will be read by the class and uploaded to the server. The stream should be open and normally set to position 0. The class will automatically close this stream if CloseStreamAfterTransfer is True (default). If the stream is closed, you will need to call SetUploadStream again before calling Upload again. The content of the stream will be read from the current position all the way to the end and no bytes will be skipped.
Note: SetUploadStream and LocalFile will reset the other.
SSHLogoff Method (SSHPlex Class)
Logoff from the SSH server.
Syntax
public void SSHLogoff();
Remarks
Logoff from the SSH server. If that fails, the connection is terminated by the local host.
SSHLogon Method (SSHPlex Class)
Logon to the SSHHost using the current SSHUser and SSHPassword .
Syntax
public void SSHLogon(String SSHHost, int SSHPort);
Remarks
Logon to the SSH server using the current SSHUser and SSHPassword. This will perform the SSH handshake and authentication.
Example (Logging On)
SSHPlexControl.SSHUser = "username"
SSHPlexControl.SSHPassword = "password"
SSHPlexControl.SSHLogon("sshHost", sshPort)
UpdateFileAttributes Method (SSHPlex Class)
Instructs the class to send the FileAttributes to the server using SFTP.
Syntax
public String updateFileAttributes();
Remarks
When UpdateFileAttributes is called, the class will send the value of FileAttributes to the server.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the UpdateFileAttributesComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the UpdateFileAttributesComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp.
Upload Method (SSHPlex Class)
Upload a file specified by LocalFile using SCP or SFTP.
Syntax
public String upload();
Remarks
This method Uploads the local file specified by LocalFile to the remote file specified by RemoteFile. The StartTransfer, Transfer, and EndTransfer events provide details about the individual file transfers. If the LocalFile property is "" (empty string) then the file data will be available through the Transfer event.
This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.
When the operation completes the UploadComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the UploadComplete event to determine the result.
If a Secure Shell (SSH) session is not in place, one is automatically created by the component first.
This method is only applicable when ChannelType is set to cstSftp or cstScp.
Set LocalFile to the name of the file to upload before calling this method. If SetUploadStream is used to set an upload stream the data to upload is taken from the stream instead.
RemoteFile should be set to either a relative or absolute path. If RemoteFile is not an absolute path it will be uploaded relative to RemotePath.
Code Example
SSHPlexControl.Localfile = "C:\localfile.txt";
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Upload();
// Use Path in RemoteFile
SSHPlexControl.Localfile = "C:\localfile2.txt";
SSHPlexControl.RemoteFile = "folder/remotefile2.txt";
string operationId = SSHPlexControl.Upload();
Resuming Uploads
The class also supports resuming failed uploads by using the StartByte property. If an upload is interrupted or canceled, set StartByte to the appropriate offset before calling this method to resume the upload.
string localFile = "C:\localfile.txt";
SSHPlexControl.Localfile = localFile;
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Upload();
// Cancel Upload using the CancelOperation method
SSHPlexControl.CancelOperation(operationId);
// Get the size of the partially uploaded temp file and set StartByte
SSHPlexControl.StartByte = SSHPlexControl.FileAttributes.Size;
// Resume upload
string operationId = SSHPlexControl.Upload();
AppendComplete Event (SSHPlex Class)
Fired when an Append operation completes.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void appendComplete(SSHPlexAppendCompleteEvent e) {} ... } public class SSHPlexAppendCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String localFile; public String remoteFile; public String remotePath; }
Remarks
This event fires when an Append operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
LocalFile is the local file that was specified when the operation was initiated.
RemoteFile is the remote file that was specified when the operation was initiated.
RemotePath is the remote path that was specified when the operation was initiated.
Connected Event (SSHPlex Class)
Fired immediately after a connection completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void connected(SSHPlexConnectedEvent e) {} ... } public class SSHPlexConnectedEvent { public int statusCode; public String description; }
Remarks
If the connection is made normally, StatusCode is 0 and Description is "OK".
If the connection fails, StatusCode has the error code returned by the Transmission Control Protocol (TCP)/IP stack. Description contains a description of this code. The value of StatusCode is equal to the value of the error.
Please refer to the Error Codes section for more information.
ConnectionStatus Event (SSHPlex Class)
Fired to indicate changes in the connection state.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void connectionStatus(SSHPlexConnectionStatusEvent e) {} ... } public class SSHPlexConnectionStatusEvent { public String connectionEvent; public int statusCode; public String description; }
Remarks
This event is fired when the connection state changes: for example, completion of a firewall or proxy connection or completion of a security handshake.
The ConnectionEvent parameter indicates the type of connection event. Values may include the following:
Firewall connection complete. | |
Secure Sockets Layer (SSL) or S/Shell handshake complete (where applicable). | |
Remote host connection complete. | |
Remote host disconnected. | |
SSL or S/Shell connection broken. | |
Firewall host disconnected. |
CreateFileComplete Event (SSHPlex Class)
Fired when a CreateFile operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void createFileComplete(SSHPlexCreateFileCompleteEvent e) {} ... } public class SSHPlexCreateFileCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String remoteFile; public String remotePath; }
Remarks
This event fires when a CreateFile operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
RemoteFile is the remote file that was specified when the operation was initiated.
RemotePath is the remote path that was specified when the operation was initiated.
DeleteFileComplete Event (SSHPlex Class)
Fired when a DeleteFile operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void deleteFileComplete(SSHPlexDeleteFileCompleteEvent e) {} ... } public class SSHPlexDeleteFileCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String remoteFile; public String remotePath; }
Remarks
This event fires when a DeleteFile operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
RemoteFile is the remote file that was specified when the operation was initiated.
RemotePath is the remote path that was specified when the operation was initiated.
DirList Event (SSHPlex Class)
Fired when a directory entry is received.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void dirList(SSHPlexDirListEvent e) {} ... } public class SSHPlexDirListEvent { public String operationId; public String dirEntry; public String fileName; public boolean isDir; public long fileSize; public String fileTime; public boolean isSymlink; }
Remarks
OperationId is associated with the operation that fired this event.
The DirList events are fired when a directory listing is received as a response to a ListDirectory.
The StartTransfer and EndTransfer events mark the beginning and end of the event stream.
The DirEntry parameter contains the filename when ListDirectory is called.
The class tries to fill out the FileName, IsDir, FileSize, and FileTime parameters when calling the ListDirectory method.
The format of the FileTime parameter returned by the class can be controlled through the FileTimeFormat configuration setting. If no format is specified, the class will format the date dependent on the year. If the filetime is in the same year, it will be formatted as "MMM dd HH:mm", otherwise it will be formatted as "MMM dd yyyy".
IsSymlink indicates whether the entry is a symbolic link. When the entry is a symbolic link the value of IsDir will always be False since this information is not returned in the directory listing. To inspect a symlink to determine if it is a link to a file or folder set RemoteFile and query the IsDir field.
Disconnected Event (SSHPlex Class)
Fired when a connection is closed.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void disconnected(SSHPlexDisconnectedEvent e) {} ... } public class SSHPlexDisconnectedEvent { public int statusCode; public String description; }
Remarks
If the connection is broken normally, StatusCode is 0 and Description is "OK".
If the connection is broken for any other reason, StatusCode has the error code returned by the Transmission Control Protocol (TCP/IP) subsystem. Description contains a description of this code. The value of StatusCode is equal to the value of the TCP/IP error.
Please refer to the Error Codes section for more information.
DownloadComplete Event (SSHPlex Class)
Fired when a Download operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void downloadComplete(SSHPlexDownloadCompleteEvent e) {} ... } public class SSHPlexDownloadCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String localFile; public String remoteFile; public String remotePath; }
Remarks
This event fires when a Download operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
LocalFile is the local file that was specified when the operation was initiated.
RemoteFile is the remote file that was specified when the operation was initiated.
RemotePath is the remote path that was specified when the operation was initiated.
EndTransfer Event (SSHPlex Class)
Fired when a file completes downloading/uploading.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void endTransfer(SSHPlexEndTransferEvent e) {} ... } public class SSHPlexEndTransferEvent { public String operationId; public int direction; public String localFile; public String remoteFile; public String remotePath; }
Remarks
This event is fired once per file when it finishes downloading/uploading.
OperationId is the string associated with operation fired this event.
Direction is 0 for Uploads and 1 for Downloads.
LocalFile, RemoteFile, and RemotePath are populated with values of LocalFile, RemoteFile, and RemotePath, respectively, that are associated with the method that triggered this event.
Error Event (SSHPlex Class)
Information about errors during data delivery.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void error(SSHPlexErrorEvent e) {} ... } public class SSHPlexErrorEvent { public String operationId; public int errorCode; public String description; public String localFile; public String remoteFile; }
Remarks
The Error event is fired in case of exceptional conditions during message processing. Normally the class throws an exception.
ErrorCode contains an error code and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.
LocalFile identifies the local file. RemoteFile is the remote file.
ExecuteComplete Event (SSHPlex Class)
Fired when an Execute operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void executeComplete(SSHPlexExecuteCompleteEvent e) {} ... } public class SSHPlexExecuteCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public int exitStatus; }
Remarks
This event fires when an Execute operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
ExitStatus is the exit code of the executed command. If an error message is returned it is present in ErrorDescription.
ListDirectoryComplete Event (SSHPlex Class)
Fired when a ListDirectory operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void listDirectoryComplete(SSHPlexListDirectoryCompleteEvent e) {} ... } public class SSHPlexListDirectoryCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String remotePath; }
Remarks
This event fires when a ListDirectory operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
RemotePath is the remote path that was specified when the operation was initiated.
Log Event (SSHPlex Class)
Fired once for each log message.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void log(SSHPlexLogEvent e) {} ... } public class SSHPlexLogEvent { public int logLevel; public String message; public String logType; }
Remarks
Fired once for each log message generated by the class. The verbosity is controlled by the LogLevel setting.
LogLevel indicates the detail level of the message. Possible values are as follows:
0 (None) | No messages are logged. |
1 (Info - Default) | Informational events such as Secure Shell (SSH) handshake messages are logged. |
2 (Verbose) | Detailed data such as individual packet information are logged. |
3 (Debug) | Debug data including all relevant sent and received bytes are logged. |
Message is the log message.
LogType is reserved for future use.
MakeDirectoryComplete Event (SSHPlex Class)
Fired when a MakeDirectory operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void makeDirectoryComplete(SSHPlexMakeDirectoryCompleteEvent e) {} ... } public class SSHPlexMakeDirectoryCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String remotePath; }
Remarks
This event fires when a MakeDirectory operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
RemotePath is the remote path that was specified when the operation was initiated.
RemoveDirectoryComplete Event (SSHPlex Class)
Fired when a RemoveDirectory operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void removeDirectoryComplete(SSHPlexRemoveDirectoryCompleteEvent e) {} ... } public class SSHPlexRemoveDirectoryCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String directoryName; public String remotePath; }
Remarks
This event fires when a RemoveDirectory operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
DirectoryName is the name of the directory which was removed.
RemotePath is the remote path that was specified when the operation was initiated.
RenameFileComplete Event (SSHPlex Class)
Fired when a RenameFile operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void renameFileComplete(SSHPlexRenameFileCompleteEvent e) {} ... } public class SSHPlexRenameFileCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String remoteFile; public String remotePath; public String newFileName; }
Remarks
This event fires when a RenameFile operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
RemoteFile is the remote file that was specified when the operation was initiated.
RemotePath is the remote path that was specified when the operation was initiated.
NewFileName is the name to which the file was renamed as provided when RenameFile was originally called.
SSHCustomAuth Event (SSHPlex Class)
Fired when the class is doing a custom authentication.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void SSHCustomAuth(SSHPlexSSHCustomAuthEvent e) {} ... } public class SSHPlexSSHCustomAuthEvent { public String packet; //read-write }
Remarks
SSHCustomAuth is fired during the user authentication stage of the Secure Shell (SSH) logon process if SSHAuthMode is set to amCustom. Packet contains the last raw SSH packet sent by the server, in HEX-encoded format.
The client should create a new raw SSH packet to send to the server and set Packet to the HEX-encoded representation of the packet to send.
In all cases, Packet will start with the message type field.
To read the incoming packet, call DecodePacket and then use the GetSSHParam and GetSSHParamBytes methods. To create a packet, use the SetSSHParam method and then call EncodePacket to obtain a HEX-encoded value and assign this to the Packet parameter.
SSHKeyboardInteractive Event (SSHPlex Class)
Fired when the class receives a request for user input from the server.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void SSHKeyboardInteractive(SSHPlexSSHKeyboardInteractiveEvent e) {} ... } public class SSHPlexSSHKeyboardInteractiveEvent { public String name; public String instructions; public String prompt; public String response; //read-write public boolean echoResponse; }
Remarks
SSHKeyboardInteractive is fired during the user authentication stage of the Secure Shell (SSH) logon process. During authentication, the class will request a list of available authentication methods for the SSHUser. For example, if the SSHHost responds with "keyboard-interactive", the class will fire this event to allow the client application to set the password.
During authentication, the SSH server may respond with a request for the user's authentication information. Name is a server-provided value associated with the authentication method such as "CRYPTOCard Authentication". Instructions will contain specific instructions, also supplied by the server, for how the user should respond.
Along with these values, the server will also send at least one input Prompt to be displayed to and filled out by the user. Response should be set to the user's input, and will be sent back in the user authentication information response. EchoResponse is a server recommendation for whether or not the user's response should be echoed back during input.
Note: The server may send several prompts in a single packet. The class will fire the SSHKeyboardInteractive event once for each prompt.
SSHServerAuthentication Event (SSHPlex Class)
Fired after the server presents its public key to the client.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void SSHServerAuthentication(SSHPlexSSHServerAuthenticationEvent e) {} ... } public class SSHPlexSSHServerAuthenticationEvent { public byte[] hostKey; public String fingerprint; public String keyAlgorithm; public String certSubject; public String certIssuer; public String status; public boolean accept; //read-write }
Remarks
This event is fired when the client can decide whether or not to continue with the connection process. If the public key is known to be a valid key for the Secure Shell (SSH) server, Accept should be set to True within the event. Otherwise, the server will not be authenticated and the connection will be broken.
Accept will be True only if either HostKey or Fingerprint is identical to the value of SSHAcceptServerHostKey.
Accept may be set to True manually to accept the server host key.
Note: SSH's security inherently relies on client verification of the host key. Ignoring the host key and always setting Accept to True is strongly discouraged, and could cause potentially serious security vulnerabilities in your application. It is recommended that clients maintain a list of known keys for each server and check HostKey against this list each time a connection is attempted.
Host Key contains the full binary text of the key, in the same format used internally by SSH.
Fingerprint holds the SHA-256 hash of HostKey in the hex-encoded form: 0a:1b:2c:3d. To configure the hash algorithm used to calculate this value, see SSHFingerprintHashAlgorithm.
KeyAlgorithm identifies the host key algorithm. The following values are supported:
- ssh-rsa
- ssh-dss
- rsa-sha2-256
- rsa-sha2-512
- x509v3-sign-rsa
- x509v3-sign-dss
- ecdsa-sha2-nistp256
- ecdsa-sha2-nistp384
- ecdsa-sha2-nistp521
CertSubject is the subject of the certificate. This is applicable only when KeyAlgorithm is "x509v3-sign-rsa" or "x509v3-sign-dss".
CertIssuer is the issuer of the certificate. This is applicable only when KeyAlgorithm is "x509v3-sign-rsa" or "x509v3-sign-dss".
Status is reserved for future use.
SSHStatus Event (SSHPlex Class)
Fired to track the progress of the secure connection.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void SSHStatus(SSHPlexSSHStatusEvent e) {} ... } public class SSHPlexSSHStatusEvent { public String message; }
Remarks
The event is fired for informational and logging purposes only. Used to track the progress of the connection.
StartTransfer Event (SSHPlex Class)
Fired when a file starts downloading/uploading.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void startTransfer(SSHPlexStartTransferEvent e) {} ... } public class SSHPlexStartTransferEvent { public String operationId; public int direction; public String localFile; public String remoteFile; public String remotePath; public String filePermissions; //read-write }
Remarks
This event is fired once per file when it starts downloading/uploading.
OperationId is the string associated with operation fired this event.
Direction is 0 for Uploads and 1 for Downloads.
LocalFile, RemoteFile, and RemotePath are populated with values of LocalFile, RemoteFile, and RemotePath, respectively, that are associated with the method that triggered this event.
FilePermissions includes information about the file that can be modified before finishing the upload/download.
Stderr Event (SSHPlex Class)
Fired when data (complete lines) come in through stderr.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void stderr(SSHPlexStderrEvent e) {} ... } public class SSHPlexStderrEvent { public String operationId; public byte[] text; }
Remarks
The Stderr event is fired every time the process on the remote host outputs a line in its error output. The incoming data is provided through the Text parameter.
Stdout Event (SSHPlex Class)
Fired when data (complete lines) come in through stdout.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void stdout(SSHPlexStdoutEvent e) {} ... } public class SSHPlexStdoutEvent { public String operationId; public byte[] text; }
Remarks
The Stdout event is fired every time the process on the remote host outputs a line in its standard output. The incoming data is provided through the Text parameter.
Transfer Event (SSHPlex Class)
Fired during file download/upload.
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void transfer(SSHPlexTransferEvent e) {} ... } public class SSHPlexTransferEvent { public String operationId; public int direction; public String localFile; public String remoteFile; public String remotePath; public long bytesTransferred; public int percentDone; public byte[] text; public boolean cancel; //read-write }
Remarks
This event is fired once per file when it starts downloading/uploading.
OperationId is associated with the operation that fired this event. Direction is 0 for Uploads and 1 for Downloads. LocalFile, RemoteFile, and RemotePath are populated with values of LocalFile, RemoteFile, and RemotePath, respectively, that are associated with the operation that fired this event.
BytesTransferred shows the number of bytes transferred since the beginning of the transfer, and PercentDone contains the percentage (0-100) of bytes transferred based on the Direction being transferred. If PercentDone cannot be calculated the value will be -1.
Text contains the text of the file being transferred.
Setting Cancel to true will cancel the associated operation without firing a DownloadComplete or UploadComplete event. It is not equivalent to calling CancelOperation with the associated OperationId, which will fire the aforementioned events.
UpdateFileAttributesComplete Event (SSHPlex Class)
Fired when a UpdateFileAttributes operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void updateFileAttributesComplete(SSHPlexUpdateFileAttributesCompleteEvent e) {} ... } public class SSHPlexUpdateFileAttributesCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String remoteFile; public String remotePath; }
Remarks
This event fires when an UpdateFileAttributes operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
RemoteFile is the remote file that was specified when the operation was initiated.
RemotePath is the remote path that was specified when the operation was initiated.
UploadComplete Event (SSHPlex Class)
Fired when an Upload operation completes (or fails).
Syntax
public class DefaultSSHPlexEventListener implements SSHPlexEventListener { ... public void uploadComplete(SSHPlexUploadCompleteEvent e) {} ... } public class SSHPlexUploadCompleteEvent { public String operationId; public int errorCode; public String errorDescription; public String localFile; public String remoteFile; public String remotePath; }
Remarks
This event fires when an Upload operation completes either successfully or unsuccessfully. If the operation succeeded ErrorCode will be 0. If the operation failed or was canceled by CancelOperation ErrorCode will contain a non-zero value and ErrorDescription will contain a description of the error. Please refer to the Error Codes section for possible error codes.
OperationId is the Id of the completed operation. This value will match the Operation Id returned by the method which initiated the operation.
ErrorCode holds the error code (if any). A value of 0 indicates success. A positive value indicates failure.
ErrorDescription is a description of the error.
LocalFile is the local file that was specified when the operation was initiated.
RemoteFile is the remote file that was specified when the operation was initiated.
RemotePath is the remote path that was specified when the operation was initiated.
Certificate Type
This is the digital certificate being used.
Remarks
This type describes the current digital certificate. The certificate may be a public or private key. The fields are used to identify or select certificates.
Fields
EffectiveDate
String (read-only)
Default Value: ""
The date on which this certificate becomes valid. Before this date, it is not valid. The date is localized to the system's time zone. The following example illustrates the format of an encoded date:
23-Jan-2000 15:00:00.
ExpirationDate
String (read-only)
Default Value: ""
The date on which the certificate expires. After this date, the certificate will no longer be valid. The date is localized to the system's time zone. The following example illustrates the format of an encoded date:
23-Jan-2001 15:00:00.
ExtendedKeyUsage
String (read-only)
Default Value: ""
A comma-delimited list of extended key usage identifiers. These are the same as ASN.1 object identifiers (OIDs).
Fingerprint
String (read-only)
Default Value: ""
The hex-encoded, 16-byte MD5 fingerprint of the certificate. This property is primarily used for keys which do not have a corresponding X.509 public certificate, such as PEM keys that only contain a private key. It is commonly used for SSH keys.
The following example illustrates the format: bc:2a:72:af:fe:58:17:43:7a:5f:ba:5a:7c:90:f7:02
FingerprintSHA1
String (read-only)
Default Value: ""
The hex-encoded, 20-byte SHA-1 fingerprint of the certificate. This property is primarily used for keys which do not have a corresponding X.509 public certificate, such as PEM keys that only contain a private key. It is commonly used for SSH keys.
The following example illustrates the format: 30:7b:fa:38:65:83:ff:da:b4:4e:07:3f:17:b8:a4:ed:80:be:ff:84
FingerprintSHA256
String (read-only)
Default Value: ""
The hex-encoded, 32-byte SHA-256 fingerprint of the certificate. This property is primarily used for keys which do not have a corresponding X.509 public certificate, such as PEM keys that only contain a private key. It is commonly used for SSH keys.
The following example illustrates the format: 6a:80:5c:33:a9:43:ea:b0:96:12:8a:64:96:30:ef:4a:8a:96:86:ce:f4:c7:be:10:24:8e:2b:60:9e:f3:59:53
Issuer
String (read-only)
Default Value: ""
The issuer of the certificate. This field contains a string representation of the name of the issuing authority for the certificate.
KeyPassword
String
Default Value: ""
The password for the certificate's private key (if any).
Some certificate stores may individually protect certificates' private keys, separate from the standard protection offered by the StorePassword. This field can be used to read such password-protected private keys.
Note: This property defaults to the value of StorePassword. To clear it, you must set the property to the empty string (""). It can be set at any time, but when the private key's password is different from the store's password, then it must be set before calling PrivateKey.
PrivateKey
String (read-only)
Default Value: ""
The private key of the certificate (if available). The key is provided as PEM/Base64-encoded data.
Note: The PrivateKey may be available but not exportable. In this case, PrivateKey returns an empty string.
PrivateKeyAvailable
boolean (read-only)
Default Value: False
Whether a PrivateKey is available for the selected certificate. If PrivateKeyAvailable is True, the certificate may be used for authentication purposes (e.g., server authentication).
PrivateKeyContainer
String (read-only)
Default Value: ""
The name of the PrivateKey container for the certificate (if available). This functionality is available only on Windows platforms.
PublicKey
String (read-only)
Default Value: ""
The public key of the certificate. The key is provided as PEM/Base64-encoded data.
PublicKeyAlgorithm
String (read-only)
Default Value: ""
The textual description of the certificate's public key algorithm. The property contains either the name of the algorithm (e.g., "RSA" or "RSA_DH") or an object identifier (OID) string representing the algorithm.
PublicKeyLength
int (read-only)
Default Value: 0
The length of the certificate's public key (in bits). Common values are 512, 1024, and 2048.
SerialNumber
String (read-only)
Default Value: ""
The serial number of the certificate encoded as a string. The number is encoded as a series of hexadecimal digits, with each pair representing a byte of the serial number.
SignatureAlgorithm
String (read-only)
Default Value: ""
The text description of the certificate's signature algorithm. The property contains either the name of the algorithm (e.g., "RSA" or "RSA_MD5RSA") or an object identifier (OID) string representing the algorithm.
Store
String
Default Value: "MY"
The name of the certificate store for the client certificate.
The StoreType field denotes the type of the certificate store specified by Store. If the store is password-protected, specify the password in StorePassword.
Store is used in conjunction with the Subject field to specify client certificates. If Store has a value, and Subject or Encoded is set, a search for a certificate is initiated. Please see the Subject field for details.
Designations of certificate stores are platform dependent.
The following designations are the most common User and Machine certificate stores in Windows:
MY | A certificate store holding personal certificates with their associated private keys. |
CA | Certifying authority certificates. |
ROOT | Root certificates. |
In Java, the certificate store normally is a file containing certificates and optional private keys.
When the certificate store type is cstPFXFile, this property must be set to the name of the file. When the type is cstPFXBlob, the property must be set to the binary contents of a PFX file (i.e., PKCS#12 certificate store).
StoreB
byte[]
Default Value: "MY"
The name of the certificate store for the client certificate.
The StoreType field denotes the type of the certificate store specified by Store. If the store is password-protected, specify the password in StorePassword.
Store is used in conjunction with the Subject field to specify client certificates. If Store has a value, and Subject or Encoded is set, a search for a certificate is initiated. Please see the Subject field for details.
Designations of certificate stores are platform dependent.
The following designations are the most common User and Machine certificate stores in Windows:
MY | A certificate store holding personal certificates with their associated private keys. |
CA | Certifying authority certificates. |
ROOT | Root certificates. |
In Java, the certificate store normally is a file containing certificates and optional private keys.
When the certificate store type is cstPFXFile, this property must be set to the name of the file. When the type is cstPFXBlob, the property must be set to the binary contents of a PFX file (i.e., PKCS#12 certificate store).
StorePassword
String
Default Value: ""
If the type of certificate store requires a password, this field is used to specify the password needed to open the certificate store.
StoreType
int
Default Value: 0
The type of certificate store for this certificate.
The class supports both public and private keys in a variety of formats. When the cstAuto value is used, the class will automatically determine the type. This field can take one of the following values:
0 (cstUser - default) | For Windows, this specifies that the certificate store is a certificate store owned by the current user.
Note: This store type is not available in Java. |
1 (cstMachine) | For Windows, this specifies that the certificate store is a machine store.
Note: This store type is not available in Java. |
2 (cstPFXFile) | The certificate store is the name of a PFX (PKCS#12) file containing certificates. |
3 (cstPFXBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in PFX (PKCS#12) format. |
4 (cstJKSFile) | The certificate store is the name of a Java Key Store (JKS) file containing certificates.
Note: This store type is only available in Java. |
5 (cstJKSBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in Java Key Store (JKS) format.
Note: This store type is only available in Java. |
6 (cstPEMKeyFile) | The certificate store is the name of a PEM-encoded file that contains a private key and an optional certificate. |
7 (cstPEMKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains a private key and an optional certificate. |
8 (cstPublicKeyFile) | The certificate store is the name of a file that contains a PEM- or DER-encoded public key certificate. |
9 (cstPublicKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains a PEM- or DER-encoded public key certificate. |
10 (cstSSHPublicKeyBlob) | The certificate store is a string (binary or Base64-encoded) that contains an SSH-style public key. |
11 (cstP7BFile) | The certificate store is the name of a PKCS#7 file containing certificates. |
12 (cstP7BBlob) | The certificate store is a string (binary) representing a certificate store in PKCS#7 format. |
13 (cstSSHPublicKeyFile) | The certificate store is the name of a file that contains an SSH-style public key. |
14 (cstPPKFile) | The certificate store is the name of a file that contains a PPK (PuTTY Private Key). |
15 (cstPPKBlob) | The certificate store is a string (binary) that contains a PPK (PuTTY Private Key). |
16 (cstXMLFile) | The certificate store is the name of a file that contains a certificate in XML format. |
17 (cstXMLBlob) | The certificate store is a string that contains a certificate in XML format. |
18 (cstJWKFile) | The certificate store is the name of a file that contains a JWK (JSON Web Key). |
19 (cstJWKBlob) | The certificate store is a string that contains a JWK (JSON Web Key). |
21 (cstBCFKSFile) | The certificate store is the name of a file that contains a BCFKS (Bouncy Castle FIPS Key Store).
Note: This store type is only available in Java and .NET. |
22 (cstBCFKSBlob) | The certificate store is a string (binary or Base64-encoded) representing a certificate store in BCFKS (Bouncy Castle FIPS Key Store) format.
Note: This store type is only available in Java and .NET. |
23 (cstPKCS11) | The certificate is present on a physical security key accessible via a PKCS#11 interface.
To use a security key, the necessary data must first be collected using the CertMgr class. The ListStoreCertificates method may be called after setting CertStoreType to cstPKCS11, CertStorePassword to the PIN, and CertStore to the full path of the PKCS#11 DLL. The certificate information returned in the CertList event's CertEncoded parameter may be saved for later use. When using a certificate, pass the previously saved security key information as the Store and set StorePassword to the PIN. Code Example. SSH Authentication with Security Key:
|
99 (cstAuto) | The store type is automatically detected from the input data. This setting may be used with both public and private keys and can detect any of the supported formats automatically. |
SubjectAltNames
String (read-only)
Default Value: ""
Comma-separated lists of alternative subject names for the certificate.
ThumbprintMD5
String (read-only)
Default Value: ""
The MD5 hash of the certificate. It is primarily used for X.509 certificates. If the hash does not already exist, it is automatically computed.
ThumbprintSHA1
String (read-only)
Default Value: ""
The SHA-1 hash of the certificate. It is primarily used for X.509 certificates. If the hash does not already exist, it is automatically computed.
ThumbprintSHA256
String (read-only)
Default Value: ""
The SHA-256 hash of the certificate. It is primarily used for X.509 certificates. If the hash does not already exist, it is automatically computed.
Usage
String (read-only)
Default Value: ""
The text description of UsageFlags.
This value will be one or more of the following strings and will be separated by commas:
- Digital Signature
- Non-Repudiation
- Key Encipherment
- Data Encipherment
- Key Agreement
- Certificate Signing
- CRL Signing
- Encipher Only
If the provider is OpenSSL, the value is a comma-separated list of X.509 certificate extension names.
UsageFlags
int (read-only)
Default Value: 0
The flags that show intended use for the certificate. The value of UsageFlags is a combination of the following flags:
0x80 | Digital Signature |
0x40 | Non-Repudiation |
0x20 | Key Encipherment |
0x10 | Data Encipherment |
0x08 | Key Agreement |
0x04 | Certificate Signing |
0x02 | CRL Signing |
0x01 | Encipher Only |
Please see the Usage field for a text representation of UsageFlags.
This functionality currently is not available when the provider is OpenSSL.
Version
String (read-only)
Default Value: ""
The certificate's version number. The possible values are the strings "V1", "V2", and "V3".
Subject
String
Default Value: ""
The subject of the certificate used for client authentication.
This field will be populated with the full subject of the loaded certificate. When loading a certificate, the subject is used to locate the certificate in the store.
If an exact match is not found, the store is searched for subjects containing the value of the property.
If a match is still not found, the property is set to an empty string, and no certificate is selected.
The special value "*" picks a random certificate in the certificate store.
The certificate subject is a comma-separated list of distinguished name fields and values. For instance, "CN=www.server.com, OU=test, C=US, E=support@nsoftware.com". Common fields and their meanings are as follows:
Field | Meaning |
CN | Common Name. This is commonly a hostname like www.server.com. |
O | Organization |
OU | Organizational Unit |
L | Locality |
S | State |
C | Country |
E | Email Address |
If a field value contains a comma, it must be quoted.
Encoded
String
Default Value: ""
The certificate (PEM/Base64 encoded). This field is used to assign a specific certificate. The Store and Subject fields also may be used to specify a certificate.
When Encoded is set, a search is initiated in the current Store for the private key of the certificate. If the key is found, Subject is updated to reflect the full subject of the selected certificate; otherwise, Subject is set to an empty string.
EncodedB
byte[]
Default Value: ""
The certificate (PEM/Base64 encoded). This field is used to assign a specific certificate. The Store and Subject fields also may be used to specify a certificate.
When Encoded is set, a search is initiated in the current Store for the private key of the certificate. If the key is found, Subject is updated to reflect the full subject of the selected certificate; otherwise, Subject is set to an empty string.
Constructors
public Certificate();
Creates a instance whose properties can be set. This is useful for use with when generating new certificates.
public Certificate( certificateFile);
Opens CertificateFile and reads out the contents as an X.509 public key.
public Certificate( encoded);
Parses Encoded as an X.509 public key.
public Certificate( storeType, store, storePassword, subject);
StoreType identifies the type of certificate store to use. See for descriptions of the different certificate stores. Store is a file containing the certificate store. StorePassword is the password used to protect the store.
After the store has been successfully opened, the class will attempt to find the certificate identified by Subject . This can be either a complete or a substring match of the X.509 certificate's subject Distinguished Name (DN). The Subject parameter can also take an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load in a "Thumbprint=value" format.
public Certificate( storeType, store, storePassword, subject, configurationString);
StoreType identifies the type of certificate store to use. See for descriptions of the different certificate stores. Store is a file containing the certificate store. StorePassword is the password used to protect the store.
ConfigurationString is a newline-separated list of name-value pairs that may be used to modify the default behavior. Possible values include "PersistPFXKey", which shows whether or not the PFX key is persisted after performing operations with the private key. This correlates to the PKCS12_NO_PERSIST_KEY CryptoAPI option. The default value is True (the key is persisted). "Thumbprint" - an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load. When specified, this value is used to select the certificate in the store. This is applicable to the cstUser , cstMachine , cstPublicKeyFile , and cstPFXFile store types. "UseInternalSecurityAPI" shows whether the platform (default) or the internal security API is used when performing certificate-related operations.
After the store has been successfully opened, the class will attempt to find the certificate identified by Subject . This can be either a complete or a substring match of the X.509 certificate's subject Distinguished Name (DN). The Subject parameter can also take an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load in a "Thumbprint=value" format.
public Certificate( storeType, store, storePassword, encoded);
StoreType identifies the type of certificate store to use. See for descriptions of the different certificate stores. Store is a file containing the certificate store. StorePassword is the password used to protect the store.
After the store has been successfully opened, the class will load Encoded as an X.509 certificate and search the opened store for a corresponding private key.
public Certificate( storeType, store, storePassword, subject);
StoreType identifies the type of certificate store to use. See for descriptions of the different certificate stores. Store is a byte array containing the certificate data. StorePassword is the password used to protect the store.
After the store has been successfully opened, the class will attempt to find the certificate identified by Subject . This can be either a complete or a substring match of the X.509 certificate's subject Distinguished Name (DN). The Subject parameter can also take an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load in a "Thumbprint=value" format.
public Certificate( storeType, store, storePassword, subject, configurationString);
StoreType identifies the type of certificate store to use. See for descriptions of the different certificate stores. Store is a byte array containing the certificate data. StorePassword is the password used to protect the store.
After the store has been successfully opened, the class will attempt to find the certificate identified by Subject . This can be either a complete or a substring match of the X.509 certificate's subject Distinguished Name (DN). The Subject parameter can also take an MD5, SHA-1, or SHA-256 thumbprint of the certificate to load in a "Thumbprint=value" format.
public Certificate( storeType, store, storePassword, encoded);
StoreType identifies the type of certificate store to use. See for descriptions of the different certificate stores. Store is a byte array containing the certificate data. StorePassword is the password used to protect the store.
After the store has been successfully opened, the class will load Encoded as an X.509 certificate and search the opened store for a corresponding private key.
DirEntry Type
This is a listing in a directory returned from the server.
Remarks
The DirEntry listings are filled out by the class when a directory listing is received as a response to a ListDirectory or ListDirectoryLong call. The server returns a listing for each directory and file at the current path that exists. This listing is parsed into a directory entry.
If ListDirectoryLong is called, all of the fields listed below are supplied by the server. When the ListDirectory method is called, however, the FileSize, FileTime, and IsDir fields all are left empty by the server. In this case, the only field it returns is the FileName.
The full line for the directory entry is provided by the Entry field.
Fields
Entry
String (read-only)
Default Value: ""
This field contains the raw entry as received from the server. It is the complete unparsed entry in the directory listing.
FileName
String (read-only)
Default Value: ""
This field shows the file name in the last directory listing. This also may be the directory name if a directory is being listed. You can tell whether it is a file or a directory by the Boolean IsDir field.
FileSize
long (read-only)
Default Value: 0
This field shows the file size in the last directory listing.
FileTime
String (read-only)
Default Value: ""
This field shows the file time in the last directory listing. This contains the date/time stamp in which the file was created.
Note: In Unix systems, the date is given in two types of formats: If the date is in the past 12 months, the exact time is specified and the year is omitted. Otherwise, only the date and the year, but not hours or minutes, are given.
IsDir
boolean (read-only)
Default Value: False
This field specifies whether entries in the last directory listing are directories. This Boolean value denotes whether or not the directory entry listed in FileName is a file or a directory.
IsSymlink
boolean (read-only)
Default Value: False
This field indicates whether the entry is a symbolic link. When the entry is a symbolic link, the value of IsDir will always be False because this information is not returned in the directory listing. To inspect a symlink to determine if it is a link to a file or a folder, set RemoteFile and query the FileAttributes.IsDir field.
Constructors
public DirEntry();
Firewall Type
The firewall the class will connect through.
Remarks
When connecting through a firewall, this type is used to specify different properties of the firewall, such as the firewall Host and the FirewallType.
Fields
AutoDetect
boolean
Default Value: False
Whether to automatically detect and use firewall system settings, if available.
Connection information will first be obtained from Java system properties, such as http.proxyHost and https.proxyHost. Java properties may be set in a variety of ways; please consult the Java documentation for information about how firewall and proxy values can be specified.
If no Java system properties define connection information, the class will inspect the Windows registry for connection information that may be present on the system (applicable only on Windows systems).
FirewallType
int
Default Value: 0
The type of firewall to connect through. The applicable values are as follows:
fwNone (0) | No firewall (default setting). |
fwTunnel (1) | Connect through a tunneling proxy. Port is set to 80. |
fwSOCKS4 (2) | Connect through a SOCKS4 Proxy. Port is set to 1080. |
fwSOCKS5 (3) | Connect through a SOCKS5 Proxy. Port is set to 1080. |
fwSOCKS4A (10) | Connect through a SOCKS4A Proxy. Port is set to 1080. |
Host
String
Default Value: ""
The name or IP address of the firewall (optional). If a Host is given, the requested connections will be authenticated through the specified firewall when connecting.
If this field is set to a Domain Name, a DNS request is initiated. Upon successful termination of the request, this field is set to the corresponding address. If the search is not successful, the class throws an exception.
Password
String
Default Value: ""
A password if authentication is to be used when connecting through the firewall. If Host is specified, the User and Password fields are used to connect and authenticate to the given firewall. If the authentication fails, the class throws an exception.
Port
int
Default Value: 0
The Transmission Control Protocol (TCP) port for the firewall Host. See the description of the Host field for details.
Note: This field is set automatically when FirewallType is set to a valid value. See the description of the FirewallType field for details.
User
String
Default Value: ""
A username if authentication is to be used when connecting through a firewall. If Host is specified, this field and the Password field are used to connect and authenticate to the given Firewall. If the authentication fails, the class throws an exception.
Constructors
public Firewall();
SFTPFileAttributes Type
Includes a set of attributes for a file existing on an secure file transfer protocol (SFTP) server.
Remarks
This type describes a file residing on an SFTP server.
Fields
AccessTime
long
Default Value: 0
Contains the number of milliseconds since 12:00:00 AM, January 1, 1970, when this file was last accessed.
AccessTimeNanos
int
Default Value: 0
Contains a subsecond value associated with this file's AccessTime.
ACL
String
Default Value: ""
Contains a string containing an access control list (ACL).
AllocationSize
long (read-only)
Default Value: 0
Specifies the size, in bytes, that this file consumes on disk.
AttributeBits
int (read-only)
Default Value: 0
AttributeBits and AttributeBitsValid each contain a bitmask representing attributes of the file on the secure file transfer protocol (SFTP) server. These two values must be interpreted together. Any value present in AttributeBitsValid must be ignored in AttributeBits. This is done so that the server and client can communicate the attributes they know about without confusing any bits they do not understand.
This field can have one or more of the following values ORed together:
- 0x00000001 (SSH_FILEXFER_ATTR_FLAGS_READONLY)
- 0x00000002 (SSH_FILEXFER_ATTR_FLAGS_SYSTEM)
- 0x00000004 (SSH_FILEXFER_ATTR_FLAGS_HIDDEN)
- 0x00000008 (SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE)
- 0x00000010 (SSH_FILEXFER_ATTR_FLAGS_ARCHIVE)
- 0x00000020 (SSH_FILEXFER_ATTR_FLAGS_ENCRYPTED)
- 0x00000040 (SSH_FILEXFER_ATTR_FLAGS_COMPRESSED)
- 0x00000080 (SSH_FILEXFER_ATTR_FLAGS_SPARSE)
- 0x00000100 (SSH_FILEXFER_ATTR_FLAGS_APPEND_ONLY)
- 0x00000200 (SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE)
- 0x00000400 (SSH_FILEXFER_ATTR_FLAGS_SYNC)
- 0x00000800 (SSH_FILEXFER_ATTR_FLAGS_TRANSLATION_ERR)
AttributeBitsValid
int (read-only)
Default Value: 0
AttributeBits and AttributeBitsValid each contain a bitmask representing attributes of the file on the secure file transfer protocol (SFTP) server. These two values must be interpreted together. Any value present in AttributeBitsValid must be ignored in AttributeBits. This is done so that the server and client can communicate the attributes they know about without confusing any bits they do not understand.
This field can have one or more of the following values ORed together:
- 0x00000001 (SSH_FILEXFER_ATTR_FLAGS_READONLY)
- 0x00000002 (SSH_FILEXFER_ATTR_FLAGS_SYSTEM)
- 0x00000004 (SSH_FILEXFER_ATTR_FLAGS_HIDDEN)
- 0x00000008 (SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE)
- 0x00000010 (SSH_FILEXFER_ATTR_FLAGS_ARCHIVE)
- 0x00000020 (SSH_FILEXFER_ATTR_FLAGS_ENCRYPTED)
- 0x00000040 (SSH_FILEXFER_ATTR_FLAGS_COMPRESSED)
- 0x00000080 (SSH_FILEXFER_ATTR_FLAGS_SPARSE)
- 0x00000100 (SSH_FILEXFER_ATTR_FLAGS_APPEND_ONLY)
- 0x00000200 (SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE)
- 0x00000400 (SSH_FILEXFER_ATTR_FLAGS_SYNC)
- 0x00000800 (SSH_FILEXFER_ATTR_FLAGS_TRANSLATION_ERR)
CreationTime
long
Default Value: 0
Specifies the number of milliseconds since 12:00:00 AM, January 1, 1970, when this file was created.
CreationTimeNanos
int
Default Value: 0
Contains a subsecond value associated with this file's CreationTime.
FileType
int (read-only)
Default Value: 0
The type of file. FileType may be one of the following values:
1 (sftRegular - default) | A normal file. |
2 (sftDirectory) | A directory. |
3 (symlink) | The file is a Unix symbolic link. |
4 (sftSpecial) | The file type is a special system file. |
5 (sftUnknown) | The file type is unknown. |
6 (sftSocket) | The file handle is a socket handle. |
7 (sftCharDevice) | The file handle is a character input device. |
8 (sftBlockDevice) | The file handle is a block input device. |
9 (sftpFIFO) | The file handle is a buffering input device. |
Flags
int
Default Value: 0
Flags is an integer containing a bitmask that indicates which fields are valid. When retrieving file attributes from an secure file transfer protocol (SFTP) server, this field indicates which values were read by the class. When setting values, the field is used to determine which values get passed to the server.
Flags may be bitwise-ORed with any of the following values:
0x00000001 (SSH_FILEXFER_ATTR_SIZE) | Size is valid. |
0x00000002 (SSH_FILXFER_ATTR_UIDGID) | OwnerId and GroupId are valid. Note: this attribute is only valid when using SFTP protocol version 3. |
0x00000004 (SSH_FILEXFER_ATTR_PERMISSIONS) | Permissions is valid. |
0x00000008 (SSH_FILEXFER_ATTR_ACCESSTIME) | AccessTime is valid. Note: For protocol version 3, this also denotes that ModifiedTime is valid. |
0x00000010 (SSH_FILEXFER_ATTR_CREATETIME) | CreationTime is valid. Note: This attribute is valid only when using SFTP protocol version 4 and above. |
0x00000020 (SSH_FILEXFER_ATTR_MODIFYTIME) | ModifiedTime is valid. Note: This attribute is valid only when using SFTP protocol version 4 and above. |
0x00000040 (SSH_FILEXFER_ATTR_ACL) | ACL is valid. Note: This attribute is valid only when using SFTP protocol version 4 and above. |
0x00000080 (SSH_FILEXFER_ATTR_OWNERGROUP) | OwnerId and GroupId are valid. Note: This attribute is valid only when using SFTP protocol version 4 and above. |
0x00000100 (SSH_FILEXFER_ATTR_SUBSECOND_TIMES) | AccessTimeNanos, CreationTimeNanos and ModifiedTimeNanos are valid. Note: This attribute is valid only when using SFTP protocol version 4 and above. |
0x00000200 (SSH_FILEXFER_ATTR_BITS) | AttributeBits is valid. Note: This attribute is valid only when using SFTP protocol version 5 and above. When using SFTP protocol version 6 and above, this also indicates that AttributeBitsValid is valid. |
0x00000400 (SSH_FILEXFER_ATTR_ALLOCATION_SIZE) | AllocationSize is valid. Note: This attribute is valid only when using SFTP protocol version 6 and above. |
0x00000800 (SSH_FILEXFER_ATTR_TEXT_HINT) | TextHint is valid. Note: This attribute is valid only when using SFTP protocol version 6 and above. |
0x00001000 (SSH_FILEXFER_ATTR_MIME_TYPE) | MIMEType is valid. Note: This attribute is valid only when using SFTP protocol version 6 and above. |
0x00002000 (SSH_FILEXFER_ATTR_LINK_COUNT) | LinkCount is valid. Note: This attribute is valid only when using SFTP protocol version 6 and above. |
0x00004000 (SSH_FILEXFER_ATTR_UNTRANSLATED_NAME) | UntranslatedName is valid. Note: This attribute is valid only when using SFTP protocol version 6 and above. |
0x80000000 (SSH_FILEXFER_ATTR_EXTENDED) | Extended (vendor-specific) values are associated with the file. This attribute is currently ignored by the class. |
GroupId
String
Default Value: ""
Specifies the Id of the group that has access rights this file.
IsDir
boolean (read-only)
Default Value: False
Specifies whether or not the file represented by these attributes is a directory.
IsSymlink
boolean (read-only)
Default Value: False
Specifies whether or not the file or directory represented by these attributes is a symbolic link. This setting is applicable only when GetSymlinkAttrs is set to True. By default, the attributes of the actual file referred to by the link (not the symbolic link) are returned and this field will always be False.
LinkCount
int (read-only)
Default Value: 0
Includes the number of links that reference this file.
MIMEType
String
Default Value: ""
Specifies a value that can be used in the Content-Type header for a MIME entity part containing this file.
ModifiedTime
long
Default Value: 0
Specifies the number of milliseconds since 12:00:00 AM, January 1, 1970, that this file was last modified.
ModifiedTimeNanos
int
Default Value: 0
Includes a subsecond value associated with this file's ModifiedTime.
OwnerId
String
Default Value: ""
Specifies the user Id of this file's owner.
Permissions
int
Default Value: 0
Includes a 32-bit integer containing the a POSIX-compatible file permission bitmask.
The bitmask should be interpreted as a decimal value of a series of octal digits. For example, an octal permission value of "100644" would be "33188" in Base10, and "40755" in octal would be "16877" in Base10.
The last three octal digits are the most significant and represent, in order, the file access capabilities of the file's owner, the owner's group, and other users. Each of these octal digits is, on its own, a 3-bit bitmask with the following possible values:
1 (001) | Execute |
2 (010) | Write |
4 (100) | Read |
An octal permission digit of 7 would have all three values set and would mean that the file can be read, written, and executed by that user class. For example, the octal permissions "100644" would have a value "6" for the owner, "4" for the group, and "4" for other users. This would be interpreted to mean that all users can read the file, no users can execute it, and only the owner can write it. The permissions "40755" would mean that all users can read and execute the file, but only the owner can write it.
The previous octal digit is another bitmask with the following values:
1 (001) | Sticky Bit - retain the file in memory for performance |
2 (010) | Set GID - sets the group Id of the process to the file's group Id upon execution (only for executable files) |
4 (100) | Set UID - sets the user Id of the process to the file's user Id upon execution (only for executable files) |
The previous two octal digits are used together as a bitmask to determine the type of file. This bitmask has the following values:
01 (000001) | Named pipe |
02 (000010) | Character special |
04 (000100) | Directory |
06 (000110) | Block special |
10 (001000) | Regular |
12 (001010) | Symbolic link |
14 (001100) | Socket |
For example, the octal file permissions "100644" would indicate a regular file and octal "40755" would indicate a directory.
Note: You will need to convert the octal permissions bitmask into its decimal representation.
PermissionsOctal
String
Default Value: ""
Includes an octal string containing the a POSIX-compatible file permission bitmask.
The bitmask should be interpreted as a series of octal digits. For example, "100644" and "40755".
The last three octal digits are the most significant and represent, in order, the file access capabilities of the file's owner, the owner's group, and other users. Each of these octal digits is, on its own, a 3-bit bitmask with the following possible values:
1 (001) | Execute |
2 (010) | Write |
4 (100) | Read |
An octal permission digit of 7 would have all three values set and would mean that the file can be read, written, and executed by that user class. For example, the octal permissions "100644" would have a value "6" for the owner, "4" for the group, and "4" for other users. This would be interpreted to mean that all users can read the file, no users can execute it, and only the owner can write it. The permissions "40755" would mean that all users can read and execute the file, but only the owner can write it.
The previous octal digit is another bitmask with the following values:
1 (001) | Sticky Bit - retain the file in memory for performance |
2 (010) | Set GID - sets the group Id of the process to the file's group Id upon execution (only for executable files) |
4 (100) | Set UID - sets the user Id of the process to the file's user Id upon execution (only for executable files) |
The previous two octal digits are used together as a bitmask to determine the type of file. This bitmask has the following values:
01 (000001) | Named pipe |
02 (000010) | Character special |
04 (000100) | Directory |
06 (000110) | Block special |
10 (001000) | Regular |
12 (001010) | Symbolic link |
14 (001100) | Socket |
For example, the octal file permissions "100644" would indicate a regular file and octal "40755" would indicate a directory.
Size
long (read-only)
Default Value: 0
Specifies the total size, in bytes, of this file.
TextHint
int (read-only)
Default Value: 0
Provides a hint for whether or not the file is a text file.
UntranslatedName
String (read-only)
Default Value: ""
Provides the untranslated name of the file.
SSHPlexOperation Type
This object contains information about a currently running operation.
Remarks
A SSHPlexOperation object is created and added to the Operations collection each time a relevant method is called. The object will be removed from the Operations collection when the operation completes, fails, or is canceled by the CancelOperation method.
Fields
OperationId
String (read-only)
Default Value: ""
This field contains the Id of the currently running operation.
Config Settings (SSHPlex Class)
The class accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.
SFTPClient Config Settings
The default value is False.
The server must support the check-file extension.
The class supports the following hash algorithms (in order of preference): sha256,sha224,sha384,sha512,sha1,md5. The server may choose to use any value from this list. No action is needed to configure the algorithm, the class will automatically use the same algorithm that the server users.
If the extension is unsupported or a mismatch in hashes is detected, the class throws an exception. If the hashes match the value, True is returned.
try {
String flag = sftp.Config("CheckFileHash");
// flag will be equal to "True"
}
catch (Exception e) {
// mismatch
}
Set RemoteFile to the path of the source file. Optionally set StartByte to indicate from where in the source file to start reading.
Then set CopyRemoteData to a semicolon (;) delimited listed of Name=Value pairs. In this list, DestFile must be set to the path of the destination file. Length may be set to the number of bytes to read. WriteOffset may be set to the location in the destination file from where to start writing.
sftp.RemoteFile = "/my/source/file.txt";
sftp.Overwrite = true;
sftp.StartByte = 6;
sftp.Config("CopyRemoteData=DestFile=/my/destination/file.txt;Length=5;WriteOffset=14");
Set RemoteFile to the path of the source file, then set CopyRemoteFile to the path of the destination file. Overwrite controls whether an existing file will be overwritten.
sftp.Overwrite = true;
sftp.RemoteFile = "/my/source/file.txt";
sftp.Config("CopyRemoteFile=" + "/my/destination/file.txt");
Note: The server must understand either the "statvfs@openssh.com" or "space-available" extension for this operation to succeed.
If it is desired to retrieve the attributes of the symbolic link itself, set GetSymlinkAttrs to True before querying FileAttributes.
When uploading or downloading, this value will be compared to ServerEOL. If ServerEOL and LocalEOL are different, the line endings in the file being transferred will be converted to the line endings used by the destination. Line endings will be converted to the value in LocalEOL when downloading. Line endings will be converted to the value in ServerEOL when uploading. If ServerEOL and LocalEOL are the same, no conversion takes place.
The value supplied to this setting must be quoted. For example:
component.Config("LocalEOL=\"" + myEOLSequence + "\"");
Where myEOLSequence is a Cr, Lf, or CrLf character sequence.
Conversion will only happen when TransferMode is set to 1 (ASCII) and ServerEOL and LocalEOL are different.
Note: Setting this value to True will increase the amount of data that are logged.
Most servers that use smaller values will use a maximum SSH packet size of 16KB (16384). To most efficiently communicate with such servers, MaxFileData size should be set to 14745.
Note: Values larger than 64,000 (65,536) may not be respected by some servers (such as OpenSSH) and will result in unexpected behavior. If specifying a value, it is recommended to set a value less than or equal to 65,536.
The default value is 32,768.
string resolvedPath = component.Config("ReadLink=/home/test/mysymlink.txt");
SSH_FXP_REALPATH_NO_CHECK (1) | Server should not check if the path exists. |
SSH_FXP_REALPATH_STAT_IF (2) | Server should return the file/directory attributes if the path exists and is accessible, but should not fail otherwise. |
SSH_FXP_REALPATH_STAT_ALWAYS (3) | Server should return the file/directory attributes if the path exists and is accessible; otherwise, it fails with an error. |
When uploading or downloading, this value will be compared to LocalEOL. If ServerEOL and LocalEOL are different, the line endings in the file being transferred will be converted to the line endings used by the destination. Line endings will be converted to the value in LocalEOL when downloading. Line endings will be converted to the value in ServerEOL when uploading. If ServerEOL and LocalEOL are the same, no conversion takes place.
The value supplied to this setting must be quoted. For example:
component.Config("ServerEOL=\"" + myEOLSequence + "\"");
Where myEOLSequence is a Cr, Lf, or CrLf character sequence.
Conversion will happen only when TransferMode is set to 1 (ASCII) and ServerEOL and LocalEOL are different.
When this value is set to 1 (ASCII) the class will use the values specified in LocalEOL and ServerEOL to convert line endings as appropriate.
Note: When this value is set to 1 (ASCII) and ProtocolVersion is set to 4 or higher the class will automatically determine the value for ServerEOL if the server supports the newline protocol extension.
This configuration setting can be used in conjunction with the StartByte property to download a specific range of data from the current RemoteFile.
Set this to false to not send the packet. This will cause PreserveFileTime to not work and prevent PercentDone in Transfer from being calculated.
The default is true.
SCP Config Settings
When enabled, the class will also populate LastModifiedTime and LastAccessedTime configuration settings. These are applicable only during download and may be used to check the times of the remote file from within the StartTransfer event. To cancel a transfer, call the Interrupt method.
SShell Config Settings
Default is True.
class.Config("EncodedTerminalModes=" + Encoding.Default.GetString(new byte[] { 53,0,0,0,0,0 })");
In this example, the first byte is the opcode (53 for echo). The next 4 bytes represent the opcode value, which is a uint 32. The last byte is always a null character to end the string. This example sets echo to off just as in the example for TerminalModes.
Default is False.
class.Config("TerminalModes=53=0");
In this example, 53 is the opcode (for echo) and the value is 0. So this sets echo to off.
sshell.Config("UpdateTerminalSize");
SExec Config Settings
Default is False.
class.Config("EncodedTerminalModes=" + Encoding.Default.GetString(new byte[] { 53,0,0,0,0,0 })");
In this example, the first byte is the opcode (53 for echo). The next 4 bytes represent the opcode value, which is a uint 32. The last byte is always a null character to end the string. This example sets echo to off just as in the example for TerminalModes.
class.Config("TerminalModes=53=0");
In this example, 53 is the opcode (for echo) and the value is 0. So this sets echo to off.
SSHClient Config Settings
If MaxChannelDataLength is greater than 0 and ChannelDataEOL is a nonempty string, the class will internally buffer data waiting to fire SSHChannelData until either MaxChannelDataLength is reached or ChannelDataEOL is found, whichever comes first. Query ChannelDataEOLFound to know which condition was met. The buffer is reset any time SSHChannelData fires.
ChannelDataEOL and MaxChannelDataLength must be set together or unexpected behavior could occur.
This configuration setting is valid only when queried inside SSHChannelData, MaxChannelDataLength > 0, and ChannelDataEOL is nonempty.
Most SSH servers expect the SSH version string to have the expected format "SSH-protocol version-software version". See above for an example.
Value | Description |
0 (Disabled - default) | No communication with Pageant is attempted. |
1 (Enabled) | Pageant authentication is used if available. If Pageant is not running, or does not contain the expected key, no error is thrown. |
2 (Required) | Only Pageant authentication is used. If Pageant is not running, or does not contain the expected key, an error is thrown. |
Example 1. Enabling Pageant:
component.Config("EnablePageantAuth=1");
component.SSHUser = "sshuser";
component.SSHLogon("localhost", 22);
Note: This functionality is available only on Windows.
Note: Even if the client asks for delegation, the server/KDC might not grant it, and authentication will still succeed.
Example. Setting the Threshold to 500 MB:
SSHComponent.Config("KeyRenegotiationThreshold=524288000")
0 (None) | No messages are logged. |
1 (Info - Default) | Informational events such as Secure Shell (SSH) handshake messages are logged. |
2 (Verbose) | Detailed data such as individual packet information are logged. |
3 (Debug) | Debug data including all relevant sent and received bytes are logged. |
If MaxChannelDataLength is greater than 0 and ChannelDataEOL is a nonempty string, the class will internally buffer data waiting to fire SSHChannelData until either MaxChannelDataLength is reached or ChannelDataEOL is found, whichever comes first. Query ChannelDataEOLFound to know which condition was met. The buffer is reset any time SSHChannelData fires.
ChannelDataEOL and MaxChannelDataLength must be set together or unexpected behavior could occur.
Note: This value may be changed during the connection, but the window size can only be increased, not decreased.
component.Config("NegotiatedStrictKex")
This provides an easy way to automatically reply to prompts with the password if one is presented by the server. The password will be autofilled in the Response parameter of the SSHKeyboardInteractive event in the case of a match.
The following special characters are supported for pattern matching:
? | Any single character. |
* | Any characters or no characters (e.g., C*t matches Cat, Cot, Coast, Ct). |
[,-] | A range of characters (e.g., [a-z], [a], [0-9], [0-9,a-d,f,r-z]). |
\ | The slash is ignored and exact matching is performed on the next character. |
If these characters need to be used as a literal in a pattern, then they must be escaped by surrounding them with brackets []. Note: "]" and "-" do not need to be escaped. See below for the escape sequences:
Character | Escape Sequence |
? | [?] |
* | [*] |
[ | [[] |
\ | [\] |
For example, to match the value [Something].txt, specify the pattern [[]Something].txt.
The default value is 0, meaning this setting is not used.
component.Config("SignedSSHCert=ssh-rsa-cert-v01@openssh.com AAAAB3NzaC1yc2EAAAADAQABAAAB...");
The algorithm such as ssh-rsa-cert-v01@openssh.com in the previous string is used as part of the authentication process. To use a different algorithm, simply change this value. For instance, all of the following are acceptable with the same signed public key:
- ssh-rsa-cert-v01@openssh.com AAAAB3NzaC1yc2EAAAADAQABAAAB...
- rsa-sha2-256-cert-v01@openssh.com AAAAB3NzaC1yc2EAAAADAQABAAAB...
- rsa-sha2-512-cert-v01@openssh.com AAAAB3NzaC1yc2EAAAADAQABAAAB...
component.Config("SSHAcceptServerCAKey=ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...");
SSHClient.Config("SSHAcceptServerHostKeyFingerprint=0a:1b:2c:3d");
If the server's fingerprint matches one of the values supplied, the class will accept the host key.
- MD5
- SHA1
- SHA256 (default)
The default value is 0, meaning no keep alives will be sent.
Note: The SSHReverseTunnel class uses a default value of 30.
- curve25519-sha256
- curve25519-sha256@libssh.org
- diffie-hellman-group1-sha1
- diffie-hellman-group14-sha1
- diffie-hellman-group14-sha256
- diffie-hellman-group16-sha512
- diffie-hellman-group18-sha512
- diffie-hellman-group-exchange-sha256
- diffie-hellman-group-exchange-sha1
- ecdh-sha2-nistp256
- ecdh-sha2-nistp384
- ecdh-sha2-nistp521
- gss-group14-sha256-toWM5Slw5Ew8Mqkay+al2g==
- gss-group16-sha512-toWM5Slw5Ew8Mqkay+al2g==
- gss-nistp256-sha256-toWM5Slw5Ew8Mqkay+al2g==
- gss-curve25519-sha256-toWM5Slw5Ew8Mqkay+al2g==
- gss-group14-sha1-toWM5Slw5Ew8Mqkay+al2g==
- gss-gex-sha1-toWM5Slw5Ew8Mqkay+al2g==
Example 3. Renegotiating SSH Keys:
SSHClient.Config("SSHKeyRenegotiate")
- hmac-sha1
- hmac-md5
- hmac-sha1-96
- hmac-md5-96
- hmac-sha2-256
- hmac-sha2-256-96
- hmac-sha2-512
- hmac-sha2-512-96
- hmac-ripemd160
- hmac-ripemd160-96
- hmac-sha2-256-etm@openssh.com
- hmac-sha2-512-etm@openssh.com
- hmac-sha2-256-96-etm@openssh.com
- hmac-sha2-512-96-etm@openssh.com
- umac-64@openssh.com
- umac-64-etm@openssh.com
- umac-128@openssh.com
- umac-128-etm@openssh.com
The setting should be a comma-separated list of algorithms. At runtime, the class will evaluate the specified algorithms, and if the algorithm is applicable to the certificate specified in SSHCert, it will be used. If the algorithm is not applicable, the class will evaluate the next algorithm. Possible values are as follows:
- ssh-rsa
- rsa-sha2-256
- rsa-sha2-512
- ssh-dss
- ecdsa-sha2-nistp256
- ecdsa-sha2-nistp384
- ecdsa-sha2-nistp521
- ssh-ed25519
- x509v3-sign-rsa
- x509v3-sign-dss
The default value in Windows is ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519.
rsa-sha2-256 and rsa-sha2-512 notes
The class will query the server for supported algorithms when connecting. If the server indicates support for rsa-sha2-256 or rsa-sha2-512 and the algorithm is present in the list defined by this setting (as in the default value), that algorithm will be used instead of ssh-rsa even when ssh-rsa appears first in the list.
For the rsa-sha2-256 and rsa-sha2-512 algorithms to be automatically preferred, the server must support the ext-info-c mechanism. In practice, older servers do not support this, and in that case, ssh-rsa will be used because it appears first in the list. Newer servers do support this mechanism, and in that case, rsa-sha2-256 or rsa-sha2-512 will be used even though it appears after ssh-rsa.
This behavior has been carefully designed to provide maximum compatibility while automatically using more secure algorithms when connecting to servers that support them.
*SSH-1.99-*,*SSH-2.0-*,*SSH-2.99-*
Because both client and server must implement strict key exchange to effectively mitigate the Terrapin attack, the class provides options to further control the behavior in different scenarios. Possible values for this setting are as follows:
0 | Disabled. Strict key exchange is not supported in the class. |
1 (default) | Enabled, but not enforced. This setting enables strict key exchange, but if the remote host does not support strict key exchange the connection is still allowed to continue. |
2 | Enabled, but will reject affected algorithms if the remote host does not support strict key exchange. If the remote host supports strict key exchange, all algorithms may be used. If the remote host does not support strict key exchange, the connection will continue only if the selected encryption and message authentication code (MAC) algorithms are not affected by the Terrapin attack. |
3 | Required. If the remote host does not support strict key exchange, the connection will fail. |
When True (default), the class will wait for a response to the channel close message until the responses have been received, the server closes the connection, or Timeout seconds is reached.
When False, the class will still send the channel close messages, but it will not wait for a response and will proceed to close the connection.
When set to True, the class will initiate the disconnection sequence by sending SSH_MSG_DISCONNECT, but it will not close the connection and instead will wait for the server to close the connection. Setting this to True may be beneficial in circumstances in which many connections are being established, to avoid port exhaustion when sockets are in a TIME_WAIT state. Allowing the server to close the connection avoids the TIME_WAIT state of socket on the client machine.
When set to False (default), the client will close the connection. It is recommended to use this value unless there is a specific need to change it.
TCPClient Config Settings
If the FirewallHost setting is set to a Domain Name, a DNS request is initiated. Upon successful termination of the request, the FirewallHost setting is set to the corresponding address. If the search is not successful, an error is returned.
Note: This setting is provided for use by classs that do not directly expose Firewall properties.
If this entry is set, the class acts as a server. RemoteHost and RemotePort are used to tell the SOCKS firewall in which address and port to listen to. The firewall rules may ignore RemoteHost, and it is recommended that RemoteHost be set to empty string in this case.
RemotePort is the port in which the firewall will listen to. If set to 0, the firewall will select a random port. The binding (address and port) is provided through the ConnectionStatus event.
The connection to the firewall is made by calling the Connect method.
Note: This setting is provided for use by classs that do not directly expose Firewall properties.
Note: This configuration setting is provided for use by classs that do not directly expose Firewall properties.
0 | No firewall (default setting). |
1 | Connect through a tunneling proxy. FirewallPort is set to 80. |
2 | Connect through a SOCKS4 Proxy. FirewallPort is set to 1080. |
3 | Connect through a SOCKS5 Proxy. FirewallPort is set to 1080. |
10 | Connect through a SOCKS4A Proxy. FirewallPort is set to 1080. |
Note: This setting is provided for use by classs that do not directly expose Firewall properties.
Note: This setting is provided for use by classs that do not directly expose Firewall properties.
Note: This value is not applicable in macOS.
In the case that Linger is True (default), two scenarios determine how long the connection will linger. In the first, if LingerTime is 0 (default), the system will attempt to send pending data for a connection until the default IP timeout expires.
In the second scenario, if LingerTime is a positive value, the system will attempt to send pending data until the specified LingerTime is reached. If this attempt fails, then the system will reset the connection.
The default behavior (which is also the default mode for stream sockets) might result in a long delay in closing the connection. Although the class returns control immediately, the system could hold system resources until all pending data are sent (even after your application closes).
Setting this property to False forces an immediate disconnection. If you know that the other side has received all the data you sent (e.g., by a client acknowledgment), setting this property to False might be the appropriate course of action.
In multihomed hosts (machines with more than one IP interface), setting LocalHost to the value of an interface will make the class initiate connections (or accept in the case of server classs) only through that interface.
If the class is connected, the LocalHost setting shows the IP address of the interface through which the connection is made in internet dotted format (aaa.bbb.ccc.ddd). In most cases, this is the address of the local host, except for multihomed hosts (machines with more than one IP interface).
Setting this to 0 (default) enables the system to choose a port at random. The chosen port will be shown by LocalPort after the connection is established.
LocalPort cannot be changed once a connection is made. Any attempt to set this when a connection is active will generate an error.
This configuration setting is useful when trying to connect to services that require a trusted port on the client side. An example is the remote shell (rsh) service in UNIX systems.
If an EOL string is found in the input stream before MaxLineLength bytes are received, the DataIn event is fired with the EOL parameter set to True, and the buffer is reset.
If no EOL is found, and MaxLineLength bytes are accumulated in the buffer, the DataIn event is fired with the EOL parameter set to False, and the buffer is reset.
The minimum value for MaxLineLength is 256 bytes. The default value is 2048 bytes.
www.google.com;www.nsoftware.com
Note: This value is not applicable in Java.
By default, this configuration setting is set to False.
0 | IPv4 only |
1 | IPv6 only |
2 | IPv6 with IPv4 fallback |
Socket Config Settings
Note: This option is not valid for User Datagram Protocol (UDP) ports.
Some TCP/IP implementations do not support variable buffer sizes. If that is the case, when the class is activated the InBufferSize reverts to its defined size. The same happens if you attempt to make it too large or too small.
Some TCP/IP implementations do not support variable buffer sizes. If that is the case, when the class is activated the OutBufferSize reverts to its defined size. The same happens if you attempt to make it too large or too small.
Base Config Settings
In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GUIAvailable to false will ensure that the class does not attempt to process external events.
- Product: The product the license is for.
- Product Key: The key the license was generated from.
- License Source: Where the license was found (e.g., RuntimeLicense, License File).
- License Type: The type of license installed (e.g., Royalty Free, Single Server).
- Last Valid Build: The last valid build number for which the license will work.
This setting only works on these classes: AS3Receiver, AS3Sender, Atom, Client(3DS), FTP, FTPServer, IMAP, OFTPClient, SSHClient, SCP, Server(3DS), Sexec, SFTP, SFTPServer, SSHServer, TCPClient, TCPServer.
The Java edition requires installation of the FIPS-certified Bouncy Castle library regardless of the target operating system. This can be downloaded from https://www.bouncycastle.org/fips-java/. Only the "Provider" library is needed. The jar file should then be installed in a JRE search path.
The following classes must be imported in the application in which the component will be used:
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
The Bouncy Castle provider must be added as a valid provider and must also be configured to operate in FIPS mode:
System.setProperty("org.bouncycastle.fips.approved_only","true");
Security.addProvider(new BouncyCastleFipsProvider());
When UseFIPSCompliantAPI is true, Secure Sockets Layer (SSL)-enabled classes can optionally be configured to use the Transport Layer Security (TLS) Bouncy Castle library. When SSLProvider is set to sslpAutomatic (default) or sslpInternal, an internal TLS implementation is used, but all cryptographic operations are offloaded to the Bouncy Castle FIPS provider to achieve FIPS-compliant operation. If SSLProvider is set to sslpPlatform, the Bouncy Castle JSSE will be used in place of the internal TLS implementation.
To enable the use of the Bouncy Castle JSSE take the following steps in addition to the steps above. Both the Bouncy Castle FIPS provider and the Bouncy Castle JSSE must be configured to use the Bouncy Castle TLS library in FIPS mode. Obtain the Bouncy Castle TLS library from https://www.bouncycastle.org/fips-java/. The jar file should then be installed in a JRE search path.
The following classes must be imported in the application in which the component will be used:
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
//required to use BCJSSE when SSLProvider is set to sslpPlatform
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
The Bouncy Castle provider must be added as a valid provider and also must be configured to operate in FIPS mode:
System.setProperty("org.bouncycastle.fips.approved_only","true");
Security.addProvider(new BouncyCastleFipsProvider());
//required to use BCJSSE when SSLProvider is set to sslpPlatform
Security.addProvider(new BouncyCastleJsseProvider("fips:BCFIPS"));
//optional - configure logging level of BCJSSE
Logger.getLogger("org.bouncycastle.jsse").setLevel(java.util.logging.Level.OFF);
//configure the class to use BCJSSE
component.setSSLProvider(1); //platform
component.config("UseFIPSCompliantAPI=true");
Note: TLS 1.3 support requires the Bouncy Castle TLS library version 1.0.14 or later.
FIPS mode can be enabled by setting the UseFIPSCompliantAPI configuration setting to true. This is a static setting that applies to all instances of all classes of the toolkit within the process. It is recommended to enable or disable this setting once before the component has been used to establish a connection. Enabling FIPS while an instance of the component is active and connected may result in unexpected behavior.
For more details, please see the FIPS 140-2 Compliance article.
Note: Enabling FIPS compliance requires a special license; please contact sales@nsoftware.com for details.
Setting this configuration setting to true tells the class to use the internal implementation instead of using the system security libraries.
This setting is set to false by default on all platforms.
Trappable Errors (SSHPlex Class)
SSHPlex Errors
1039 | Invalid channel type. |
1040 | Operation has been canceled. |
SFTPClient Errors
118 | Firewall error. Error description contains detailed information. |
1102 | The server's SFTP draft version is unsupported. |
1103 | SFTP command failed. Error description contains detailed information. |
1104 | Server does not support renaming. |
1105 | Received invalid response from server. Error description contains detailed information. |
1106 | Cannot resolve path: path does not exist. |
1107 | You must set LocalFile/RemoteFile before attempting to download/upload. |
1108 | Cannot download file: LocalFile exists and Overwrite is set to False. |
1109 | CheckFileHash failed because of hash value mismatch. |
SCP Errors
118 | Firewall error. Error description contains detailed information. |
SExec Errors
1050 | Busy performing other action. |
SShell Errors
1050 | Busy performing another action. |
SSHClient Errors
1001 | Server has disconnected. |
1002 | Protocol version unsupported or other issue with version string. |
1003 | Cannot negotiate algorithms. |
1005 | Selected algorithm unsupported. |
1006 | Cannot set keys. |
1010 | Unexpected algorithm. |
1011 | Cannot create exchange hash. |
1012 | Cannot make key. |
1013 | Cannot sign data. |
1014 | Cannot encrypt packet. |
1015 | Cannot decrypt packet. |
1016 | Cannot decompress packet. |
1020 | Failure to open channel. |
1021 | Invalid channel Id. |
1022 | Invalid channel data. |
1023 | Invalid channel message. |
1024 | SSH message unimplemented. |
1027 | Server message unsupported. |
1030 | Server's host key was rejected. The host key may be accepted within the SSHServerAuthentication event or using the SSHAcceptServerHostKey property. |
1031 | Cannot verify server's host key. |
1032 | Authentication failed. Check description for details. |
1033 | Channel request failed. |
1034 | Diffie-Hellman exchange failed. |
1036 | SSH connection failed. |
1037 | SSH reconnect limit reached. |
1038 | Elliptic curve Diffie-Hellman exchange failed. |
1039 | SSH keep-alive limit reached. |
1098 | Request failure. |
1130 | Would block error. |
1133 | Would block, reason: key reExchange. |
TCPClient Errors
100 | You cannot change the RemotePort at this time. A connection is in progress. |
101 | You cannot change the RemoteHost (Server) at this time. A connection is in progress. |
102 | The RemoteHost address is invalid (0.0.0.0). |
104 | Already connected. If you want to reconnect, close the current connection first. |
106 | You cannot change the LocalPort at this time. A connection is in progress. |
107 | You cannot change the LocalHost at this time. A connection is in progress. |
112 | You cannot change MaxLineLength at this time. A connection is in progress. |
116 | RemotePort cannot be zero. Please specify a valid service port number. |
117 | You cannot change the UseConnection option while the class is active. |
135 | Operation would block. |
201 | Timeout. |
211 | Action impossible in control's present state. |
212 | Action impossible while not connected. |
213 | Action impossible while listening. |
301 | Timeout. |
303 | Could not open file. |
434 | Unable to convert string to selected CodePage. |
1105 | Already connecting. If you want to reconnect, close the current connection first. |
1117 | You need to connect first. |
1119 | You cannot change the LocalHost at this time. A connection is in progress. |
1120 | Connection dropped by remote host. |
TCP/IP Errors
10004 | [10004] Interrupted system call. |
10009 | [10009] Bad file number. |
10013 | [10013] Access denied. |
10014 | [10014] Bad address. |
10022 | [10022] Invalid argument. |
10024 | [10024] Too many open files. |
10035 | [10035] Operation would block. |
10036 | [10036] Operation now in progress. |
10037 | [10037] Operation already in progress. |
10038 | [10038] Socket operation on nonsocket. |
10039 | [10039] Destination address required. |
10040 | [10040] Message is too long. |
10041 | [10041] Protocol wrong type for socket. |
10042 | [10042] Bad protocol option. |
10043 | [10043] Protocol is not supported. |
10044 | [10044] Socket type is not supported. |
10045 | [10045] Operation is not supported on socket. |
10046 | [10046] Protocol family is not supported. |
10047 | [10047] Address family is not supported by protocol family. |
10048 | [10048] Address already in use. |
10049 | [10049] Cannot assign requested address. |
10050 | [10050] Network is down. |
10051 | [10051] Network is unreachable. |
10052 | [10052] Net dropped connection or reset. |
10053 | [10053] Software caused connection abort. |
10054 | [10054] Connection reset by peer. |
10055 | [10055] No buffer space available. |
10056 | [10056] Socket is already connected. |
10057 | [10057] Socket is not connected. |
10058 | [10058] Cannot send after socket shutdown. |
10059 | [10059] Too many references, cannot splice. |
10060 | [10060] Connection timed out. |
10061 | [10061] Connection refused. |
10062 | [10062] Too many levels of symbolic links. |
10063 | [10063] File name is too long. |
10064 | [10064] Host is down. |
10065 | [10065] No route to host. |
10066 | [10066] Directory is not empty |
10067 | [10067] Too many processes. |
10068 | [10068] Too many users. |
10069 | [10069] Disc Quota Exceeded. |
10070 | [10070] Stale NFS file handle. |
10071 | [10071] Too many levels of remote in path. |
10091 | [10091] Network subsystem is unavailable. |
10092 | [10092] WINSOCK DLL Version out of range. |
10093 | [10093] Winsock is not loaded yet. |
11001 | [11001] Host not found. |
11002 | [11002] Nonauthoritative 'Host not found' (try again or check DNS setup). |
11003 | [11003] Nonrecoverable errors: FORMERR, REFUSED, NOTIMP. |
11004 | [11004] Valid name, no data record (check DNS setup). |