使用SFTP传输文件

什么是 SFTP ?

FTP( File Transfer Protocol )文件传输协议,是一种常用来在两终端系统之间传输文件的方法。
SFTP ,即 SSH 文件传输协议( SSH File Transfer Protocol ),或者说是安全文件传输协议( Secure File Transfer Protocol )。SFTP 是一个独立的 SSH 封装协议包,通过安全连接以相似的方式工作。它的优势在于可以利用安全的连接传输文件,还能遍历本地和远程系统上的文件系统。

在大多数情况下,优先选择 SFTP 而不是 FTP ,原因在于 SFTP 最基本的安全特性和能利用 SSH 连接的能力。FTP 是一种不安全的协议,应当只有在特定的情况下或者你信任的网络中使用。

How to Use

To connect to a remote sftp server, first establish an secure SSH connection and then create an SFTP session as shown.

sftp -P <port number> username@remote_hostname_or_IP

Operations

Check operations with help

How to Upload a Directory Using sFTP

First create a directory with the same name on the remote host, before uploading it from the local host, the -r does the magic, enabling subdirectories and subfile to be copied as well:

sftp> mkdir testdir
sftp> put -r testdir

# for file upload use:
sftp put testfile.zip
# check file size
sftp ls -lah

To preserve the modification times, access times, and modes from the original files transferred, use the -p flag.

sftp> put -pr testdir

How to Download a Directory Using sFTP

To download a whole directory called fstools-0.0 from remote Linux host to local machine, use the get command with the -r flag as follows:

sftp> get -r testdir

To quite the sFTP shell, type:

sftp> bye
# OR
sftp> exit
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,009评论 19 139
  • BOOLEAN OPTIONS Below is a list of boolean options. The v...
    usrbin阅读 1,746评论 0 0
  • 心情不好……字也好丑……
    魚遇見海阅读 124评论 0 2
  • The way ............ ——————————Licy 缓解压力。 ——bela
    三个远方阅读 151评论 0 0
  • 这张思维导图是画的化学反应速率和平衡。在创作的时候我不但画了一些基础知识点,还加入了一些解题的套路和思路。
    陈虹宇_e51c阅读 296评论 0 1