使用nc或者结合tar进行文件传输

王福强


相对于scp来说, 使用nc进行文件传输牵扯步骤要繁琐一些,但可以换取可观的传输速度,对于大文件或者大量文件的传输来说,尤其可取!

单纯使用nc进行文件传输

  1. 在目标机器上执行监听并将接受到的数据重定向到文件nc -l 6969 > targetfile
  2. 在文件源端机器上使用nc连接目标机器并执行文件传输: nc host 6969 < sourcefile

结合tar使用

依然首先在目标机器上执行:

nc -l -p 6969 | tar xf – -C /tmp/

之后,在源端机器上执行:

tar cf – dir | nc -w1 hostB 6969
If the name of the tarfile is ‘-’, tar writes to the standard output or reads from the standard input, whichever is appropriate.

-C directory file

Performs a chdir (see cd(1)) operation on directory and performs the c (create) or r (replace) operation on file . Use short relative path names for file . If file is `.’, archive all files in directory. This option enables archiving files from multiple directories not related by a close common parent.

参考资料

  1. Transferring large amount of data over the network: scp, tar | ssh, tar | nc compared
  2. netcat file transfers
  3. man NC(1)

>>>>>> 更多阅读 <<<<<<

「为AI疯狂」星球上,扶墙老师正在和朋友们讨论有趣的AI话题,你要不要⼀起来呀?^-^
这里

  1. 不但有及时新鲜的AI资讯和深度探讨
  2. 还分享AI工具、产品方法和商业机会
  3. 更有体系化精品付费内容等着你,加入星球(https://t.zsxq.com/0dI3ZA0sL) 即可免费领取。(加入之后一定记得看置顶消息呀!)

知识星球二维码

存量的时代,省钱就是赚钱。
在增量的时代,省钱其实是亏钱。
避坑儿是省钱的一种形式,更是真正聪明人的选择!
弯路虽然也是路,但还是能少走就少走,背后都是高昂的试错成本。
订阅「福报」,少踩坑,少走弯路,多走一步,就是不一样的胜率!

订阅「福报Premium订阅」