退出或者退出 sftp

输入 exit 、 quit 或者 bye 关闭连接并退出 sftp。

sftp> bye

或者

sftp> quit

或者

sftp> exit
如何使用 sftp 安全传输文件

sftp 命令是 ftp 的安全替代方案,其功能与 ftp 相同。
登录到运行 OpenSSH 守护进程 sshd 的服务器时,请使用 sftp 而不是 ftp。
sftp 和 ftp 之间的主要区别在于,前者使用加密通过网络传输密码,而后者则不使用。

导航目录和列出文件

  1. 在本地服务器上查找当前目录:
sftp> lpwd
Local working directory: /root
  1. 在远程主机上查找当前工作目录:
sftp> pwd
Remote working directory: /root
  1. 同样,要更改本地服务器上的目录,请使用 lcd 命令:
sftp> lcd /tmp
  1. 要更改远程服务器上的目录,请使用 cd 命令:
sftp> cd /tmp
  1. 列出远程服务器上当前目录中的文件:
sftp> ls
anaconda-ks.cfg         initial-setup-ks.cfg    test
  1. 列出本地服务器上当前目录中的文件:
sftp> lls
file1  file2  file3

sftp 语法

连接到远程系统的格式是:

# sftp [options] [user@]host

输入帮助或者?
显示 sftp 命令列表。

sftp> help
Available commands:
bye                                Quit sftp
cd path                            Change remote directory to 'path'
chgrp grp path                     Change group of file 'path' to 'grp'
chmod mode path                    Change permissions of file 'path' to 'mode'
chown own path                     Change owner of file 'path' to 'own'
df [-hi] [path]                    Display statistics for current directory or
                                   filesystem containing 'path'
exit                               Quit sftp
get [-Ppr] remote [local]          Download file
reget remote [local]		Resume download file
help                               Display this help text
lcd path                           Change local directory to 'path'
lls [ls-options [path]]            Display local directory listing
lmkdir path                        Create local directory
ln [-s] oldpath newpath            Link remote file (-s for symlink)
lpwd                               Print local working directory
ls [-1afhlnrSt] [path]             Display remote directory listing
lumask umask                       Set local umask to 'umask'
mkdir path                         Create remote directory
progress                           Toggle display of progress meter
put [-Ppr] local [remote]          Upload file
pwd                                Display remote working directory
quit                               Quit sftp
rename oldpath newpath             Rename remote file
rm path                            Delete remote file
rmdir path                         Remove remote directory
symlink oldpath newpath            Symlink remote file
version                            Show SFTP version
!command                           Execute 'command' in local shell
!                                  Escape to local shell
?                                  Synonym for help
sftp>

使用 sftp 连接远程系统

以下示例假设我们以用户 testuser 身份登录到本地系统并连接到远程系统 192.168.219.149:

$ sftp testuser@192.168.219.149
Connecting to 192.168.219.149...
testuser@192.168.219.149 password:
Connected to 192.168.219.149.
sftp>

提供正确的密码后,我们会看到 sftp> 提示,如图所示。
输入帮助或者?
显示可用命令的列表。

使用 sftp 下载文件或者目录

  1. 要从远程主机下载单个文件,请使用 get 命令。
sftp> get file1
  1. 要下载多个文件,请使用以下命令。
sftp> mget file1 file2 file3
  1. 递归下载目录(及其所有内容):
get -r dir
www. On IT Road .com

创建和删除目录

  1. 在远程服务器上创建一个新目录:
sftp> mkdir data
  1. 在本地服务器上创建一个新目录:
sftp> lmkdir testdir

使用 sftp 上传文件和目录

  1. 以下示例上传文件,或者将文件从本地系统复制到远程系统:
sftp> put file1
  1. 要将多个文件传输到远程主机,请使用 mput(多个放置)命令。
sftp> mput file1 file2 file3
  1. 为了能够将目录传输到远程主机,我们必须首先在远程主机上创建一个目录并开始传输。
sftp> mkdir /dir
sftp> put -r dir/
日期:2020-09-17 00:13:55 来源:oir作者:oir