Windows11 - 使用 sftp连接 CentOS 7,实现文件上传与下载


前言

Windows系统的cmd命令实现远程连接服务器,并且使用 sftp连接 CentOS 7,实现文件上传与下载


一、ssh连接服务器

注意:下方所有服务器ip,均为示例ip

Microsoft Windows [版本 10.0.22621.963]
(c) Microsoft Corporation。保留所有权利。

C:\Users\nanyi>ssh -p 22 root@8.161.180.227 
root@8.161.180.227's password:
Last failed login: Tue Jan 10 12:21:59 CST 2023 from 122.80.263.116 on ssh:notty
There were 24 failed login attempts since the last successful login.
Last login: Sun Dec 18 14:35:25 2022 from 126.213.74.53

Welcome to Alibaba Cloud Elastic Compute Service !

-bash: export: `/usr/local/software/nginx-1.21.6/sbin': not a valid identifier
[root@izbp1g3qo24yvt8e0635uxz ~]# dir
get-docker.sh  logs  tmall_logs
[root@izbp1g3qo24yvt8e0635uxz ~]# cd /
[root@izbp1g3qo24yvt8e0635uxz /]# dir
bin   dev  home  lib64       media  mynacos  proc  run   srv  tmall  usr  菜谱.txt
boot  etc  lib   lost+found  mnt    opt      root  sbin  sys  tmp    var

这样就成功连接上服务器,不过命令和Linux上命令有所区别

二、sftp连接服务器,实现文件上传与下载

如下(示例):

C:\Users\nanyi>sftp root@8.161.180.227
root@8.161.180.227's password:
Connected to 8.161.180.227.
sftp>

注意:sftp> 表示已经进入 sftp 的交互模式。
连接成功之后,使用 pwd 命令查看远程服务器上的当前工作目录:

sftp> pwd
Remote working directory: /root

使用 ls 命令查看远程服务器上的当前工作目录下的文件:

sftp> ls -l
lrwxrwxrwx    1 root     root            7 Aug 18  2017 bin
dr-xr-xr-x    4 root     root         4096 Sep 12  2017 boot
drwxr-xr-x   19 root     root         2980 Jan 21  2022 dev
drwxr-xr-x   85 root     root         4096 Feb 14  2022 etc
drwxrwxrwx    3 root     root         4096 Jun 15  2021 home
lrwxrwxrwx    1 root     root            7 Aug 18  2017 lib
lrwxrwxrwx    1 root     root            9 Feb  5  2021 lib64
drwx------    2 root     root        16384 Aug 18  2017 lost+found
drwxr-xr-x    2 root     root         4096 Nov  5  2016 media
drwxr-xr-x    2 root     root         4096 Nov  5  2016 mnt
drwxr-xr-x    7 root     root         4096 Feb  8  2022 mynacos
-rw-r--r--    1 root     root           13 Apr  8  2022 菜谱.txt

使用 lpwd 命令查看本地服务器上的当前工作目录:

sftp> lpwd
Local working directory: c:\users\nanyi

使用 lcd 命令切换到本机指定工作目录:

sftp> lcd D:\
sftp> lpwd
Local working directory: d:\

使用 lls 命令查看本机指定目录下的文件:

sftp> lls D:\
2022/12/09  16:44    <DIR>          nanyi_rust_projects
2021/10/16  13:44    <DIR>          Pr
2021/01/26  21:44    <DIR>          questionnaire
2022/12/22  15:33    <DIR>          software
2022/07/06  17:48    <DIR>          spring-framework-5.2.x
sftp> 

使用 put 命令将本机上指定目录下的文件上传到远程服务器上当前目录下

sftp> put test.txt
Uploading test.txt to /test.txt
test.txt                                                                              100%    0     0.0KB/s   00:00
sftp> ls -l
lrwxrwxrwx    1 root     root            7 Aug 18  2017 bin
dr-xr-xr-x    4 root     root         4096 Sep 12  2017 boot
drwxr-xr-x   19 root     root         2980 Jan 21  2022 dev
drwxr-xr-x   85 root     root         4096 Feb 14  2022 etc
drwxrwxrwx    3 root     root         4096 Jun 15  2021 home
lrwxrwxrwx    1 root     root            7 Aug 18  2017 lib
lrwxrwxrwx    1 root     root            9 Feb  5  2021 lib64
-rw-r--r--    1 root     root           13 Apr  8  2022 菜谱.txt
-rw-r--r--    1 root     root            0 Jan 10 19:32 test.txt

使用 get 命令从远程服务器上下载指定文件到本地服务器

sftp> ls -l
lrwxrwxrwx    1 root     root            7 Aug 18  2017 bin
dr-xr-xr-x    4 root     root         4096 Sep 12  2017 boot
drwxr-xr-x   19 root     root         2980 Jan 21  2022 dev
drwxr-xr-x   85 root     root         4096 Feb 14  2022 etc
drwxrwxrwx    3 root     root         4096 Jun 15  2021 home
lrwxrwxrwx    1 root     root            7 Aug 18  2017 lib
lrwxrwxrwx    1 root     root            9 Feb  5  2021 lib64
-rw-r--r--    1 root     root           13 Apr  8  2022 菜谱.txt
-rw-r--r--    1 root     root            0 Jan 10 19:32 test.txt
sftp> lpwd
Local working directory: d:\
sftp> get 菜谱.txt
Fetching /菜谱.txt to 菜谱.txt
/菜谱.txt                                                                           100%   13     0.5KB/s   00:00
sftp> lls
 Volume in drive D is Data
 Volume Serial Number is FE47-6B17

 Directory of D:\


2022/12/09  16:44    <DIR>          nanyi_rust_projects
2021/10/16  13:44    <DIR>          Pr
2021/01/26  21:44    <DIR>          questionnaire
2022/12/22  15:33    <DIR>          software
2022/07/06  17:48    <DIR>          spring-framework-5.2.x
2023/01/11  10:34                13 菜谱.txt

可以看到 “菜谱.txt” 文件已经下载到了本地!

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值