Ubuntu 服务器之间拷贝文件命令

从本服务器上访问另一个服务器  ssh zhangmeng@10.167.174.123   然后输入密码即可。


1.拷贝远程服务器的目录到本地服务器

远程服务器192.168.1.112上面/tmp目录下面有个test目录,里面有个文件名为test,内容也为test
root@ubuntu:/tmp# cat test/test 
test

拷贝远程服务器192.168.1.112的目录/tmp/test到当前目录下。
[root@CentOS_Test_Server tmp]#  scp -r root@192.168.1.112:/tmp/test ./
The authenticity of host '192.168.1.112 (192.168.1.112)' can't be established.
RSA key fingerprint is 64:76:a6:1e:23:76:ec:25:5e:c2:f3:ef:fc:ad:48:7b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.112' (RSA) to the list of known hosts.
root@192.168.1.112's password: 
test                                                                                                                                                       100%       5         0.0KB/s    00:00 

注意拷贝到本地服务器后形成的目录结构为/tmp/test,而不是/tmp/tmp/test,一定要注意,这里比较容易混淆,经过自己亲自测试,再碰到类似的问题心里就有底了。
[root@CentOS_Test_Server tmp]# ls test/
test

2.拷贝远程服务器的文件到本地服务器
将1中拷贝过来的目录test删除
rm -rf test

[root@CentOS_Test_Server tmp]# ls -l | grep test | grep -v "grep"

拷贝远程服务器192.168.1.112的文件/tmp/test/test到当前目录下。
[root@CentOS_Test_Server tmp]#  scp root@192.168.1.112:/tmp/test/test ./
root@192.168.1.112's password: 
test                                                                                                                                                       100%       5         0.0KB/s    00:00
[root@CentOS_Test_Server tmp]# ls -l | grep test | grep -v "grep"
-rw-r--r-- 1 root   root         5 Sep 22 14:07 test

3.拷贝本地服务器的目录到远程服务器
在/tmp目录下面建立目录dir111,在此目录下创建文件file111,内容为file111
[root@CentOS_Test_Server tmp]# mkdir dir111
[root@CentOS_Test_Server tmp]# echo 'content111' > dir111/file111
[root@CentOS_Test_Server tmp]# cat dir111/file111
content111

拷贝本地服务器的目录dir111到远程服务器的目录/tmp下

与上述1中类似,拷贝到远程服务器后形成的目录结构为/tmp/dir111,而不是/tmp/tmp/dir111,一定要注意,这里比较容易混淆。

不管拷贝命令是scp -r dir111 root@192.168.1.112:/tmp还是scp -r /tmp/dir111 root@192.168.1.112:/tmp,在远程服务器上面生成的目录结构均一样,我亲自测试过了。

[root@CentOS_Test_Server tmp]# scp -r /tmp/dir111 root@192.168.1.112:/tmp
root@192.168.1.112's password: 
file111                                                                                                                                                 100%     11         0.0KB/s    00:00      

远程服务器192.168.1.112上面的内容
root@ubuntu:/tmp# ls
dir111   test   vmware-root
root@ubuntu:/tmp# cat dir111/file111
content111

4.拷贝本地服务器的文件到远程服务器
[root@CentOS_Test_Server tmp]#  scp dir111/file111 root@192.168.1.112:/tmp
root@192.168.1.112's password: 
file111                                                                                                                                                 100%     11         0.0KB/s    00:00 

远程服务器192.168.1.112上面的内容
root@ubuntu:/tmp# ls
dir111 file111   test   vmware-root
要将Windows文件拷贝Ubuntu系统中,可以使用以下方法之一: 1. 使用FileZilla软件进行文件传输。首先打开FileZilla软件,然后选择“文件” -> “站点管理器” -> “新增站点”,配置连接参数后点击连接。连接成功后,可以在左侧窗口中找到Windows的文件,然后将其拖拽到右侧Ubuntu指定的目录中即可完成文件拷贝。\[1\] 2. 使用增强工具VMware Tools设置共享文件夹。如果你是在虚拟机中运行Ubuntu系统,可以安装VMware Tools并设置共享文件夹,这样可以在Windows和Ubuntu之间进行文件互传。具体的设置方法可以参考VMware Tools的文档或者官方指南。\[2\] 3. 配置Ubuntu的Samba服务。在Ubuntu系统中配置Samba服务后,可以在Windows的网络中输入Ubuntu的IP地址来访问Samba的共享目录,从而实现文件互传。你可以在Windows中映射Samba共享目录到本地,这样就可以像访问Windows的C盘、D盘一样访问Samba共享目录了。\[3\] 以上是几种将Windows文件拷贝Ubuntu的方法,推荐使用FileZilla和Samba服务器这两种方法。 #### 引用[.reference_title] - *1* *3* [windows主机和ubuntu互传文件的4种方法](https://blog.csdn.net/luobeihai/article/details/124003483)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [ubuntu 与 windows 之间的文件互传](https://blog.csdn.net/Chuangke_Andy/article/details/126240032)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值