caddy - upload file

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 简介

最近面临一次系统跨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
[root@localhost ~]# curl -I https://mirrors.alltobid.com/robots.txt HTTP/2 200 alt-svc: h3=":443"; ma=2592000 cache-control: max-age=2592000 content-type: text/plain date: Sat, 19 Jul 2025 16:14:11 GMT last-modified: Wed, 19 Feb 2025 14:04:48 GMT server: Caddy server: Nexus/3.76.1-01 (OSS) x-content-type-options: nosniff x-frame-options: DENY x-xss-protection: 1; mode=block content-length: 66 [root@localhost ~]# curl -X POST https://mirrors.alltobid.com/api/files -d 'path=../../' <!DOCTYPE html> <html lang="en"> <head> <title>405 - Sonatype Nexus Repository</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <link rel="icon" type="image/png" href="../static/rapture/resources/safari-favicon-32x32.png?3.76.1-01" sizes="32x32"> <link rel="mask-icon" href="../static/rapture/resources/favicon-white.svg?3.76.1-01" color="#00bb6c"> <link rel="icon" type="image/png" href="../static/rapture/resources/favicon.svg?3.76.1-01" sizes="16x16"> <link rel="stylesheet" type="text/css" href="../static/css/nexus-content.css?3.76.1-01"/> </head> <body> <div class="nexus-header"> <a href=".."> <div class="product-logo"> <img src="../static/rapture/resources/nxrm-reverse-icon.png?3.76.1-01" alt="Product logo"/> </div> <div class="product-id"> <div class="product-id__line-1"> <span class="product-name">Sonatype Nexus Repository</span> </div> <div class="product-id__line-2"> <span class="product-spec">OSS 3.76.1-01</span> </div> </div> </a> </div> <div class="nexus-body"> <div class="content-header"> <img src="../static/rapture/resources/icons/x32/exclamation.png?3.76.1-01" alt="Exclamation point" aria-role="presentation"/> <span class="title">Error 405</span> <span class="description">Method Not Allowed</span> </div> <div class="content-body"> <div class="content-section"> HTTP method POST is not supported by this URL </div> </div> </div> </body> </html> [root@localhost ~]#
最新发布
07-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值