任何事情都需要耐心和细心,心急吃不了热豆腐。
需要在aria2配置文件里面把脚本路径配置上
vi /root/.aria2/aria2.conf
on-download-complete=/root/upload.sh
然后创建脚本(路径都改成自己的包括php)
#!/bin/bash
path=$3
#aria2的下载目录
downloadpath='/www/wwwroot/aria2/download'
#OneDrive的下载目录
folder='Download'
if [ $2 -eq 0 ]
then
exit 0
fi
while true; do
filepath=$path
path=${path%/*};
#把下面4个oneindex_com替换成自己oneindex的位置
if [ "$path" = "$downloadpath" ] && [ $2 -eq 1 ]
then
/www/server/php/72/bin/php /www/wwwroot/pan.shazi.co/one.php upload:file "$filepath" /$folder/
rm -rf "$filepath"
rm -rf "$filepath+.aria2"
/www/server/php/72/bin/php /www/wwwroot/pan.shazi.co/one.php cache:refresh
exit 0
elif [ "$path" = "$downloadpath" ]
then
/www/server/php/72/bin/php /www/wwwroot/pan.shazi.co/one.php upload:folder "$filepath" /$folder/
rm -rf "$filepath/"
/www/server/php/72/bin/php /www/wwwroot/pan.shazi.co/one.php cache:refresh
exit 0
fi
done

然后在ar后台下载一个小的文件,下载完成后看看会不会自动上传。
会自动上传,但是会丢数据或者不完整,意外不意外?
下面来说第二种方法(这个方法我试的没问题,自己去看,别问我为什么不转载)
https://www.moerats.com/archives/697/
D="$1";
FileNum="$2";
File="$3";
MaxSize="15728640"
RemoteDIR="Download"; #上传到Onedrive的路径,默认为根目录,如果要上传到指定目录,方法看文章最后面。
LocalDIR="/www/wwwroot/aria2/download/"; #Aria2下载目录,记得最后面加上/
if [[ -z $(echo "$FileNum" |grep -o '[0-9]*' |head -n1) ]]; then FileNum='0'; fi
if [[ "$FileNum" -le '0' ]]; then exit 0; fi
if [[ "$#" != '3' ]]; then exit 0; fi
function LoadFile(){
IFS_BAK=$IFS
IFS=$'\n'
if [[ ! -d "$LocalDIR" ]]; then return; fi
if [[ -e "$File" ]]; then
if [[ $(dirname "$File") == $(readlink -f $LocalDIR) ]]; then
ONEDRIVE="onedrive";
else
ONEDRIVE="onedrive-d";
fi
FileLoad="${File/#$LocalDIR}"
while true
do
if [[ "$FileLoad" == '/' ]]; then return; fi
echo "$FileLoad" |grep -q '/';
if [[ "$?" == "0" ]]; then
FileLoad=$(dirname "$FileLoad");
else
break;
fi;
done;
if [[ "$FileLoad" == "$LocalDIR" ]]; then return; fi
if [[ -n "$RemoteDIR" ]]; then
Option=" -f $RemoteDIR";
else
Option="";
fi
EXEC="$(command -v $ONEDRIVE)";
if [[ -z "$EXEC" ]]; then return; fi
cd "$LocalDIR";
if [[ -e "$FileLoad" ]]; then
ItemSize=$(du -s "$FileLoad" |cut -f1 |grep -o '[0-9]*' |head -n1)
if [[ -z "$ItemSize" ]]; then return; fi
"upload.sh" 57L, 1678C
D="$1";
FileNum="$2";
File="$3";
MaxSize="15728640"
RemoteDIR="Download"; #上传到Onedrive的路径,默认为根目录,如果要上传到指定目录
,方法看文章最后面。
LocalDIR="/www/wwwroot/aria2/download/"; #Aria2下载目录,记得最后面加上/
if [[ -z $(echo "$FileNum" |grep -o '[0-9]*' |head -n1) ]]; then FileNum='0'; fi
if [[ "$FileNum" -le '0' ]]; then exit 0; fi
if [[ "$#" != '3' ]]; then exit 0; fi
function LoadFile(){
IFS_BAK=$IFS
IFS=$'\n'
if [[ ! -d "$LocalDIR" ]]; then return; fi
if [[ -e "$File" ]]; then
if [[ $(dirname "$File") == $(readlink -f $LocalDIR) ]]; then
ONEDRIVE="onedrive";
else
ONEDRIVE="onedrive-d";
fi
FileLoad="${File/#$LocalDIR}"
D="$1";
FileNum="$2";
File="$3";
MaxSize="15728640"
RemoteDIR="Download"; #上传到Onedrive的路径,默认为根目录,如果要上传到指定目录,方法看文章最后面。
LocalDIR="/www/wwwroot/aria2/download/"; #Aria2下载目录,记得最后面加上/
if [[ -z $(echo "$FileNum" |grep -o '[0-9]*' |head -n1) ]]; then FileNum='0'; fi
if [[ "$FileNum" -le '0' ]]; then exit 0; fi
if [[ "$#" != '3' ]]; then exit 0; fi
function LoadFile(){
IFS_BAK=$IFS
IFS=$'\n'
if [[ ! -d "$LocalDIR" ]]; then return; fi
if [[ -e "$File" ]]; then
if [[ $(dirname "$File") == $(readlink -f $LocalDIR) ]]; then
ONEDRIVE="onedrive";
else
ONEDRIVE="onedrive-d";
fi
FileLoad="${File/#$LocalDIR}"
while true
do
if [[ "$FileLoad" == '/' ]]; then return; fi
echo "$FileLoad" |grep -q '/';
if [[ "$?" == "0" ]]; then
FileLoad=$(dirname "$FileLoad");
else
break;
fi;
done;
if [[ "$FileLoad" == "$LocalDIR" ]]; then return; fi
if [[ -n "$RemoteDIR" ]]; then
Option=" -f $RemoteDIR";
else
Option="";
fi
EXEC="$(command -v $ONEDRIVE)";
if [[ -z "$EXEC" ]]; then return; fi
cd "$LocalDIR";
if [[ -e "$FileLoad" ]]; then
ItemSize=$(du -s "$FileLoad" |cut -f1 |grep -o '[0-9]*' |head -n1)
if [[ -z "$ItemSize" ]]; then return; fi
if [[ "$ItemSize" -ge "$MaxSize" ]]; then
echo -ne "\033[33m$File \033[0mtoo large to spik.\n";
return;
fi
eval "${EXEC}${Option}" \'"${FileLoad}"\';
if [[ $? == '0' ]]; then
rm -rf "$FileLoad";
fi
fi
fi
IFS=$IFS_BAK
}
LoadFile;
onedrive安装
wget --no-check-certificate -qO- "https://raw.githubusercontent.com/0oVicero0/OneDrive/master/OneDrive.sh" |bash
如果我们要上传/root
文件夹里面的moerats.txt
,使用命令:
#此命令默认上传到OneDrive根目录
onedrive '/root/moerats.txt'
#如果上传到指定文件夹,就需要加-f参数
onedrive -f RATS '/root/moerats.txt' #上传到OneDrive根目录的RATS文件夹
onedrive -f RATS/RATS '/root/moerats.txt' #上传到OneDrive根目录RATS文件夹里的RATS文件夹
如果我们要将/root
文件夹及里面的文件夹和文件一起上传,使用命令:
#此命令默认上传到OneDrive根目录
onedrive-d '/root'
#如果上传到指定文件夹,就需要加-f参数
onedrive-d -f RATS '/root' #上传到OneDrive根目录的RATS文件夹
onedrive-d -f RATS/RATS '/root' #上传到OneDrive根目录RATS文件夹里的RATS文件夹
如果我们想直接查看OneDrive
网盘目录的文件,使用命令:
#此命令只查看根目录文件
onedrive -l
#如果我们要查看根目录root文件夹里的文件
onedrive -l /root