利用ssh传输文件
在linux下一般用scp这个命令来通过ssh传输文件。
1、从服务器上下载文件
scp username@servername:/path/filename /var/www/local_dir(本地目录)
例如scp root@192.168.0.101:/var/www/test.txt 把192.168.0.101上的/var/www/test.txt 的文件下载到/var/www/local_dir(本地目录)
2、上传本地文件到服务器
scp /path/filename username@servername:/path
例如scp /var/www/test.php root@192.168.0.101:/var/www/ 把本机/var/www/目录下的test.php文件上传到192.168.0.101这台服务器上的/var/www/目录中
3、从服务器下载整个目录
scp -r username@servername:/var/www/remote_dir/(远程目录) /var/www/local_dir(本地目录)
例如:scp -r root@192.168.0.101:/var/www/test /var/www/
4、上传目录到服务器
scp -r local_dir username@servername:remote_dir
例如:scp -r test root@192.168.0.101:/var/www/ 把当前目录下的test目录上传到服务器的/var/www/ 目录
实践:
[root@localhost home]# scp -r root@255.255.255.255:/home/remote /home/local The authenticity of host '255.255.255.255 (255.255.255.255)' can't be established. ECDSA key fingerprint is SHA256:53QDqcS8qtxst2SbSc1OfqfEknmi4WcFBdPCq41aNLQ. ECDSA key fingerprint is MD5:25:fa:25:22:39:e5:72:88:1e:2f:64:5d:fa:ac:df:2c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '255.255.255.255' (ECDSA) to the list of known hosts. Authorized users only. All activities may be monitored and reported. Password: // 输入远程服务器255.255.255.255的密码即可
注:目标服务器要开启写入权限。