Giter Site home page Giter Site logo

bpcs_uploader's Introduction

bpcs_uploader

百度pcs上传脚本

系统要求

Linux (or cygwin) with php & curl installed.

使用方法

chmod +x bpcs_uploader.php
./bpcs_uploader.php

由于VPS上安装的php可能存在于各种地方,因此运行很可能不正常。请以使用which php得到你的php绝对路径,修改bpcs_uploader.php的头一句#!后的路径。 如果你的php是为了网站环境安装的,那么很有可能你会得到下面这条错误消息:

xxx() has been disabled for security reasons

那么说明你的环境由于安全原因禁止了部分函数的执行。请看FAQs的1。请使用那条长长的命令代替./bpcs_uploader.php。eg:php -d disable_functions -d safe_mode=Off -f bpcs_uploader.php quota

快速初始化

./bpcs_uploader.php quickinit

敲下命令直接进入快速初始化流程,输入y,然后打开浏览器访问 https://openapi.baidu.com/device ,在“请输入设备上显示的用户授权码:”文本框中输入上面显示的授权码(这里是12abcxyz),并点击继续。 看到网页上显示“请返回设备继续操作!”后,返回ssh上按下回车后,即完成了初始化配置。

初始化

./bpcs_uploader.php init

敲下命令之后会进入初始化流程,这里分段详述设置方法。

Uploader initialization will be begin. If you have already configured the uploader before, your old settings will be overwritten.
Continue? [y/N] y

确认初始化。如果之前有初始化过,那么以前的配置将会被覆盖。

Please enter your PSC App API Key. You can get this key by visiting http://developer.baidu.com/dev#/create
If you have already created an app, you can visit http://developer.baidu.com/console#/app and get it in your app's info.
If you don't want to bother creating an app, you can press Enter to use the demo API Key.
Doing so (without your own API Key/Secret) will cause the access-token to expire every 30 days, and you'll have to re-initialize when it expires.
App API KEY [uFBSHEwWE6DD94SQx9z77vgG] :

第一步,输入App key。这里需要输入一个有PCS权限的API KEY,如果没有的话直接敲回车就好了,这里会默认使用内置的一组app key,app secret和app folder name,所以只要敲下回车就能直接跳到第四步。如果你没有App secret(例如使用L6g70tBRRIXLsY0Z3HwKqlRE这个Key时),只能获取一个有效期为一个月的access token。如果有一个有PSC权限的API KEY和secret,那么就能获得一个有效期为10年的refresh token,以便长期使用。

App API Key has been set to uFBSHEwWE6DD94SQx9z77vgG .
Please enter your Baidu PSC App API Secret. If you have no idea what it is, keep it blank.
App API SECRET [] :

第二步,输入App secret。如果输入了app secret,将会转到device code模式验证;或者直接输入回车使用oob模式验证。先直接回车:

Please enter your app's folder name. You can choose to input this later in the file [ /root/bpcs_files/config/appname ].
** Why do I have to enter the app's folder name? Please check the FAQs. **
If your app's name has Chinese characters, please ensure that your client supports UTF-8 encoding.
Below are some Chinese characters for testing. Please make sure that you can read them before you enter Chinese here.
这里是一些中文字符。
If you can't read the characters above, please press Enter and change it manually within the file [ /root/bpcs_files/config/appname ].
If you have Enter the key [L6g70tBRRIXLsY0Z3HwKqlRE] (by default) , just press Enter.
App Name [pcstest_oauth] :

第三步,这里需要输入app folder name,也就是你申请API时填写的文件夹名字。详情见FAQ 2。因为是使用的默认的key,所以直接回车即可。

In the next step, you'll have to grab the access_token generated by Baidu.
You can check out this link for more information on this procedure:
http://developer.baidu.com/wiki/index.php?title=docs/pcs/guide/usage_example

Easy Guide:

  1. Visit https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=$appkey&redirect_uri=oob&scope=netdisk
  2. After the page is being redirected (it should show something like OAuth 2.0), copy the current URL to your favorite text editor.
  3. Grab the access_token part, take only the part between "access_token=" and the next "&" symbol (without quotes).
  4. Copy it and paste here, then press Enter.
    access_token[] :

