|
|
@@ -6,36 +6,65 @@ SSH.NET is a Secure Shell (SSH-2) library for .NET, optimized for parallelism.
|
|
|
[](https://www.nuget.org/packages/SSH.NET)
|
|
|
[](https://ci.appveyor.com/api/projects/status/ih77qu6tap3o92gu/branch/develop)
|
|
|
|
|
|
-## Introduction
|
|
|
+## Key Features
|
|
|
|
|
|
-This project was inspired by **Sharp.SSH** library which was ported from java and it seems like was not supported
|
|
|
-for quite some time. This library is a complete rewrite, without any third party dependencies, using parallelism
|
|
|
-to achieve the best performance possible.
|
|
|
+* Execution of SSH command using both synchronous and asynchronous methods
|
|
|
+* SFTP functionality for both synchronous and asynchronous operations
|
|
|
+* SCP functionality
|
|
|
+* Remote, dynamic and local port forwarding
|
|
|
+* Interactive shell/terminal implementation
|
|
|
+* Authentication via publickey, password and keyboard-interactive methods, including multi-factor
|
|
|
+* Connection via SOCKS4, SOCKS5 or HTTP proxy
|
|
|
|
|
|
-## Documentation
|
|
|
+## How to Use
|
|
|
|
|
|
-Documentation is hosted at https://sshnet.github.io/SSH.NET/. Currently (4/18/2020), the documentation is very sparse.
|
|
|
-Fortunately, there are a large number of [tests](https://github.com/sshnet/SSH.NET/tree/develop/test/) that demonstrate usage with working code.
|
|
|
-If the test for the functionality you would like to see documented is not complete, then you are cordially
|
|
|
-invited to read the source, Luke, and highly encouraged to generate a pull request for the implementation of
|
|
|
-the missing test once you figure things out. 🤓
|
|
|
+### Run a command
|
|
|
|
|
|
-## Features
|
|
|
+```cs
|
|
|
+using (var client = new SshClient("sftp.foo.com", "guest", new PrivateKeyFile("path/to/my/key")))
|
|
|
+{
|
|
|
+ client.Connect();
|
|
|
+ using SshCommand cmd = client.RunCommand("echo 'Hello World!'");
|
|
|
+ Console.WriteLine(cmd.Result); // "Hello World!\n"
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
-* Execution of SSH command using both synchronous and asynchronous methods
|
|
|
-* Return command execution exit status and other information
|
|
|
-* Provide SFTP functionality for both synchronous and asynchronous operations
|
|
|
-* Provides SCP functionality
|
|
|
-* Provide status report for upload and download sftp operations to allow accurate progress bar implementation
|
|
|
-* Remote, dynamic and local port forwarding
|
|
|
-* Shell/Terminal implementation
|
|
|
-* Specify key file pass phrase
|
|
|
-* Use multiple key files to authenticate
|
|
|
-* Supports publickey, password and keyboard-interactive authentication methods
|
|
|
-* Supports two-factor or higher authentication
|
|
|
-* Supports SOCKS4, SOCKS5 and HTTP Proxy
|
|
|
+### Upload and list files using SFTP
|
|
|
+
|
|
|
+```cs
|
|
|
+using (var client = new SftpClient("sftp.foo.com", "guest", "pwd"))
|
|
|
+{
|
|
|
+ client.Connect();
|
|
|
+
|
|
|
+ using (FileStream fs = File.OpenRead(@"C:\tmp\test-file.txt"))
|
|
|
+ {
|
|
|
+ client.UploadFile(fs, "/home/guest/test-file.txt");
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (ISftpFile file in client.ListDirectory("/home/guest/"))
|
|
|
+ {
|
|
|
+ Console.WriteLine($"{file.FullName} {file.LastWriteTime}");
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+## Main Types
|
|
|
+
|
|
|
+The main types provided by this library are:
|
|
|
+
|
|
|
+* Renci.SshNet.SshClient
|
|
|
+* Renci.SshNet.SftpClient
|
|
|
+* Renci.SshNet.ScpClient
|
|
|
+* Renci.SshNet.PrivateKeyFile
|
|
|
+* Renci.SshNet.SshCommand
|
|
|
+* Renci.SshNet.ShellStream
|
|
|
+
|
|
|
+## Additional Documentation
|
|
|
|
|
|
-## Encryption Method
|
|
|
+* [Further examples](https://sshnet.github.io/SSH.NET/examples.html)
|
|
|
+* [API browser](https://sshnet.github.io/SSH.NET/api/Renci.SshNet.html)
|
|
|
+
|
|
|
+## Encryption Methods
|
|
|
|
|
|
**SSH.NET** supports the following encryption methods:
|
|
|
* aes128-ctr
|
|
|
@@ -57,7 +86,7 @@ the missing test once you figure things out. 🤓
|
|
|
* arcfour256
|
|
|
* cast128-cbc
|
|
|
|
|
|
-## Key Exchange Method
|
|
|
+## Key Exchange Methods
|
|
|
|
|
|
**SSH.NET** supports the following key exchange methods:
|
|
|
* curve25519-sha256
|
|
|
@@ -131,41 +160,6 @@ Private keys can be encrypted using one of the following cipher methods:
|
|
|
* .NET Standard 2.0 and 2.1
|
|
|
* .NET 6 (and higher)
|
|
|
|
|
|
-## Usage
|
|
|
-
|
|
|
-### Multi-factor authentication
|
|
|
-
|
|
|
-Establish a SFTP connection using both password and public-key authentication:
|
|
|
-
|
|
|
-```cs
|
|
|
-var connectionInfo = new ConnectionInfo("sftp.foo.com",
|
|
|
- "guest",
|
|
|
- new PasswordAuthenticationMethod("guest", "pwd"),
|
|
|
- new PrivateKeyAuthenticationMethod("rsa.key"));
|
|
|
-using (var client = new SftpClient(connectionInfo))
|
|
|
-{
|
|
|
- client.Connect();
|
|
|
-}
|
|
|
-
|
|
|
-```
|
|
|
-
|
|
|
-### Verify host identify
|
|
|
-
|
|
|
-Establish a SSH connection using user name and password, and reject the connection if the fingerprint of the server does not match the expected fingerprint:
|
|
|
-
|
|
|
-```cs
|
|
|
-string expectedFingerPrint = "LKOy5LvmtEe17S4lyxVXqvs7uPMy+yF79MQpHeCs/Qo";
|
|
|
-
|
|
|
-using (var client = new SshClient("sftp.foo.com", "guest", "pwd"))
|
|
|
-{
|
|
|
- client.HostKeyReceived += (sender, e) =>
|
|
|
- {
|
|
|
- e.CanTrust = expectedFingerPrint.Equals(e.FingerPrintSHA256);
|
|
|
- };
|
|
|
- client.Connect();
|
|
|
-}
|
|
|
-```
|
|
|
-
|
|
|
## Building the library
|
|
|
|
|
|
The library has no special requirements to build, other than an up-to-date .NET SDK. See also [CONTRIBUTING.md](https://github.com/sshnet/SSH.NET/blob/develop/CONTRIBUTING.md).
|