|  | 
|  | 1 | +--- | 
|  | 2 | +type: docs | 
|  | 3 | +title: "SFTP binding spec" | 
|  | 4 | +linkTitle: "SFTP" | 
|  | 5 | +description: "Detailed documentation on the Secure File Transfer Protocol (SFTP) binding component" | 
|  | 6 | +aliases: | 
|  | 7 | +  - "/operations/components/setup-bindings/supported-bindings/sftp/" | 
|  | 8 | +--- | 
|  | 9 | + | 
|  | 10 | +## Component format | 
|  | 11 | + | 
|  | 12 | +To set up the SFTP binding, create a component of type `bindings.sftp`. See [this guide]({{ ref bindings-overview.md }}) on how to create and apply a binding configuration. | 
|  | 13 | + | 
|  | 14 | +```yaml | 
|  | 15 | +apiVersion: dapr.io/v1alpha1 | 
|  | 16 | +kind: Component | 
|  | 17 | +metadata: | 
|  | 18 | +  name: <NAME> | 
|  | 19 | +spec: | 
|  | 20 | +  type: bindings.sftp | 
|  | 21 | +  version: v1 | 
|  | 22 | +  metadata: | 
|  | 23 | +  - name: rootPath | 
|  | 24 | +    value: "<string>" | 
|  | 25 | +  - name: address | 
|  | 26 | +    value: "<string>" | 
|  | 27 | +  - name: username | 
|  | 28 | +    value: "<string>" | 
|  | 29 | +  - name: password | 
|  | 30 | +    value: "*****************" | 
|  | 31 | +  - name: privateKey | 
|  | 32 | +    value: "*****************" | 
|  | 33 | +  - name: privateKeyPassphrase | 
|  | 34 | +    value: "*****************" | 
|  | 35 | +  - name: hostPublicKey | 
|  | 36 | +    value: "*****************" | 
|  | 37 | +  - name: knownHostsFile | 
|  | 38 | +    value: "<string>" | 
|  | 39 | +  - name: insecureIgnoreHostKey | 
|  | 40 | +    value: "<bool>" | 
|  | 41 | +``` | 
|  | 42 | +
 | 
|  | 43 | +## Spec metadata fields | 
|  | 44 | +
 | 
