# ReadFile

Required Frends version: 5.5+

Required .NET version: 6.0

Compatible Agents: Crossplatform

Source code: <https://github.com/FrendsPlatform/Frends.SFTP/tree/main/Frends.SFTP.ReadFile>

{% tabs %}
{% tab title="Parameter: Input" %}

| Name                          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Path : `String`               | <p>Full path of the target file to be read.</p><p><br>Default: <code>/</code><br>Example: <code>/destination</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| FileEncoding : `FileEncoding` | <p>Encoding for the read content.</p><p>By selecting 'Other' you can use any encoding.</p><p>Possible values:</p><ul><li><code>UTF8</code>:</li></ul><p>Encoding for the read content.</p><p>By selecting 'Other' you can use any encoding.</p><ul><li><code>ANSI</code>:</li></ul><p>Encoding for the read content.</p><p>By selecting 'Other' you can use any encoding.</p><ul><li><code>ASCII</code>:</li></ul><p>Encoding for the read content.</p><p>By selecting 'Other' you can use any encoding.</p><ul><li><code>WINDOWS1252</code>:</li></ul><p>Encoding for the read content.</p><p>By selecting 'Other' you can use any encoding.</p><ul><li><code>Unicode</code>:</li></ul><p>Encoding for the read content.</p><p>By selecting 'Other' you can use any encoding.</p><ul><li><code>Other</code>:</li></ul><p>Encoding for the read content.</p><p>By selecting 'Other' you can use any encoding.</p><p><br>Default: <code>1</code><br>Example: <code>FileEncoding.ANSI</code></p> |
| EnableBom : `Boolean`         | <p>Additional option for UTF-8 encoding to enable bom.</p><p><br>Default: <code>False</code><br>Example: <code>true</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| EncodingInString : `String`   | <p>File encoding to be used.</p><p>Encoding don't support any unicode encoding. It only support the code page encodings.</p><p>A partial list of possible encodings: <https://en.wikipedia.org/wiki/Windows_code_page#List>.</p><p><br>Default: <code>-</code><br>Example: <code>iso-8859-1</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| {% endtab %}                  |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

{% tab title="Parameter: Connection" %}

