首页·终端命令

sftp

网络

用法

sftp [-P <port>] <user>@<host>

架在 ssh 连接之上的交互式传输工具;端口选项是大写 `-P` 而不是 ssh 的 `-p`,而且它不能执行远端 shell 命令,只认自己的 put、get、ls。

常用选项

选项含义
-P 2222Port, capital P. ssh uses lowercase -p for the same thing.
-i <key>Use a specific private key.
-rRecursive, for put -r and get -r on directories.
-b <batchfile>Run a list of commands without a prompt, for scripts.
put / get / ls / lcdIts own commands inside the session; lcd changes the local directory.

示例

sftp -P 2222 deploy@example.com

Open an interactive transfer session.

sftp deploy@example.com:/var/log/app.log .

Fetch one file without entering the prompt.

连不上的时候,这些能把范围缩小——是名字解析不了、没有路由,还是端口被挡。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. sftp 是做什么的?

架在 ssh 连接之上的交互式传输工具;端口选项是大写 `-P` 而不是 ssh 的 `-p`,而且它不能执行远端 shell 命令,只认自己的 put、get、ls。

Q. 怎么写?

sftp [-P <port>] <user>@<host> —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 5 个,完整列表在 man sftp。这条命令属于网络。

相关命令

man 手册: man sftp