hi,欢迎访问本站!
当前位置: 首页操作系统正文

通过ssh实现文件传输命令

墨初 操作系统 1227阅读

在shell命令脚本窗口中,可以使用scp命令来实现文件的传输,比如文件/文件夹的上传,文件/文件夹的下载。下面就由文蚂蚁博客详细的来说一说。

ssh 文件/文件夹上传命令

1、ssh上传文件命令

命令格式:

#wenmayi.com 文蚂蚁博客
scp 本地文件目录 服务器用户名@服务器IP:服务器上传的目录

例:下面以windows系统向linux服务器上传文件为例

scp d:b.txt mozhu@192.168.31.106:/www/
Connecting to 192.168.31.106:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Password: *****
Start scp session to upload.
b.txt1.00 KB
Sent all of files.
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(192.168.31.106:22) at 18:11:26.
Type `help' to learn how to use Xshell prompt.

2、ssh 上传文件夹命令

命令格式:

#wenmayi.com 文蚂蚁博客
scp -r 本地要上传的文件夹 服务器用户名@服务器IP:服务器上传的目录

例:下面以windows系统向linux服务器上传文件夹为例

$ scp -r d:b mozhu@192.168.31.106:/www/
Connecting to 192.168.31.106:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Password: *****
Start scp session to upload.
a.txt5.74 KB
aa.txt0 字节
bb.txt0 字节
b.php0 字节
Sent all of files.
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(192.168.31.106:22) at 18:18:42.
Type `help' to learn how to use Xshell prompt.

ssh 文件/文件夹下载命令

从linux服务器下载文件,也需要使用 scp 命,与上传不同的是,命令的格式有些区别

1、ssh 下载文件的方法

命令格式:

#wenmayi.com 文蚂蚁博客
scp  服务器用户名@服务器IP:服务器上下载的文件 本地存放目录

例:从linux服务器下载文件到本地window系统

scp mozhu@192.168.31.106:/www/a.txt d:\dow
Connecting to 192.168.31.106:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Password: *****
Start scp session to download.
a.txt1.00 KB
Connection closed.
Disconnected from remote host(192.168.31.106:22) at 18:34:16.
Type `help' to learn how to use Xshell prompt.

2、ssh下载文件夹的方法

命令格式

#wenmayi.com 文蚂蚁博客
scp -r  服务器用户名@服务器IP:服务器上下载的目录 本地存放目录

例:从linux服务器下载文件夹到本地window系统

scp -r mozhu@192.168.31.106:/www/mochu  d:/dow/
Connecting to 192.168.31.106:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Password: *****
Start scp session to download.
a.txt55 字节
b.txt64 字节
Connection closed.
Disconnected from remote host(192.168.31.106:22) at 18:50:52.
Type `help' to learn how to use Xshell prompt.

PS:

(1)、执行scp命令时,必须在一个没有建立链接的shell命令窗口中进行

(2)、文件上传/下载命令执行时都需要输入目标服务器的密码

(3)、上传文件到linux服务器时,需要注意linux服务器目标文件夹的权限,是否有权限上传

声明:无特别说明,转载请标明本文来源!