点击个人博客,查看更多文章https://elonjelinek.github.io/
这里直接在终端用scp命令进行传输,scp是secure copy即安全传输的简写,是用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝,而scp是跨服务器传输并且是加密的。
ElonJelinek:Desktop ElonJelinek$ scp --help
scp: illegal option -- -
usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 ... [[user@]host2:]file2
ElonJelinek:Desktop ElonJelinek$
-P
大写的P,表示指定端口,一般会使用默认端口,所以该参数可省略
-r
小写的r,用于传输文件夹,表示递归复制整个目录
-l
小写的L,limit,限定用户所能使用的带宽,以Kbit/s为单位
-i
小写的i,identity_file,从指定文件中读取传输时使用的密钥文件,此参数直接传递给ssh
-F
ssh_config,指定一个替代的ssh配置文件,此参数直接传递给ssh
-c
小写的c,cipher,以cipher将数据传输进行加密,这个选项将直接传递给ssh
-o
小写的o,指定使用的ssh选项
上传语法:scp /本地文件路径/本地文件名 服务器用户名@服务器IP:路径
冒号后面为空,表示上传至根目录
注意,这里@后面,既可以写服务器地址,也可以写与IP绑定的域名
ElonJelinek:Desktop ElonJelinek$ ls
mygo.go 屏幕快照 2018-03-27 下午5.55.57.png
mysql-apt-config_0.8.10-1_all.deb 屏幕快照 2018-03-27 下午6.01.12.png
ElonJelinek:Desktop ElonJelinek$ pwd mygo.go
/Users/ElonJelinek/Desktop
ElonJelinek:Desktop ElonJelinek$ cat /Users/ElonJelinek/Desktop/mygo.go
package main
import "fmt"
func main() {
fmt.Println("Hello world!")
}
ElonJelinek:Desktop ElonJelinek$ scp /Users/ElonJelinek/Desktop/mygo.go root@batbatbat.com:
root@batbatbat.com's password:
mygo.go 100% 74 9.4KB/s 00:00
ElonJelinek:Desktop ElonJelinek$
root@higbeuwbgriueqiu849hhuir:~# ls
go main.go mygo.go test update_source.sh update_source.tgz
root@higbeuwbgriueqiu849hhuir:~# cat mygo.go
package main
import "fmt"
func main() {
fmt.Println("Hello world!")
}
root@higbeuwbgriueqiu849hhuir:~#
scp /Users/ElonJelinek/Desktop/mysql-apt-config_0.8.10-1_all.deb root@batbatbat.com:
过程
ElonJelinek:Desktop ElonJelinek$ pwd mysql-apt-config_0.8.10-1_all.deb
/Users/ElonJelinek/Desktop
ElonJelinek:Desktop ElonJelinek$ scp /Users/ElonJelinek/Desktop/mysql-apt-config_0.8.10-1_all.deb root@batbatbat.com:
root@batbatbat.com's password:
mysql-apt-config_0.8.10-1_all.deb 100% 35KB 95.6KB/s 00:00
ElonJelinek:Desktop ElonJelinek$
在服务器查看
root@higbeuwbgriueqiu849hhuir:~# ls
go mygo.go mysql-apt-config_0.8.10-1_all.deb update_source.sh update_source.tgz
root@higbeuwbgriueqiu849hhuir:~#
下载文件语法:scp 服务器用户名@服务器IP:路径/文件名 /本地文件路径
ElonJelinek:Desktop ElonJelinek$ pwd
/Users/ElonJelinek/Desktop
ElonJelinek:Desktop ElonJelinek$ scp root@batbatbat.com:mygo.go /Users/ElonJelinek/Desktop
root@batbatbat.com's password:
mygo.go 100% 74 11.9KB/s 00:00
ElonJelinek:Desktop ElonJelinek$ ls
mygo.go 屏幕快照 2018-09-27 下午6.01.12.png
屏幕快照 2018-09-27 下午5.55.57.png
ElonJelinek:Desktop ElonJelinek$
只需多加一个-r
即可
scp -r /Users/ElonJelinek/Desktop/newDir [email protected]:
ElonJelinek:~ ElonJelinek$ scp -r /Users/ElonJelinek/Desktop/newDir aliyun@batbatbat.com:
aliyun@batbatbat.com's password:
test.txt 100% 0 0.0KB/s 00:00
ElonJelinek:~ ElonJelinek$
ElonJelinek:Desktop ElonJelinek$ scp -r aliyun@batbatbat.com:newDir /Users/ElonJelinek/Desktop/
aliyun@batbatbat.com's password:
test.txt 100% 0 0.0KB/s 00:00
ElonJelinek:Desktop ElonJelinek$
点击个人博客,查看更多文章https://elonjelinek.github.io/