使用transfer部署一个内网上传程序
文章发布较早,内容可能过时,阅读注意甄别。
- 软件官网:https://transfer.sh/
# 1,部署
docker run -d --publish 8001:8080 -v /data/upload/:/data/upload dutchcoders/transfer.sh:latest --provider local --basedir /data/upload --log /data/upload/transfer.log
1
# 2,域名
可以用 NGINX 简单配置一个域名代理。
server {
listen 80;
server_name file.test.com;
root /data/upload;
# 配置内网访问
allow 0.0.0.0/0
deny all;
client_header_timeout 256s;
client_body_timeout 256s;
client_max_body_size 5g;
client_body_buffer_size 256k;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8001;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 3,使用
# Upload:
$ curl --upload-file ./hello.txt https://file.test.com/hello.txt
1
# Encrypt & upload:
$ cat /tmp/hello.txt|gpg -ac -o-|curl -X PUT --upload-file "-" https://file.test.com/test.txt
1
# Download & decrypt:
$ curl https://file.test.com/1lDau/test.txt|gpg -o- > /tmp/hello.txt
1
# Upload to virustotal:
$ curl -X PUT --upload-file nhgbhhj https://file.test.com/test.txt/virustotal
1
# Deleting
$ curl -X DELETE <X-Url-Delete Response Header URL>
1
# 4,优化
# 1,优化脚本
这种可能不太方便,可以创建一个命令,通过命令直接进行上传:
$ cat /usr/local/bin/transfer
#!/bin/bash
# 指定服务 base_url
base_url='http://file.test.com'
get_system() {
uname_str=`uname -a`
if [[ ${uname_str} =~ "Darwin" ]]
then
system_str='osx'
elif [[ ${uname_str} =~ "Linux" ]]
then
system_str='linux'
fi
echo ${system_str}
}
print() {
msg=$1
color=$2
# 按系统指定颜色
system_str=`get_system`
case "${system_str}" in
"linux")
echo_with_color='echo -e'
;;
"osx")
echo_with_color='echo -e'
;;
esac
case "${color}" in
"black")
${echo_with_color} "\033[30m${msg}\033[0m"
;;
"red")
${echo_with_color} "\033[31m${msg}\033[0m"
;;
"green")
${echo_with_color} "\033[32m${msg}\033[0m"
;;
"yellow")
${echo_with_color} "\033[33m${msg}\033[0m"
;;
"blue")
${echo_with_color} "\033[34m${msg}\033[0m"
;;
"purple")
${echo_with_color} "\033[35m${msg}\033[0m"
;;
"sky-blue")
${echo_with_color} "\033[36m${msg}\033[0m"
;;
"white")
${echo_with_color} "\033[37m${msg}\033[0m"
;;
*)
${echo_with_color} ${msg}
esac
}
# print out help for the forgetful
function check_help {
if [ ! -n "$1" ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ] ; then
print '[使用说明]:' green
print '\ttransfer 文件名 [最大下载次数(默认: 25)]'
print '[示例]:' green
print '\ttransfer a.log'
print '\ttransfer a.log 5'
kill -SIGINT $$
fi
}
transfer() {
# 检测帮助文档
check_help $1
file=$1
max_download_num=$2
max_download_days=$3
# check file
if [ ! -f "${file}" ]; then
print "[error]: 您上传的文件${file}不存在或不是文件" red
exit 0
fi
# download_num
if [ ! -n "${max_download_num}" ]; then
max_download_num=25
fi
# download_days
if [ ! -n "${max_download_days}" ]; then
max_download_days=1
fi
# prompt
print "[info]: 你输入的文件是${file} \n[info]: 正在上传, 请稍后..." sky-blue
# 上传
result_url=`curl -H "Max-Downloads: ${max_download_num}" -H "Max-Days: ${max_download_days}" --progress-bar --upload-file "${file}" ${base_url}/$(basename $1)`;
print "[info]: 恭喜你上传成功" sky-blue
print "[info]: 相关信息: \n\t下载次数: ${max_download_num} \n\t下载地址: ${result_url}" sky-blue
exit
}
transfer $*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
用法如下:
$ transfer
[使用说明]:
transfer 文件名 [最大下载次数(默认: 25)] [最大保留时间(单位: 天, 默认: 1)]
[示例]:
transfer a.log
transfer a.log 5
transfer a.log 5 0.1
1
2
3
4
5
6
7
2
3
4
5
6
7
过期之后将会自动清理。
# 2,定时清理
因为程序强调的是文件临时中转,因此最好添加一个定时清理存储目录的任务:
03 03 * * * rsync --delete-before -d /empty/ /data/upload/
1
首先创建一个 /empty
目录,然后每晚清空上传目录。
上次更新: 2024/11/19, 23:11:42