惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

酷酷的白

拍到了南湖的花花 - 酷酷的白 花花草草才是最爱 - 酷酷的白 休闲一刻,大理环洱海一日游 - 酷酷的白 记今日摘菊,拾起老家的小美好 - 酷酷的白 好家伙,前两天才开发了一个基于Alist的文件床(图床)项目,今天就被爆出了Alist被卖的消息 - 酷酷的白 在老家待了半年,学会了一项技能:嫁接 - 酷酷的白 批量删除Mattermost频道聊天记录的脚本 - 酷酷的白 在Linux 服务器下安装Warp并配置代理模式 - 酷酷的白 通过配置Ngixn Proxy Manager 与 Fail2ban 实现在 Cloudflare 上拦截恶意请求 - 酷酷的白
Linux下通过Curl 上传文件到Aalist 脚本 - 酷酷的白
mengkun · 2025-03-19 · via 酷酷的白

Alist 是一个支持多种存储的文件列表程序,挂载各大网盘也是非常方便,在服务器内网部署一个alist 并且挂载各大网盘可实现将本地文件的备份和同步到云上。一般情况下的操作就是Alist 的webdav + rclone 的方式,不过 alist 的 webdav 协议遇到大文件会出现问题,但是通过正常的 http 上传就不会有太大的问题。alist api 上传文件的原理是先通过登录账号获取到token ,然后使用带有token的请求上传文件,token 可以通过网页登录的然后浏览器 F12 形式获取,不过这个获取的 token 有一定的时限,所以使用脚本自动化的形式自动获取并实现登录并上传。

脚本

新建一个脚本文件,如: xxx.sh 新建并编辑

vim xxx.sh

i 把以下脚本复制进去,之后按 esc 在按 :wq保持并退出

#!/bin/bash

# 检查参数数量
if [ $# -ne 6 ]; then
    echo "Usage: $0 --username <username> --password <password> <local-file> <alist-url>"
    exit 1
fi

# 解析输入参数
USERNAME=$2
PASSWORD=$4
LOCAL_FILE=$5
REMOTE_PATH=$6

# 从 URL 中提取 alist app 的 base URL
BASE_URL=$(echo $REMOTE_PATH | sed -E 's|(https?://[^/]+).*|\1|')

# 提取 URL 路径部分(去除 BASE_URL)
REMOTE_FILE_PATH=$(echo $REMOTE_PATH | sed "s|$BASE_URL||")

# 获取 token
RESPONSE=$(curl --location --request POST "$BASE_URL/api/auth/login" \
--header 'Content-Type: application/json' \
--data-raw "{ \"username\": \"$USERNAME\", \"password\": \"$PASSWORD\" }")

# 提取 token
TOKEN=$(echo $RESPONSE | grep -o '"token":"[^"]*' | grep -o '[^"]*$')

if [ -z "$TOKEN" ]; then
    echo "Error: Failed to get token"
    exit 1
fi

# 上传文件
UPLOAD_URL="$BASE_URL/api/fs/put"
curl -# -T "$LOCAL_FILE" "$UPLOAD_URL" \
  -H "Authorization: $TOKEN" \
  -H "File-Path: $REMOTE_FILE_PATH/$LOCAL_FILE"

# 提示用户上传完成
if [ $? -eq 0 ]; then
    echo "Upload successful!"
else
    echo "Upload failed!"
fi

脚本使用

为脚本赋予执行权限

chmod +x xxx.sh

运行脚本

./xxx.sh --username <username> --password <password> <local-file> <alist-url>

替换 <> 中的内容,不保留 <> , --username--password 必须保留

  • <username> alist 登录账号
  • <password> alist 登录密码
  • <local-file> 本地需要上传的文件
  • <ailst-url> alist的地址,如:保存到 /buckup - https://127.0.0.1/buckup ,加上端口的话 https://127.0.0.1:5244/buckup

相关文档

9人点赞

打赏