第四步,获取access token。在浏览器中打开上述URL( https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=L6g70tBRRIXLsY0Z3HwKqlRE&redirect_uri=oob&scope=netdisk ),进行授权。 授权完毕后,将会跳到一个写着“百度 Oauth2.0”的页面。复制出其中的网页URL,找到access_token=和&之间的字符串,例如: 3.**05c2ea85d52c2***************a5.2592000.136***9032.3089166538-23**47 将其复制到shell中粘贴并回车。使用这种方式初始化的用户,需要每月重新初始化。

如果第三步输入app secret的时候没有留空,将会得到下面的消息:

Launch your favorite web browser and visit https://openapi.baidu.com/device
Input 12abcxyz as the user code if asked.
After granting access to the application, come back here and press Enter to continue.

来到这里,打开浏览器访问 https://openapi.baidu.com/device ,在“请输入设备上显示的用户授权码:”文本框中输入上面显示的授权码(这里是12abcxyz),并点击继续。 看到网页上显示“请返回设备继续操作!”后,返回ssh上按下回车后,即可继续。

curl -X GET -k -L "...."
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 62 0 62 0 0 40 0 --:--:-- 0:00:01 --:--:-- 235
Access Granted. Your Storage Status: 0.06G/115.00G (0.05%)
Enjoy!

你所看到的输出可能和这里给出的不一样,但是只要看到了存储空间的剩余量,和【Have fun !】提示,即说明成功初始化。

查询容量(配额)

./bpcs_uploader.php quota

结果:

Your Storage Status : 0.06G/115.00G (0.05%)

上传文件

./bpcs_uploader.php upload [path_local] [path_remote]

路径格式:foo/bar/file.ext(路径中一定要包括文件名) 上传后,能在百度网盘/我的应用数据/应用名/foo/bar下找到一个叫file.ext的文件。

下载文件

./bpcs_uploader.php download [path_local] [path_remote]

删除文件

./bpcs_uploader.php delete [path_remote]

离线下载

./bpcs_uploader.php fetch [path_remote] [path_to_fetch]

注:离线下载已经可以正常使用。

FAQs

  1. 各种错误提示

试试php -d disable_functions -d safe_mode=Off -f bpcs_uploader.php

  1. 为什么要输入文件夹名?

因为百度PCS的权限被限制在了/apps/文件夹名/下。如果发现输入文件夹名后仍然无法上传文件,请通过网页版找到【我的应用数据】找到对应的文件夹名,写入/config/appname文件。上传文件的时候会自动帮您处理文件夹,无需手动写出完整路径。

  1. 杀软报毒

某些PHP后门(比如PHPSpy)会调用shell命令,所以杀软以此作为判断PHP病毒的依据。bpcs_uploader只是调用shell命令来实现一些必要的操作(curl、wget等),可以放心使用。

bpcs_uploader's People

Contributors

abstractdatatype avatar ajaxsys avatar coxxs avatar maddie avatar mightbxg avatar oott123 avatar weakish avatar wy0917 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bpcs_uploader's Issues

上传文件是否可以批量上传文件夹和文件呢

./bpcs_uploader.php upload [path_local] [path_remote] //上传文件

这个命令

