Linux 拷贝文件 scp fstp rsync的简单使用

scp:是基于ssh的,如果ssh没有启动,那么就使用不了。

[root@localhost test]# touch /hh.txt

[root@localhost test]# scp /hh.txt  [email protected]:/  相当于将/hh.txt文件传到192.168.146.138上面

The authenticity of host '192.168.146.138 (192.168.146.138)' can't be established.

ECDSA key fingerprint is c6:7a:1b:03:9a:bf:3c:80:a3:58:d0:84:0d:f5:b8:e5.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.146.138' (ECDSA) to the list of known hosts.

[email protected]'s password:

hh.txt                                               100%    0     0.0KB/s   00:00  

 [root@localhost test]# scp   [email protected]:/hh.txt  /   相当于下载192.168.146.138上面的hh.txt文件到本机的根目录/下面

 

[root@server0 ~]# scp -r /test  root@desktop0:/  --使用-r选项递归目录,将目录传输过去

root@desktop0's password:

file1                                                                   100%    0     0.0KB/s   00:00    

file2                                                                   100%    0     0.0KB/s   00:00    

file3                                                                   100%    0     0.0KB/s   00:00

 

在拷贝的过程当中,注意文件的所有者会发生改变,每次传输完毕最好查看一下文件所有者和其他人以及相对应的权限

[root@server0 ~]# su - test

Last login: Tue Apr 10 03:31:16 CST 2018 on pts/0

[test@server0 ~]$ touch test.txt

[test@server0 ~]$ ls -l

total 0

-rw-rw-r--. 1 test test 0 Apr 10 03:35 test.txt

[test@server0 ~]$ su - root

Password:

Last login: Tue Apr 10 03:12:27 CST 2018 from 172.25.0.250 on pts/0

[root@server0 ~]# scp /home/test/test.txt  root@desktop0:/  --用root身份将test用户的文件拷贝过去,这样文件的所有者会发生改变

root@desktop0's password:

test.txt                                                                100%    0     0.0KB/s   00:00    

[root@server0 ~]# ssh root@desktop0

root@desktop0's password:

Last login: Tue Apr 10 03:33:02 2018 from server0.example.com

[root@desktop0 ~]# ls -l /test.txt

-rw-r--r--. 1 root root 0 Apr 10 03:36 /test.txt

 

 

 

fstp

[root@localhost test]# sftp [email protected] --sftp相对于客户端,以root身份登入到192.168.146.138上面去取文件

[email protected]'s password:

Connected to 192.168.146.138.

sftp> pwd

Remote working directory: /root

sftp> ls

anaconda-ks.cfg              initial-setup-ks.cfg         

sftp> get anaconda-ks.cfg

Fetching /root/anaconda-ks.cfg to anaconda-ks.cfg

/root/anaconda-ks.cfg                                100% 1872     1.8KB/s   00:00    

sftp> bye

注意下载的位置是当前目录。上面就相当于ftp的客户端。scp命令是不会登入到远程主机上面的,但是ftp相对于客户端可以登入到远程主机拿自己想要的文件。

 

 

Synchronize files and floaders with rsync

The rsync tool is another way to securely copy files from one system to another.it differs from scp in that if two files or directories are similar between two system,rsync only need to copy the differences between the systems,while scp would need to copy everything.

 

rsync:如果在目的端有相同的文件,那么如果在源端,该文件发生改变会将其拷贝过去,如果和目的端文件一样那么就不拷贝

[root@localhost test]# rsync -av /hh.txt    [email protected] /tmp

sending incremental file list

hh.txt

[email protected]

 

sent 134 bytes  received 50 bytes  368.00 bytes/sec

total size is 0  speedup is 0.00

因为主机192.168.146.138的/tmp下面已经有了hh.txt文件,所以不会将其copy过去。只会增量的进行copy。只要文件发生改变就会拷贝过去而不是文件名相同就不会拷贝过去。

 

 

 

 

 

 

猜你喜欢

转载自blog.csdn.net/qq_34556414/article/details/81461349
今日推荐