基础信息:

服务器端:Cnetos8.2

客户端:windows

sftp:/root> help
bye     finish your SFTP session
cd      change your remote working directory
clear   clear screen
exit    finish your SFTP session
explore explore your local directory
get     download a file from the server to your local machine
help    give help
lcd     change and/or print local working directory
lls     list contents of a local directory
lpwd    print your local working directory
ls      list contents of a remote directory
mkdir   create a directory on the remote server
mv      move or rename a file on the remote server
put     upload a file from your local machine to the server
pwd     print your remote working directory
quit    finish your SFTP session
rename  move or rename a file on the remote server
rm      delete a file
rmdir   remove a directory on the remote server
 

操作记录:

#显示远程主机上的当前目录

sftp> pwd

Remote working directory: /home/tdops

#显示本地主机上的当前目录

sftp> lpwd

/root

sftp>

#更改目录

sftp> cd dir/

sftp> pwd

Remote working directory: /home/tdops/dir

#将文件上传到远程主机

sftp> put test.txt

Uploading test.txt to /home/tdops/dir/test.txt

test.txt    100%   20    24.7KB/s   00:00

sftp> ls

test.txt

#将一些文件上传到远程主机

sftp> put *.txt

Uploading test.txt to /home/tdops/dir/test.txt

test.txt                    100%   20    25.5KB/s   00:00

Uploading test01.txt to /home/tdops/dir/test01.txt

test01.txt                  100%   22    32.2KB/s   00:00

sftp> ls

test.txt     test01.txt

# 使用cd.. 切换到上一级目录

sftp> cd ..

sftp> ls

dir             getfile.txt     sshserver.txt   test01.txt

#从远程主机下载文件

sftp> get getfile.txt

Fetching /home/tdops/getfile.txt to getfile.txt

#从远程主机下载一些文件

sftp> get *.txt

Fetching /home/tdops/getfile.txt to getfile.txt

Fetching /home/tdops/sshserver.txt to sshserver.txt

Fetching /home/tdops/test01.txt to test01.txt

/home/tdops/test01.txt          100%   22    17.1KB/s   00:00

sftp> ls

getfile.txt     sshserver.txt   test01.txt

#查看已经下载到本机的文件

sftp> lls

anaconda-ks.cfg  getfile.txt  initial-setup-ks.cfg  lianglab.ovpn  sshserver.txt  test01.txt  test.txt

sftp>

#在远程主机上创建目录

sftp> mkdir testdir

sftp> cd t

test01.txt   testdir/

sftp> cd testdir/

sftp> put *.txt

Uploading test.txt to /home/tdops/testdir/test.txt

test.txt             100%   20    24.1KB/s   00:00

Uploading test01.txt to /home/tdops/testdir/test01.txt

test01.txt    100%   22    35.1KB/s   00:00

sftp> ls

test.txt     test01.txt

sftp> ls -l

-rw-r--r--    1 tdops    users          20 Dec  5 12:48 test.txt

-rw-r--r--    1 tdops    users          22 Dec  5 12:48 test01.txt

sftp> cd ..

sftp> ls

dir          test01.txt   testdir

#删除远程主机上的文件

sftp> rmdir testdir/

Couldn't remove directory: Failure  #删除时有错误,说明目录有文件

sftp> rmdir testdir

Couldn't remove directory: Failure

sftp> ls

dir          test01.txt   testdir

#进入我们要删除的testdir目录,并删除里面的txt文件

sftp> cd testdir/

sftp> ls

test.txt     test01.txt

sftp> rm t

test.txt     test01.txt

#删除 test.txt和test01.txt文件

sftp> rm test.txt

Removing /home/tdops/testdir/test.txt

sftp> rm test01.txt

Removing /home/tdops/testdir/test01.txt

sftp> cd ..

sftp> ls

dir          test01.txt   testdir

#在删除testdir目录

sftp> rmdir testdir/

sftp> ls -l

drwxr-xr-x    2 tdops    users          40 Dec  5 12:48 dir

-rw-r--r--    1 tdops    users          22 Dec  5 12:44 test01.txt

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