我使用./bpcs_uploader.php upload /home/bak/uploadfile/* *

这样好像无法上传呢。

请问下是否可以像windows系统下百度网盘客户端那样。同步多个文件夹和文件呢。

ERROR thrown at bpcs_uploader/_bpcs_files_/common.inc.php

root@domain [~/src]# git clone [email protected]:oott123/bpcs_uploader.git
Cloning into 'bpcs_uploader'...
remote: Counting objects: 181, done.
remote: Total 181 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (181/181), 56.57 KiB | 0 bytes/s, done.
Resolving deltas: 100% (63/63), done.
Checking connectivity... done.
root@domain [~/src]# cd bpcs_uploader/
root@domain [~/src/bpcs_uploader]# chmod +x bpcs_uploader.php
root@domain [~/src/bpcs_uploader]# ./bpcs_uploader.php init
X-Powered-By: PHP/5.5.17
Content-type: text/html

===========================Baidu PCS Uploader===========================
Usage: ./bpcs_uploader.php init|quickinit|quota
Usage: ./bpcs_uploader.php upload|download path_local path_remote
Usage: ./bpcs_uploader.php delete path_remote
Usage: ./bpcs_uploader.php uploadbig path_local path_remote [slice_size(default:1073741824)] [temp_dir(def:/tmp/)]
Usage: ./bpcs_uploader.php fetch path_remote path_to_fetch
========================================================================
Uploader initialization will be begin. If you have already configured the uploader before, your old settings will be overwritten.
Continue? [y/N] err2 : /root/src/bpcs_uploader/_bpcs_files_/common.inc.php (11) fgets() expects parameter 1 to be resource, string given
Exiting ...
root@domain [~/src/bpcs_uploader]#

上传失败。

错误代码:
API calling error 31024 : app id is empty

是不是因为我的应用百度还没有审核通过的原因?

关于API回调地址

不知道您还看不看issues,当我知道百度云pcs的时候已经不能申请了,我的应用是web端的,不可能每次去页面取code,我看了文档,只要知道您的回调地址,我可以转到我的页面,如果方便希望告诉我一下,不胜感激。

上传速度

请问这个脚本对上传速度有限制吗?
我上传的时候速度好像总是在400-500k以下,是因为本地服务器网速原因,还是说传输速度就是限制这个水平?

用户授权码错误

最近quickinit无法授权,程序返回了授权码但是在 https://openapi.baidu.com/device 上显示授权码错误,请问有遇到吗?

Missing variable in md5check()

function md5check($argv2, $argv4) {
if (is_file($argv2)) {
$a = 'md5sum "' . $argv2 . '"';
cmd($a, true);
// TODO: Where is $r?
if ($r == $argv4) {
echon("--" . date("Y-m-d") . " " . date("h:i:sa") . "-- local file's MD5 is " . $r . ",the remote flie's MD5 is " . $argv4 . ",they are equal,so no need to download.", false, 32);

Need to fix and test

win下上传出错,其他功能正常

win下使用download方法出错,报403,dirdown同样报错,’bu.php’ 不是内部或外部命令,也不是可运行的程序或批处理文件。其他方法正常。curl和wget已经安装。

上传时文件名没有编码,导致某些文件名不能上传

上传时文件名没有编码,导致某些文件名不能上传
./bpcs_uploader.php upload ~/iPhone5,1_7.1.2_11D257_Restore.ipsw iOS/iPhone51_7.1.2_11D257_Restore.ipsw
curl: (26) failed creating formpost data
API calling faild.
上传失败。

mv ~/iPhone5,1_7.1.2_11D257_Restore.ipsw ~/iPhone5-1_7.1.2_11D257_Restore.ipsw

./bpcs_uploader.php upload ~/iPhone5-1_7.1.2_11D257_Restore.ipsw iOS/iPhone5-1_7.1.2_11D257_Restore.ipsw
上传成功。

Reading of /app/name should avoid adding newline

请通过网页版找到【我的应用数据】找到对应的文件夹名,写入/config/appname文件。

It seems the current way to write the folder name is via echo -n:

echo -n 'bpcs_uploader' > _bpcs_files_/config/appname

Without -n, or manually edit the file with a normal editor, it fails.
It seems that bpcs_uploader thinks the directory name is bpcs_uploader%0A instead.

Can't set Secret Key

在设置了APP key之后,应该设置secret key,但是这一部分是直接显示了源码,而没有输入提示,之后就要求输入app folder name了。这是可能是什么问题?

现在没法初始化了

最后会提示
API calling error 31024 : app id is empty
我在两个VPS上都试过了,但原来初始化好的上传没问题,只是如果新买了一个VPS然后初始化的时候就会提示这个。

减少不必要的 token refresh

do_oauth_refresh 函数每次使用时都会调用。

建议根据token里的时间参数来决定是否要refresh。只有当access token即将过期的时候才刷新。

API calling faild.

你好,百度是否对文件大小有限制?

我原本有一个文件夹3.9G上传,显示 API calling faild.
于是分成两份文件,一个1.9G的tar.gz上传没问题,另一个2.4G的ISO文件仍然显示 API calling faild.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.