在shell命令脚本窗口中,可以使用scp命令来实际文件的传输,比如文件/文件夹的上传,文件/文件夹的下载。

1、ssh上传文件命令

命令格式:

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上传文件夹命令

命令格式:

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下载文件的方法

命令格式:

scp  服务器用户名@服务器IP:服务器上下载的文件 本地存放目录

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

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下载文件夹的方法

命令格式

scp -r  服务器用户名@服务器IP:服务器上下载的目录 本地存放目录

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

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.

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

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

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