|  | 45 | +| Field              | Required | Binding support |  Details | Example | | 
|  | 46 | +|--------------------|:--------:|------------|-----|---------| | 
|  | 47 | +| `rootPath` | Y | Output | Root path for default working directory | `"/path"` | | 
|  | 48 | +| `address`             | Y        | Output |  Address of SFTP server | `"localhost:22"` | | 
|  | 49 | +| `username`           | Y        | Output | Username for authentication | `"username"` | | 
|  | 50 | +| `password`          | N        | Output | Password for username/password authentication | `"password"` | | 
|  | 51 | +| `privateKey`          | N        | Output | Private key for public key authentication | <pre>"\|-<br>-----BEGIN OPENSSH PRIVATE KEY-----<br>*****************<br>-----END OPENSSH PRIVATE KEY-----"</pre> | | 
|  | 52 | +| `privateKeyPassphrase`       | N        | Output | Private key passphrase for public key authentication | `"passphrase"`    | | 
|  | 53 | +| `hostPublicKey`       | N        | Output | Host public key for host validation | `"ecdsa-sha2-nistp256 *** root@openssh-server"`    | | 
|  | 54 | +| `knownHostsFile`       | N        | Output | Known hosts file for host validation | `"/path/file"` | | 
|  | 55 | +| `insecureIgnoreHostKey`       | N        | Output | Allows to skip host validation. Defaults to `"false"` | `"true"`, `"false"` | | 
|  | 56 | + | 
|  | 57 | +## Binding support | 
|  | 58 | + | 
|  | 59 | +This component supports **output binding** with the following operations: | 
|  | 60 | + | 
|  | 61 | +- `create` : [Create file](#create-file) | 
|  | 62 | +- `get` : [Get file](#get-file) | 
|  | 63 | +- `list` : [List files](#list-files) | 
|  | 64 | +- `delete` : [Delete file](#delete-file) | 
|  | 65 | + | 
|  | 66 | +### Create file | 
|  | 67 | + | 
|  | 68 | +To perform a create file operation, invoke the SFTP binding with a `POST` method and the following JSON body: | 
|  | 69 | + | 
|  | 70 | +```json | 
|  | 71 | +{ | 
|  | 72 | +  "operation": "create", | 
|  | 73 | +  "data": "<YOUR_BASE_64_CONTENT>", | 
|  | 74 | +  "metadata": { | 
|  | 75 | +    "fileName": "<filename>", | 
|  | 76 | +  } | 
|  | 77 | +} | 
|  | 78 | +``` | 
|  | 79 | + | 
|  | 80 | +#### Example | 
|  | 81 | + | 
|  | 82 | +{{< tabs Windows Linux >}} | 
|  | 83 | + | 
|  | 84 | +  {{% codetab %}} | 
|  | 85 | +  ```bash | 
|  | 86 | +  curl -d "{ \"operation\": \"create\", \"data\": \"YOUR_BASE_64_CONTENT\", \"metadata\": { \"fileName\": \"my-test-file.jpg\" } }" http://localhost:<dapr-port>/v1.0/bindings/<binding-name> | 
|  | 87 | +  ``` | 
|  | 88 | +  {{% /codetab %}} | 
|  | 89 | + | 
|  | 90 | +  {{% codetab %}} | 
|  | 91 | +  ```bash | 
|  | 92 | +  curl -d '{ "operation": "create", "data": "YOUR_BASE_64_CONTENT", "metadata": { "fileName": "my-test-file.jpg" } }' \ | 
|  | 93 | +        http://localhost:<dapr-port>/v1.0/bindings/<binding-name> | 
|  | 94 | +  ``` | 
|  | 95 | +  {{% /codetab %}} | 
|  | 96 | + | 
|  | 97 | +{{< /tabs >}} | 
|  | 98 | + | 
|  | 99 | +#### Response | 
|  | 100 | + | 
|  | 101 | +The response body contains the following JSON: | 
|  | 102 | + | 
|  | 103 | +```json | 
|  | 104 | +{ | 
|  | 105 | +   "fileName": "<filename>" | 
|  | 106 | +} | 
|  | 107 | +
 | 
|  | 108 | +``` | 
|  | 109 | + | 
|  | 110 | +### Get file | 
|  | 111 | + | 
|  | 112 | +To perform a get file operation, invoke the SFTP binding with a `POST` method and the following JSON body: | 
|  | 113 | + | 
|  | 114 | +```json | 
|  | 115 | +{ | 
|  | 116 | +  "operation": "get", | 
|  | 117 | +  "metadata": { | 
|  | 118 | +    "fileName": "<filename>" | 
|  | 119 | +  } | 
|  | 120 | +} | 
|  | 121 | +``` | 
|  | 122 | + | 
|  | 123 | +#### Example | 
|  | 124 | + | 
|  | 125 | +{{< tabs Windows Linux >}} | 
|  | 126 | + | 
|  | 127 | +  {{% codetab %}} | 
|  | 128 | +  ```bash | 
|  | 129 | +  curl -d '{ \"operation\": \"get\", \"metadata\": { \"fileName\": \"filename\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name> | 
|  | 130 | +  ``` | 
|  | 131 | +  {{% /codetab %}} | 
|  | 132 | + | 
|  | 133 | +  {{% codetab %}} | 
|  | 134 | +  ```bash | 
|  | 135 | +  curl -d '{ "operation": "get", "metadata": { "fileName": "filename" }}' \ | 
|  | 136 | +        http://localhost:<dapr-port>/v1.0/bindings/<binding-name> | 
|  | 137 | +  ``` | 
|  | 138 | +  {{% /codetab %}} | 
|  | 139 | + | 
|  | 140 | +{{< /tabs >}} | 
|  | 141 | + | 
|  | 142 | +#### Response | 
|  | 143 | + | 
|  | 144 | +The response body contains the value stored in the file. | 
|  | 145 | + | 
|  | 146 | +### List files | 
|  | 147 | + | 
|  | 148 | +To perform a list files operation, invoke the SFTP binding with a `POST` method and the following JSON body: | 
|  | 149 | + | 
|  | 150 | +```json | 
|  | 151 | +{ | 
|  | 152 | +  "operation": "list" | 
|  | 153 | +} | 
|  | 154 | +``` | 
|  | 155 | + | 
|  | 156 | +If you only want to list the files beneath a particular directory below the `rootPath`, specify the relative directory name as the `fileName` in the metadata. | 
|  | 157 | + | 
|  | 158 | +```json | 
|  | 159 | +{ | 
|  | 160 | +  "operation": "list", | 
|  | 161 | +  "metadata": { | 
|  | 162 | +    "fileName": "my/cool/directory" | 
|  | 163 | +  } | 
|  | 164 | +} | 
|  | 165 | +``` | 
|  | 166 | + | 
|  | 167 | +#### Example | 
|  | 168 | + | 
|  | 169 | +{{< tabs Windows Linux >}} | 
|  | 170 | + | 
|  | 171 | +  {{% codetab %}} | 
|  | 172 | +  ```bash | 
|  | 173 | +  curl -d '{ \"operation\": \"list\", \"metadata\": { \"fileName\": \"my/cool/directory\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name> | 
|  | 174 | +  ``` | 
|  | 175 | +  {{% /codetab %}} | 
|  | 176 | + | 
|  | 177 | +  {{% codetab %}} | 
|  | 178 | +  ```bash | 
|  | 179 | +  curl -d '{ "operation": "list", "metadata": { "fileName": "my/cool/directory" }}' \ | 
|  | 180 | +        http://localhost:<dapr-port>/v1.0/bindings/<binding-name> | 
|  | 181 | +  ``` | 
|  | 182 | +  {{% /codetab %}} | 
|  | 183 | + | 
|  | 184 | +{{< /tabs >}} | 
|  | 185 | + | 
|  | 186 | +#### Response | 
|  | 187 | + | 
|  | 188 | +The response is a JSON array of file names. | 
|  | 189 | + | 
|  | 190 | +### Delete file | 
|  | 191 | + | 
|  | 192 | +To perform a delete file operation, invoke the SFTP binding with a `POST` method and the following JSON body: | 
|  | 193 | + | 
|  | 194 | +```json | 
|  | 195 | +{ | 
|  | 196 | +  "operation": "delete", | 
|  | 197 | +  "metadata": { | 
|  | 198 | +    "fileName": "myfile" | 
|  | 199 | +  } | 
|  | 200 | +} | 
|  | 201 | +``` | 
|  | 202 | + | 
|  | 203 | +#### Example | 
|  | 204 | + | 
|  | 205 | +{{< tabs Windows Linux >}} | 
|  | 206 | + | 
|  | 207 | +  {{% codetab %}} | 
|  | 208 | +  ```bash | 
|  | 209 | +  curl -d '{ \"operation\": \"delete\", \"metadata\": { \"fileName\": \"myfile\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name> | 
|  | 210 | +  ``` | 
|  | 211 | +  {{% /codetab %}} | 
|  | 212 | + | 
|  | 213 | +  {{% codetab %}} | 
|  | 214 | +  ```bash | 
|  | 215 | +  curl -d '{ "operation": "delete", "metadata": { "fileName": "myfile" }}' \ | 
|  | 216 | +        http://localhost:<dapr-port>/v1.0/bindings/<binding-name> | 
|  | 217 | +  ``` | 
|  | 218 | +  {{% /codetab %}} | 
|  | 219 | + | 
|  | 220 | +{{< /tabs >}} | 
|  | 221 | + | 
|  | 222 | +#### Response | 
|  | 223 | + | 
|  | 224 | +An HTTP 204 (No Content) and empty body is returned if successful. | 
|  | 225 | + | 
|  | 226 | +## Related links | 
|  | 227 | + | 
|  | 228 | +- [Basic schema for a Dapr component]({{< ref component-schema >}}) | 
|  | 229 | +- [Bindings building block]({{< ref bindings >}}) | 
|  | 230 | +- [How-To: Use bindings to interface with external resources]({{< ref howto-bindings.md >}}) | 
|  | 231 | +- [Bindings API reference]({{< ref bindings_api.md >}}) | 
0 commit comments