| Name                                             | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ConnectionTimeout : `Int32`                      | <p>The lenght of time, in seconds, until the connection times out.</p><p>You can use value -1 to indicate that the connection does not time out.</p><p>Default value is 60 seconds.</p><p><br>Default: <code>60</code><br>Example: <code>60</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| Address : `String`                               | <p>SFTP host address</p><p><br>Default: <code>-</code><br>Example: <code>localhost</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Port : `Int32`                                   | <p>Port number to use in the connection to the server.</p><p><br>Default: <code>22</code><br>Example: <code>22</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| Authentication : `AuthenticationType`            | <p>Selection for authentication type</p><p>Possible values:</p><ul><li><code>UsernamePassword</code>:</li></ul><p>Selection for authentication type</p><ul><li><code>UsernamePrivateKeyFile</code>:</li></ul><p>Selection for authentication type</p><ul><li><code>UsernamePrivateKeyString</code>:</li></ul><p>Selection for authentication type</p><ul><li><code>UsernamePasswordPrivateKeyFile</code>:</li></ul><p>Selection for authentication type</p><ul><li><code>UsernamePasswordPrivateKeyString</code>:</li></ul><p>Selection for authentication type</p><p><br>Default: <code>-</code><br>Example: <code>AuthenticationType.UsernamePassword</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Username : `String`                              | <p>Username to use for authentication to the server. Note that the file endpoint only supports</p><p>username for remote shares and the username must be in the format DOMAIN\Username.</p><p><br>Default: <code>-</code><br>Example: <code>foo</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| 🗝Password : `String`                            | <p>Password to use in the authentication to the server.</p><p><br>Default: <code>-</code><br>Example: <code>pass</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| PrivateKeyFile : `String`                        | <p>Full path to private key file. Supported private key formats: OpenSSH and ssh.com.</p><p>PuTTY keys can be converted with puttygen.exe application.</p><p>1. Load your key file into puttygen.exe</p><p>2. Conversion > Export OpenSSH key (not the "force new file format" option)</p><p><br>Default: <code>-</code><br>Example: <code>C:\path\to\private\key</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| 🗝PrivateKeyString : `String`                    | <p>Private key as a string, supported private key formats: OpenSSH and ssh.com.</p><p>PuTTY keys can be converted with puttygen.exe application.</p><p>1. Load your key file into puttygen.exe</p><p>2. Conversion > Export OpenSSH key (not the "force new file format" option)</p><p><br>Default: <code>-</code><br>Example: <code>-----BEGIN RSA PRIVATE KEY----- Fqxq2jbSKyb0a+oW96Tjoif3Kcb5zZ0FiQyiHgQozLXrecjdUwjWuedkDoZMxwG5 bxpOnxZ/88tDzYCtCPcYCPRF8BNueUsZO8/tztTra+4NgVd/omXHG5bqb7iMB4dc ... OX7Q/wO4lqOlFhLtRnSL0cfuhRmt59pM75Zd+euX5tv9jmCj+AQT/kiBoMhNrDGk N2gTujnH7HCr/afSBeL3xnYcEmeCQTxTPZofBjPC+TPd9g7MntSGBeU/Fstv0jbg -----END RSA PRIVATE KEY-----</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| 🗝PrivateKeyPassphrase : `String`                | <p>Passphrase for the private key file.</p><p><br>Default: <code>-</code><br>Example: <code>passphrase</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ServerFingerPrint : `String`                     | <p>Fingerprint of the SFTP server. When using "Username-Password"</p><p>authentication it is recommended to use server fingerprint in</p><p>order to be sure of the server you are connecting.</p><p><br>Default: <code>-</code><br>Example: <code>MD5: '41:76:EA:65:62:6E:D3:68:DC:41:9A:F2:F2:20:69:9D' SHA256: 'FBQn5eyoxpAl33Ly0gyScCGAqZeMVsfY7qss3KOM/hY='</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| HostKeyAlgorithm : `HostKeyAlgorithms`           | <p>Host key algorithm to use when connecting to server.</p><p>Default value is Any which doesn't force the task to use</p><p>specific algorithm.</p><p>Possible values:</p><ul><li><code>Any</code>:</li></ul><p>Host key algorithm to use when connecting to server.</p><p>Default value is Any which doesn't force the task to use</p><p>specific algorithm.</p><ul><li><code>RSA</code>:</li></ul><p>Host key algorithm to use when connecting to server.</p><p>Default value is Any which doesn't force the task to use</p><p>specific algorithm.</p><ul><li><code>Ed25519</code>:</li></ul><p>Host key algorithm to use when connecting to server.</p><p>Default value is Any which doesn't force the task to use</p><p>specific algorithm.</p><ul><li><code>nistp256</code>:</li></ul><p>Host key algorithm to use when connecting to server.</p><p>Default value is Any which doesn't force the task to use</p><p>specific algorithm.</p><ul><li><code>nistp384</code>:</li></ul><p>Host key algorithm to use when connecting to server.</p><p>Default value is Any which doesn't force the task to use</p><p>specific algorithm.</p><ul><li><code>nistp521</code>:</li></ul><p>Host key algorithm to use when connecting to server.</p><p>Default value is Any which doesn't force the task to use</p><p>specific algorithm.</p><p><br>Default: <code>0</code><br>Example: <code>HostKeyAlgorithms.RSA</code></p> |
| UseKeyboardInteractiveAuthentication : `Boolean` | <p>Enable if the server uses keyboard-interactive authentication method.</p><p><br>Default: <code>False</code><br>Example: <code>false</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| PromptAndResponse : `PromptResponse[]`           | <p>Responses for the server prompts when using Keyboard Interactive authentication method.</p><p><br>Default: <code>-</code><br>Example: <code>-</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| BufferSize : `UInt32`                            | <p>Integer value of used buffer size as KB.</p><p>Default value is 32 KB.</p><p><br>Default: <code>32</code><br>Example: <code>32</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| {% endtab %}                                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

