转载自:https://blog.youkuaiyun.com/tianzhihen28/article/details/80124535
自动上传到百度云shell脚本
步骤
1
登录网页版百度云
步骤
2
#!/bin/sh
baiduyun()
{
from="$1"
to="$2"
[ -d "${from}" ]&& {
tar -cvzf ${from}.tar.gz "${from}"
from="${from}.tar.gz"
}
[ "${to}" == "" ] && to="/upload/`date +%F`" #会出现13: [: /: unexpected operator,更改成 [ ! -n "${to}" ] && to="/upload/`date +%F`"
echo "upload ${from} to baiduyun : ${to}"
fileName=${from##*/}
encodeFile=$(python -c "import urllib; print urllib.quote('''$fileName''')")
dir=$(python -c "import urllib; print urllib.quote('''${to}''')")
httpcode=$(curl --connect-timeout 15 -m 3600 -k -o /dev/null -s -w %{http_code} \
-X POST \
-F file="@${from}" \
-F filename="${fileName}" \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'DNT: 1' \
-H 'Host: c.pcs.baidu.com' \
-H 'Origin: http://pan.baidu.com' \
-H 'Pragma: no-cache' \
-H 'Referer: http://pan.baidu.com/disk/home' \
-H 'Accept-Encoding: identity' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux; rv:5.0) Gecko/5.0 Firefox/5.0' \
-H 'Cookie: BDUSS=你的cookie' \
"https://c.pcs.baidu.com/rest/2.0/pcs/file?method=upload&ondup=overwrite&app_id=250528&dir=${dir}&filename=${encodeFile}")
echo ${httpcode}
}
baiduyun "$@"
date:2018-7-25
今天我在一台新的Linux主机上通过上述的操作实现上传数据到百度网盘时,出现上传不上的情况
脚本中echo的httpcode始终是000
后来我参照这篇博客:https://www.cnblogs.com/chenliyang/p/6634673.html 想用这种方式把linux资源上传到百度网盘;
按照操作也实现了上传资源,抱着再试试的态度,试了一下前面写的脚本;
居然可以上传了;后面也尝试卸载:
pip uninstall requests
pip uninstall bypy
apt-get remove python-pip
但是还是可以使用脚本上传,记录一下,留着后面研究。
bypy仅能操作网盘/app/bypy目录下的数据
bypy的使用:
显示文件列表: bypy list
把当前目录同步到网盘:bypy syncup or bypy upload
把网盘内容同步到本地:bypy syncdown or bypy downdir
本地当前目录和网盘:bypy compare
上传单个文件到网盘: bypy upload test.txt /
下载单个文件到本地: bypy download test.txt
大文件上传很快,但是下载很慢