9

聊聊几种传文件的方式

 4 years ago
source link: http://vearne.cc/archives/702
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
版权声明 本站原创文章 由 萌叔 发表
转载请注明 萌叔 | http://vearne.cc

聊聊几种服务器之间传文件的方式


1. 使用scp命令

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ... [[user@]host2:]file2

DESCRIPTION :scp copies files between hosts on a network.  

scp 支持传输单个文件和文件夹

2. 使用python

可以直接使用下面命令,启动简单的文件服务器(单线程)

python -m SimpleHTTPServer 8080
wget http://192.168.10.100:8080/tt.png

注意 请自行替换服务地址和文件名

3. 使用nc命令

 nc -l  8080 > tt.png
 nc 192.168.10.100 8080 < tt.png

注意 请自行替换服务地址和文件名

4. lrzsz

rz 
sz /tmp/abc.pdf

lrzsz 也支持Mac,适合大部分场景

5. 开发简单的静态文件服务

笔者之前曾经用过nginx + lua版本,所以这里也实现了一个Golang版本的,核心代码只有40行

  • 支持文件上传
  • 支持开启Basic Auth
  • 服务稳定,适合暂存 临时文件或者需要转交给他人的文件

github地址

vearne/file_transfer

上传/下载

curl -F [email protected] http://localhost:8080/upload 
wget http://localhost:8080/download/tt.png

使用basic auth

curl -F [email protected] http://localhost:8080/upload --user vearne:helloworld
wget --http-user=vearne --http-password=helloworld http://localhost:8080/download/tt.png 

你也可以直接在浏览器中访问以下地址,选择你需要的文件,进行下载文件。

http://localhost:8080/download

如果我的文章对你有帮助,你可以给我打赏以促使我拿出更多的时间和精力来分享我的经验和思考总结。

微信支付码

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK