SFTP 绑定规范
关于安全文件传输协议(SFTP)绑定组件的详细文档
组件格式
要配置 SFTP 绑定,创建一个类型为 bindings.sftp
的组件。请参阅[本指南]({{ ref bindings-overview.md }})以了解如何创建和应用绑定配置。
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: <NAME>
spec:
type: bindings.sftp
version: v1
metadata:
- name: rootPath
value: "<string>"
- name: address
value: "<string>"
- name: username
value: "<string>"
- name: password
value: "*****************"
- name: privateKey
value: "*****************"
- name: privateKeyPassphrase
value: "*****************"
- name: hostPublicKey
value: "*****************"
- name: knownHostsFile
value: "<string>"
- name: insecureIgnoreHostKey
value: "<bool>"
元数据字段说明
字段 | 必需 | 绑定支持 | 详情 | 示例 |
---|---|---|---|---|
rootPath |
Y | 输出 | 默认工作目录的根路径 | "/path" |
address |
Y | 输出 | SFTP 服务器地址 | "localhost:22" |
username |
Y | 输出 | 用于身份验证的用户名 | "username" |
password |
N | 输出 | 用户名/密码身份验证的密码 | "password" |
privateKey |
N | 输出 | 公钥身份验证的私钥 | "|- |
privateKeyPassphrase |
N | 输出 | 公钥身份验证的私钥密码 | "passphrase" |
hostPublicKey |
N | 输出 | 主机验证的主机公钥 | "ecdsa-sha2-nistp256 *** root@openssh-server" |
knownHostsFile |
N | 输出 | 主机验证的已知主机文件 | "/path/file" |
insecureIgnoreHostKey |
N | 输出 | 允许跳过主机验证。默认为 "false" |
"true" , "false" |
绑定功能支持
此组件支持以下操作的输出绑定:
创建文件
要执行创建文件操作,请使用 POST
方法调用 SFTP 绑定,并提供以下 JSON 正文:
{
"operation": "create",
"data": "<YOUR_BASE_64_CONTENT>",
"metadata": {
"fileName": "<filename>"
}
}
示例
curl -d "{ \"operation\": \"create\", \"data\": \"YOUR_BASE_64_CONTENT\", \"metadata\": { \"fileName\": \"my-test-file.jpg\" } }" http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "create", "data": "YOUR_BASE_64_CONTENT", "metadata": { "fileName": "my-test-file.jpg" } }' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
响应
响应正文将返回以下 JSON:
{
"fileName": "<filename>"
}
获取文件
要执行获取文件操作,请使用 POST
方法调用 SFTP 绑定,并提供以下 JSON 正文:
{
"operation": "get",
"metadata": {
"fileName": "<filename>"
}
}
示例
curl -d '{ \"operation\": \"get\", \"metadata\": { \"fileName\": \"filename\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "get", "metadata": { "fileName": "filename" }}' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
响应
响应正文将包含文件中的内容。
列出文件
要执行列出文件操作,请使用 POST
方法调用 SFTP 绑定,并提供以下 JSON 正文:
{
"operation": "list"
}
如果您只想列出 rootPath
下某个特定目录中的文件,请在元数据中指定该目录的相对路径作为 fileName
。
{
"operation": "list",
"metadata": {
"fileName": "my/cool/directory"
}
}
示例
curl -d '{ \"operation\": \"list\", \"metadata\": { \"fileName\": \"my/cool/directory\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "list", "metadata": { "fileName": "my/cool/directory" }}' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
响应
响应将是一个包含文件名的 JSON 数组。
删除文件
要执行删除文件操作,请使用 POST
方法调用 SFTP 绑定,并提供以下 JSON 正文:
{
"operation": "delete",
"metadata": {
"fileName": "myfile"
}
}
示例
curl -d '{ \"operation\": \"delete\", \"metadata\": { \"fileName\": \"myfile\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "delete", "metadata": { "fileName": "myfile" }}' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
响应
如果成功,将返回 HTTP 204(无内容)和空响应正文。
相关链接
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.