首页 > 编程知识 正文

百度网盘怎么上传文件,怎么上传文件到百度网盘

时间:2023-05-03 17:54:31 阅读:272228 作者:430

一、需要安装的工具:

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

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

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

安装命令:

yum install python-pippip install requestspip 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=q8WE4EpCsau1oS0MplgMKNBnAnd 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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。