Linux 使用nc传输大文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17797758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using nc to transfer large file
提问by Gopala Krishnan
I have a compressed file size of about 9.5 GB and want to transfer from one server to another server, I tried to use like the below,
我有一个大约 9.5 GB 的压缩文件大小,想从一台服务器传输到另一台服务器,我尝试使用如下,
server2:
服务器2:
nc -lp 1234 > file.tar.gz
nc -lp 1234 > 文件.tar.gz
server1:
服务器 1:
nc -w 1 1234 < file.tar.gz
nc -w 1 1234 < 文件.tar.gz
its not working.
它不工作。
I tried so many ways.
我尝试了很多方法。
One machine is CentOS 6.4 and the other one is Ubuntu 12.04 LTS
一台机器是 CentOS 6.4,另一台机器是 Ubuntu 12.04 LTS
Thanks in advance.
提前致谢。
采纳答案by Osmium USA
On receiving end:
在接收端:
nc -l 1234 > file.tar.gz
On sending end:
在发送端:
cat file.tar.gz | nc <reciever's ip or hostname> 1234
That should work. Depending on the speed, it may take a while but both processes will finish when the transfer is done.
那应该工作。根据速度,可能需要一段时间,但传输完成后两个过程都会完成。
回答by Carl Norum
From the nc(1)
man page:
从nc(1)
手册页:
-l
Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host. It is an error to use this option in conjunction with the -p, -s, or -z options.
-l
用于指定 nc 应侦听传入连接而不是启动与远程主机的连接。将此选项与 -p、-s 或 -z 选项结合使用是错误的。
So your use of -p
is wrong.
所以你的使用-p
是错误的。
Use on server2:
在 server2 上使用:
nc -l 1234 > file.tar.gz
And on server1:
在 server1 上:
nc server2 1234 < file.tar.gz
回答by yash anand
from the sender
来自发件人
nc -v -w 30 1337 - l < filename
where "-v" from verbose, "-w 30" for a wait before and after 30 sec for the connection, "1337" port number, "-l" tell nc that this is a sender
其中“-v”来自verbose,“-w 30”用于连接前后30秒的等待,“1337”端口号,“-l”告诉nc这是一个发件人
from the receiver
nc -v -w 2 ip_add_of_sender 1337 > filename
从接收者
nc -v -w 2 ip_add_of_sender 1337 > filename