caddy - upload file

本文介绍了一次系统跨AWS迁移过程中使用Caddy服务器及其upload插件进行文件传输的方法。对比scp和rsync等传统工具,Caddy提供了更为便捷且支持HTTP协议的文件上传方案。
  • 简介

最近面临一次系统跨AWS迁移,迁移过程中,少不了有文件进行传输,一般会使用scp,但是这个又牵扯到密码验证,或者key文件验证,而且scp在长距离传输的过程中速度会非常的慢;如果采用rsync,也还行,但是多少有点不太心甘情愿,而且还得安装rsync;是否可以走http协议uploadfile呢? 刚好最近看到caddy这个小巧的http服务器,而且居然发现了支持upload插件,于是小测了一下。

下载文件

http://ojv12llai.bkt.clouddn.com/uploads/20170328135542.gz

如果从官网下载,地址 https://caddyserver.com/download, 可以选择不同的插件, 插件越多,功能也会越多,但是文件体积也会越大。

解压后,把caddy 文件放到 /bin/下面,直接调用就不用输入全路径了.

配置文件

/etc/caddy.conf

:2016 {
    root /opt/caddy
    upload /upload {
      to /opt/caddy/upload
      yes_without_tls # 不写这个,貌似必须使用https了
}
filemanager /uploadmanager {
    show           /opt/caddy/upload
    allow_new      true
    allow_edit     true
    allow_commands true
    allow_command  git
    block_command  command
    block          dotfiles
}
}

上传测试

# 使用如下的命令会将本地的/etc/passwd传上去,但是注意,
# 1. 文件名会覆盖哦
# 2. tar个包,一来增加速度,二来只能传输文件
# 3. upload后边的/不跟的话,会302转向的
# 4. -F后边的data貌似跟啥字母都行,没有实际意义
curl -F data=@/etc/passwd http://116.251.211.183:2016/upload/
httplib库传输range之后的文件失败是什么原因 xiaoyong@DZ0105952:~$ curl -H "Range: bytes=13-100" http://127.0.0.1:8081/download --output first_10.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 85 88 85 75 0 0 74 0 0:00:01 0:00:01 --:--:-- 74^C xiaoyong@DZ0105952:~$ curl -H "Range: bytes=14-100" http://127.0.0.1:8081/download --output first_10.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 83 87 83 73 0 0 18 0 0:00:04 0:00:04 --:--:-- 18^C xiaoyong@DZ0105952:~$ curl -H "Range: bytes=14-100" http://127.0.0.1:8081/download --output first_10.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 83 87 83 73 0 0 14 0 0:00:06 0:00:05 0:00:01 0 curl: (18) transfer closed with 14 bytes remaining to read xiaoyong@DZ0105952:~$ curl -H "Range: bytes=10-100" http://127.0.0.1:8081/download --output first_10.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 89 91 89 81 0 0 16 0 0:00:05 0:00:05 --:--:-- 0 curl: (18) transfer closed with 10 bytes remaining to read xiaoyong@DZ0105952:~$ curl -H "Range: bytes=50-100" http://127.0.0.1:8081/download --output first_10.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 1 51 0 1 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0 curl: (18) transfer closed with 50 bytes remaining to read xiaoyong@DZ0105952:~$ curl -H "Range: bytes=50-100" http://127.0.0.1:8081/download --output first_10.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 1 51 0 1 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0 curl: (18) transfer closed with 50 bytes remaining to read xiaoyong@DZ0105952:~$ ^C xiaoyong@DZ0105952:~$ curl -H "Range: bytes=50-100" http://127.0.0.1:8081/download --output first_10.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 1 51 0 1 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0
07-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值