{% tab title="Parameter: Options" %}

| Name                        | Description                                                                                                                                                                                                                                                                                                                                                                                                                      |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ContentType : `ContentType` | <p>Determines if the content of the file is returned as string or byte array.</p><p>Possible values:</p><ul><li><code>Binary</code>:</li></ul><p>Determines if the content of the file is returned as string or byte array.</p><ul><li><code>Text</code>:</li></ul><p>Determines if the content of the file is returned as string or byte array.</p><p><br>Default: <code>2</code><br>Example: <code>ContentType.Text</code></p> |
| {% endtab %}                |                                                                                                                                                                                                                                                                                                                                                                                                                                  |

{% tab title="Result: Result" %}

| Name                       | Description                                                                                       |
| -------------------------- | ------------------------------------------------------------------------------------------------- |
| BinaryContent : `Byte[]`   | <p>Content of the file as a byte array.<br>Example: <code>\[1, 2, 3]</code></p>                   |
| TextContent : `String`     | <p>Content of the file in string format.<br>Example: <code>This is a test file</code></p>         |
| Path : `String`            | <p>Full name of the file.<br>Example: <code>c:\source\Test.txt</code></p>                         |
| SizeInMegaBytes : `Double` | <p>Size of the read file.<br>Example: <code>0</code></p>                                          |
| LastWriteTime : `DateTime` | <p>Timestamp of when the file was last modified.<br>Example: <code>06/14/2022 09:45:28</code></p> |
| {% endtab %}               |                                                                                                   |

{% tab title="Changelog" %}

## Changelog

### \[3.1.0] - 2026-02-05

#### Added

* Added support for binary files

### \[3.0.0] - 2026-01-27

#### Changed

**Breaking changes!**

* Updated dependency SSH.NET to the newest version 2025.1.0.
* Drop DSS support

### \[2.4.0] - 2026-01-13

#### Fixed

* Operation timeout is now using the Connection.ConnectionTimeout parameter.

### \[2.3.0] - 2025-01-10

#### Fixed

* Fixed issue with ConnectionInfoBuilder having static properties for connection and input parameters which lead to Task not being thread safe.

### \[2.2.0] - 2024-08-19

#### Updated

* Updated Renci.SshNet library to version 2024.1.0.

### \[2.1.0] - 2023-12-22

#### Updated

* \[Breaking] Updated dependency SSH.NET to the newest version 2023.0.0.

#### Changed

* Changed connection info builder to create the connection info as it's done in DownloadFiles.
* \[Breaking] Changed PrivateKeyFilePassphrase parameter to PrivateKeyPassphrase and enabled it when PrivateKeyString was used.

### \[2.0.1] - 2022-12-01

#### Updated

* Updated dependency Microsoft.Extensions.DependencyInjection to the newest version.

### \[2.0.0] - 2022-11-09

#### Added

* Added keyboard authentication method
* \[Breaking] Added parameter for keyboard authentication
* Added more tests e.g. Serverfingerprint tests
* Added System.Text.CodePages NuGet to the project
* Added ConnectionInfoBuilder
* Added HostKeyAlgorithm enum

### \[1.0.2] - 2022-06-23

#### Changed

* Changed the main method to read from a file.
* Updated tests

### \[1.0.1] - 2022-06-20

#### Changed

* SSH.NET version upgrade from 2020.0.1 to 2020.0.2

### \[1.0.0] - 2022-03-25

#### Added

* Initial implementation
  {% endtab %}
  {% endtabs %}
