# 百度网盘SFTP风格命令行工具 **Repository Path**: ptshime/pansftp ## Basic Information - **Project Name**: 百度网盘SFTP风格命令行工具 - **Description**: 一个基于百度网盘开放平台API的命令行工具,提供简单易用的网盘操作功能,让您可以在终端中管理百度网盘文件。 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-11-16 - **Last Updated**: 2025-11-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # BaiduPanSFTP - 百度网盘SFTP风格命令行工具 [](https://opensource.org/licenses/Apache-2.0) [](https://www.python.org/) [](https://gitee.com/solomonxu/pansftp) 一个仿SFTP风格的百度网盘命令行客户端,提供类似FTP/SFTP的交互式文件管理体验。 ## ✨ 功能特点 - 🖥️ **类SFTP交互界面** - 熟悉的命令行操作体验 - 🐍 ​**Python 3.7+支持**​ - 兼容主流Python版本 - 🔐 **OAuth 2.0认证** - 安全的API访问认证 - 📁 **完整的文件操作** - 上传、下载、列表、删除、重命名等 - 🔍 **高级搜索功能** - 支持按类型、排序方式搜索文件 - 🎯 **智能补全** - 支持命令和文件名的Tab自动补全 - 📊 **实时进度显示** - 文件传输进度条和性能统计 - ⚡ **多平台支持** - Linux, macOS, Windows (Git Bash/WSL)/ - 🐳 **会话管理** - 支持会话保存和恢复 ## 📦 安装 ### 系统要求 - Python 3.7+ - 支持的操作系统: Windows, macOS, Linux ### 自动安装脚本 (推荐) ```bash # 下载并运行安装脚本 curl -fsSL https://gitee.com/solomonxu/pansftp/raw/master/install/install.sh | bash ``` 或手动下载后运行: ```bash chmod +x install.sh ./install.sh ``` 安装脚本支持: - Ubuntu/Debian, RHEL/CentOS, macOS, Windows (Git Bash/WSL) 小提示:Ubuntu环境下测试通过,其余环境下已预留,正在测试进行中。 - 自动Python环境检测和安装 - 虚拟环境配置 - 环境变量自动设置 ### 手动安装 1. **克隆项目** ```bash git clone https://gitee.com/solomonxu/pansftp.git cd pansftp ``` 2. **创建虚拟环境** ```bash python3 -m venv venv source venv/bin/activate # Linux/macOS # 或 venv\Scripts\activate # Windows ``` 3. **安装依赖** ```bash pip install -r requirements.txt ``` 4. **运行程序** ```bash cd bin ./pansftp ``` ## 🔧 配置说明 ### 首次使用配置 在使用前需要配置百度网盘开放平台的应用信息: 1. 访问 [百度网盘开放平台](https://pan.baidu.com/union/apply) 2. 创建应用并获取 `client_id/AppKey`和 `client_secret/SecretKey` 3. 在工具中配置: ```bash # 设置客户端配置 config set --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET # 或者使用键值对格式 config set client_id=YOUR_CLIENT_ID client_secret=YOUR_CLIENT_SECRET ``` ### 认证登录 ```bash # 进行OAuth认证 auth # 刷新访问令牌 refresh ``` ## 🚀 使用指南 ### 启动程序 ```bash # 直接启动 pansftp # 或从项目目录 python main.py ``` ### 基本命令 | 命令 | 说明 | 示例 | |------|------|------| | `auth` | OAuth认证 | `auth` | | `config` | 客户端配置 | `config show` | | `ls` | 列出网盘文件 | `ls -s name` | | `cd` | 切换网盘目录 | `cd /我的资源` | | `get` | 下载文件 | `get file.txt` | | `put` | 上传文件 | `put local.txt` | | `lls` | 列出本地文件 | `lls ~/Downloads` | | `lcd` | 切换本地目录 | `lcd ~/Documents` | | `search` | 搜索文件 | `search -t file 文档` | | `mkdir` | 创建目录 | `mkdir new_folder` | | `rm` | 删除文件 | `rm old_file.txt` | | `mv` | 移动/重命名 | `mv old new` | | `cp` | 复制文件 | `cp src dest` | ### 高级功能 #### 文件搜索 ```bash # 搜索文件 search -t file 报告 # 按时间排序搜索 search -s time -r 项目 # 限制搜索结果数量 search -l 50 图片 ``` #### 目录树显示 ```bash # 显示目录树状结构 tree /我的资源 # 显示当前目录树 tree ``` #### 性能统计 ```bash # 显示性能统计 perf # 详细性能信息(暂未实现) perf stats -d detailed # 启用请求跟踪(暂未实现) perf trace on ``` #### 会话管理 ```bash # 显示会话信息 session_info # 重置会话状态 reset_session # 保存当前会话 quit --save ``` ## 📋 命令详解 ### 文件操作命令 ```bash # 列出文件(支持排序) ls [-s SORT_BY] [-r] [path] # -s: 排序方式 (name, time, size) # -r: 正序排列(默认倒序) # 下载文件 get remote_file [local_file] # 上传文件 put local_file [remote_file] # 删除文件(需要确认) rm path ``` ### 目录操作命令 ```bash # 创建目录 mkdir dirname # 切换目录 cd path # 显示当前目录 pwd # 树状显示 tree [path] ``` ### 系统命令 ```bash # 显示帮助 help [command] # 调试模式 debug [on|off] # 显示状态信息 status # 显示网盘容量 quota # 显示用户信息 userinfo ``` ## ⚙️ 配置选项 配置文件位置: `~/.baidupan/config` 支持以下配置项: - `client_id`: 应用ID - `client_secret`: 应用密钥 - `redirect_uri`: 回调地址(默认oob) - `access_token`: 访问令牌 - `refresh_token`: 刷新令牌 ## 🔍 常见问题 ### Q: 认证失败怎么办? A: 检查client_id和client_secret是否正确,确保已在百度开放平台创建应用。 ### Q: 文件上传/下载中断? A: 程序支持断点续传,重新执行命令即可恢复传输。 ### Q: 如何提高传输速度? A: 可以尝试使用`perf`命令查看性能瓶颈,或检查网络连接。 ### Q: 忘记命令用法? A: 使用`help`命令查看帮助,或`help `查看特定命令帮助。 ## 🛠️ 开发指南 ### 项目结构 ``` pansftp/ ├── bin/ # 可执行脚本 ├── src/ # 源代码目录 │ ├── auth.py # 认证管理 │ ├── commands.py # 网盘命令实现 │ ├── config.py # 配置管理 │ ├── download.py # 下载管理 │ ├── help.py # 帮助信息 │ ├── complete.py # 自动补全 │ └── progress.py # 进度显示 ├── main.py # 主程序入口 ├── requirements.txt # 依赖包列表 └── install.sh # 安装脚本 ``` ### 扩展开发 要添加新命令: 1. 在`commands.py`中实现功能 2. 在`help.py`中添加帮助信息 3. 在`main.py`的`BaiduPanSFTP`类中添加`do_命令名`方法 ### 调试模式 ```bash # 启用调试模式 debug on # 显示详细请求信息(暂未实现) perf trace on ``` ## 🤝 贡献指南 欢迎提交Issue和Pull Request! 1. Fork本项目 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`) 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`) 4. 推送到分支 (`git push origin feature/AmazingFeature`) 5. 创建Pull Request ## 📄 许可证 本项目采用 Apache License 2.0 开源许可证,详情请参阅 [LICENSE](LICENSE) 文件。 ```text Copyright 2023 pansftp Contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` ## 📞 支持与联系 - 项目地址:https://gitee.com/solomonxu/pansftp - 问题反馈:https://gitee.com/solomonxu/pansftp/issues - 邮箱:solomonxu@163.com ## 🙏 致谢 感谢以下开源项目: - [requests](https://github.com/psf/requests) - HTTP请求库 - [tqdm](https://github.com/tqdm/tqdm) - 进度条库 - [python-cmd](https://docs.python.org/3/library/cmd.html) - 命令行界面框架 --- **提示**: 使用前请确保已阅读并同意百度网盘API的使用条款。本工具仅用于技术学习和合法用途。