打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Linux实现上传文件到百度网盘

一、需要安装的工具:

①、 python-pip 注解:pip 是 Python 包管理工具,该工具提供了对Python 包的查找、下载、安装、卸载的功能。

②、 requests 注解:requests 是 是用python语言基于urllib编写的,采用的是Apache2 Licensed开源协议的HTTP库。

③、 bypy 注解:bypy是百度网盘的python客户

安装命令:

yum install python-pip
pip install requests
pip install bypy

python-pip 安装失败【提示:没有可用软件包 python-pip。】

解决方法如下:

先安装epel-release,这个包包含了 EPEL 源的 gpg 密钥和软件源信息,该软件包会自动配置yum的软件仓库

[root@localhost yum.repos.d]#yum -y install epel-release

二、授权登录:

执行 bypy info,显示下边信息,根据提示,通过浏览器访问下边灰色的https链接,如果此时百度网盘账号正在登陆,会出现长串授权码,复制。

[root@ineedle ~]# bypy info 

Please visit: # 访问下边这个连接,复制授权码
https://openapi.baidu.com/oauth/2.0/authorize?scope=basic+netdisk&redirect_uri=oob&response_type=code&client_id=q8WE4EpCsau1oS0MplgMKNBn

And authorize this app Paste the Authorization Code here within 10 minutes. Press [Enter] when you are done # 提示在下边粘贴授权码

a0bd012145abd7caa508618d985f8cfb    #这是 访问上面网址的百度网盘授权码 
Authorizing, please be patient, it may take upto 300 seconds…
Authorizing/refreshing with the OpenShift server …
OpenShift server failed, authorizing/refreshing with the Heroku server …
Heroku server failed, authorizing/refreshing with the Heroku1 server …
Successfully authorized   #显示认证成功
Quota: 2.011TB 
Used: 1.192TB

三、常用命令:

bypy list             查看目录
bypy mkdir         新建目录
bypy upload       把本地当前目录下的文件同步到百度云盘
bypy downdir     把云盘上的内容同步到本地
bypy list #显示文档
bypy upload filename         上传文档
bypy downdir filename       下载文件(存在问题)
bypy compare                     比较本地当前目录和云盘(程序的)根目录
bypy -c  取消令牌文件。一段时间后要重新授权

四、文件上传与同步:

在本地创建一个KormeeSData文件夹,再在文件夹下创建一个test.txt文本文件。如下:

[root@localhost var]# mkdir KormeeSData
[root@localhost var]# cd ./Korm*
[root@localhost KormeeSData]# vim test.txt

编辑test.txt的内容如下:


上面编辑的test.txt上传到百度云

[root@localhost KormeeSData]# bypy upload


上图可以看到test.txt已经上传成功了!

注意事项:
由于百度PCS API权限限制,程序只能存取百度云端/apps/bypy目录下面的文件和目录。

其他操作:
把云盘上的内容同步到本地。命令如下:

[root@localhost KormeeSData]#bypy downdir
比较本地当前目录和云盘根目录,看是否一致,来判断是否同步成功:
[root@localhost KormeeSData]#bypy compare
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
centos7下使用PlayOnLinux安装windows软件
yum makecache报错
Fedora
CentOS一分钟更换163的yum源
Linux CentOS更换国内 阿里/网易 yum源 | 2018最新
CentOS更改yum源与更新系统
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服