The Ssh class allows you to connect to a remote computer using ssh, scp and sftp commands. More...
The PRIMER JavaScript API provides many class constants, properties and methods. For Arup to
be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase
or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you
should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your
own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:
| Name | Description |
| Ssh.SETGROUP_BIT | Set group bit |
| Ssh.SETUID_BIT | Set uid bit |
| Ssh.STICKY_BIT | sticky bit |
| Name | Description |
| Ssh.DIRECTORY | Directory |
| Ssh.FILE | Regular file |
| Ssh.SOCKET | Socket |
| Ssh.SYMBOLIC_LINK | Symbolic link |
Detailed DescriptionThe Ssh class gives you simple functions to do secure connections to a remote computer using ssh.
Oasys LS-DYNA Environment software is built with the OpenSSH library to support the ssh, scp and sftp protocols.
The basic workflow is to create a connection using the Ssh constructor,
authenticate the connection either by using a password and AuthenticateWithPassword
or with a public key and AuthenticateWithPublicKey then the method
Execute can be used to execute commands on the remote machine, the methods
Get and Put can be used to copy files to and from the
remote machine using scp, and the commands SftpGet, SftpList,
SftpMkdir, SftpPut and
SftpRmdir can be used to perform secure file transfer commands. |
Constructornew Ssh(hostname[string], username[string])DescriptionCreate a new Ssh object for secure communication to a remote computer. |
The hostname of the machine that you want to connect to
The username on the machine that you want to connect to
ReturnsSsh object Return typeSsh |
ExampleTo create a connection to machine "example" as user "username" var s = new Ssh("example", "username");
|
Details of functionsAuthenticateWithPassword(password[string])DescriptionAuthenticate the connection using password. |
The password for the username on the remote machine
Returnsno return value |
The passphrase for authentication on the remote machine if required
Returnsno return value |
ExampleAuthenticate using your public key in SSH connection s: s.AuthenticateWithPublicKey();
|
Execute(data[object])DescriptionExecute a command in the ssh session and get the standard output and error streams. |
Execute data
Object has the following properties:
| Name | Type | Description |
| arguments (optional) | Array of strings | The arguments to pass to the command |
| command | string | The command you want to run |
Returns |
Object with the following properties:
| Name | Type | Description |
| status | integer | The exit code from the command |
| stderr | string | The standard error output from the command |
| stdout | string | The standard output from the command |
object
Get(remote[string], local[string])DescriptionGets a file from the ssh connection using scp. |
The path of the remote file to get
The path of the local file to write
Returnsno return value |
ExampleTo get the remote file "/path/to/file.txt", creating local file "C:\path\to\file.txt" in SSH connection s: s.Get("/path/to/file.txt", "C:\\path\\to\\file.txt");
|
Put(remote[string], local[string])DescriptionPuts a file on the remote ssh connection using scp. |
The path of the remote file to put
The path of the local file to read
Returnsno return value |
ExampleTo put the local file "C:\path\to\file.txt" to remote file "/path/to/file.txt" in SSH connection s: s.Put("/path/to/file.txt", "C:\\path\\to\\file.txt");
|
SftpGet(remote[string], local[string])DescriptionGets a file from the ssh connection using sftp. |
The path of the remote file to get
The path of the local file to write
Returnsno return value |
ExampleTo get the remote file "file.txt", creating local file "C:\path\to\file.txt" in SSH connection s using sftp: s.SftpGet("file.txt", "C:\\path\\to\\file.txt");
|
SftpList(remote[string])DescriptionGets a listing from the ssh connection using sftp. |
The remote path to get the listing from
Returns |
Array of objects. Each object contains the following information for a file/directory:
| Name | Type | Description |
| atime | integer | Access time for the file (seconds since epoch) |
| gid | integer | The group ID |
| info | constant | Bitwise information for the file/directory. See the permissions, file types and file bits constants |
| mtime | integer | Modification time for the file (seconds since epoch) |
| name | string | The name of the file/directory |
| size | integer | The size of the file |
| uid | integer | The user ID |
object
SftpMkdir(remote[string], mode[constant])DescriptionCreates a directory in the remote ssh connection using sftp. |
The remote directory to create
The mode/permissions for the directory. See the permissions constants for details. Note that the user's file-creation mask (umask) value will also be taken into account when creating the directory.
Returnstrue if successful, false if not Return typeBoolean |
SftpPut(remote[string], local[string])DescriptionPuts a file on the remote ssh connection using sftp. |
The path of the remote file to put
The path of the local file to read
Returnsno return value |
ExampleTo put the local file "C:\path\to\file.txt" to remote file "file.txt" in SSH connection s: s.SftpPut("file.txt", "C:\\path\\to\\file.txt");
|
SftpRmdir(remote[string])DescriptionDeletes a directory in the remote ssh connection using sftp. If this fails it is probably because the directory is not empty. |
The remote directory to delete
Returnstrue if successful, false if not Return typeBoolean |
ExampleTo delete the remote path "temp" in SSH connection s using sftp: var success = s.SftpRmdir("temp");
|