react-native-kookit 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG_CONTENT_URI.md +130 -0
- package/IMPLEMENTATION_SUMMARY.md +206 -0
- package/README.md +21 -1
- package/android/src/main/java/expo/modules/kookit/ReactNativeKookitModule.kt +139 -0
- package/build/ReactNativeKookitModule.d.ts +28 -0
- package/build/ReactNativeKookitModule.d.ts.map +1 -1
- package/build/ReactNativeKookitModule.js.map +1 -1
- package/package.json +1 -1
- package/ANDROID_BUILD_FIX.md +0 -117
- package/ANDROID_FTP_UPDATE.md +0 -161
- package/ANDROID_PARAMETER_FIX.md +0 -0
- package/ANDROID_SETUP.md +0 -188
- package/ANDROID_SMB_LIBRARY_COMPARISON.md +0 -170
- package/ANDROID_SMB_LISTSHARES_FIX.md +0 -100
- package/API_UNIFICATION.md +0 -180
- package/EXPO_PLUGIN_README.md +0 -136
- package/FTP_CLIENT_API.md +0 -301
- package/FTP_EXAMPLE_IMPLEMENTATION.md +0 -0
- package/FTP_FILE_LIST_ENHANCEMENT.md +0 -186
- package/FTP_FILE_OPERATIONS.md +0 -0
- package/FTP_README.md +0 -322
- package/README_NEW.md +0 -143
- package/RELEASE_CHECKLIST.md +0 -115
- package/SMB_CLIENT_STATIC_METHODS.md +0 -175
- package/SMB_COMPLETE_GUIDE.md +0 -308
- package/SMB_HYBRID_IMPLEMENTATION.md +0 -160
- package/SMB_IMPLEMENTATION_SUMMARY.md +0 -229
- package/SMB_USAGE.md +0 -275
- package/TROUBLESHOOTING.md +0 -132
package/RELEASE_CHECKLIST.md
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
# React Native Kookit - 发布前检查
|
|
2
|
-
|
|
3
|
-
## 修复的主要问题
|
|
4
|
-
|
|
5
|
-
✅ **Plugin undefined 错误**
|
|
6
|
-
|
|
7
|
-
- 修复了 package.json 中插件配置位置
|
|
8
|
-
- 添加了 @expo/config-plugins 依赖
|
|
9
|
-
- 改进了 app.plugin.js 的错误处理
|
|
10
|
-
|
|
11
|
-
✅ **插件导出问题**
|
|
12
|
-
|
|
13
|
-
- 确保插件正确导出为 ConfigPlugin 函数
|
|
14
|
-
- 添加了fallback处理
|
|
15
|
-
|
|
16
|
-
## 当前文件结构
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
react-native-kookit/
|
|
20
|
-
├── package.json # 主包配置,包含插件配置
|
|
21
|
-
├── app.plugin.js # 插件入口文件
|
|
22
|
-
├── plugin/ # 插件源码目录
|
|
23
|
-
│ ├── package.json # 插件依赖
|
|
24
|
-
│ ├── tsconfig.json # TypeScript 配置
|
|
25
|
-
│ ├── src/
|
|
26
|
-
│ │ └── withVolumeKeyIntercept.ts # 插件实现
|
|
27
|
-
│ └── build/ # 编译后的插件
|
|
28
|
-
│ └── withVolumeKeyIntercept.js
|
|
29
|
-
├── README_NEW.md # 更新的文档
|
|
30
|
-
├── TROUBLESHOOTING.md # 故障排除指南
|
|
31
|
-
└── EXPO_PLUGIN_README.md # 插件详细说明
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## 测试步骤
|
|
35
|
-
|
|
36
|
-
### 1. 本地测试插件加载
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
cd /path/to/react-native-kookit
|
|
40
|
-
node -e "
|
|
41
|
-
const plugin = require('./app.plugin.js');
|
|
42
|
-
console.log('Plugin type:', typeof plugin);
|
|
43
|
-
console.log('Plugin loaded:', typeof plugin === 'function' ? '✅ Success' : '❌ Failed');
|
|
44
|
-
"
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### 2. 在测试项目中验证
|
|
48
|
-
|
|
49
|
-
1. 创建新的 Expo 项目:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
npx create-expo-app TestKookit
|
|
53
|
-
cd TestKookit
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
2. 添加本地模块:
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
npm install ../react-native-kookit
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
3. 配置 app.json:
|
|
63
|
-
|
|
64
|
-
```json
|
|
65
|
-
{
|
|
66
|
-
"expo": {
|
|
67
|
-
"plugins": ["react-native-kookit"]
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
4. 预构建:
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
npx expo prebuild --clean
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
5. 检查生成的 MainActivity 是否包含必要代码
|
|
79
|
-
|
|
80
|
-
### 3. 发布验证
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
# 构建插件
|
|
84
|
-
npm run build-plugin
|
|
85
|
-
|
|
86
|
-
# 检查文件
|
|
87
|
-
ls -la plugin/build/
|
|
88
|
-
|
|
89
|
-
# 发布(测试版本)
|
|
90
|
-
npm publish --tag beta
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## 用户使用流程验证
|
|
94
|
-
|
|
95
|
-
### 正确的用户步骤:
|
|
96
|
-
|
|
97
|
-
1. ✅ `npm install react-native-kookit`
|
|
98
|
-
2. ✅ 在 app.json 添加 `"plugins": ["react-native-kookit"]`
|
|
99
|
-
3. ✅ `npx expo prebuild --clean`
|
|
100
|
-
4. ✅ `npx expo run:android`
|
|
101
|
-
|
|
102
|
-
### 预期结果:
|
|
103
|
-
|
|
104
|
-
- MainActivity 自动包含 VolumeKeyInterceptActivity 接口
|
|
105
|
-
- 音量键监听功能正常工作
|
|
106
|
-
- 无需手动修改原生代码
|
|
107
|
-
|
|
108
|
-
## 发布清单
|
|
109
|
-
|
|
110
|
-
- [ ] 插件本地测试通过
|
|
111
|
-
- [ ] 在新项目中端到端测试
|
|
112
|
-
- [ ] 文档更新完成
|
|
113
|
-
- [ ] 版本号更新
|
|
114
|
-
- [ ] README 更新为 README_NEW.md
|
|
115
|
-
- [ ] 发布到 npm
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# SMB Client 静态方法使用示例
|
|
2
|
-
|
|
3
|
-
SmbClient新增了多个静态方法来管理多个客户端实例:
|
|
4
|
-
|
|
5
|
-
## 新增的静态方法
|
|
6
|
-
|
|
7
|
-
### 1. `SmbClient.disposeClient(clientId: string)`
|
|
8
|
-
|
|
9
|
-
销毁指定客户端ID的客户端实例
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
// 销毁特定的客户端
|
|
13
|
-
const disposed = await SmbClient.disposeClient("my_client_id");
|
|
14
|
-
console.log("Client disposed:", disposed); // true/false
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
### 2. `SmbClient.getClientStatus(clientId: string)`
|
|
18
|
-
|
|
19
|
-
获取指定客户端ID的状态信息
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
// 获取客户端状态
|
|
23
|
-
const status = SmbClient.getClientStatus("my_client_id");
|
|
24
|
-
console.log("Client status:", status);
|
|
25
|
-
// 返回: {
|
|
26
|
-
// exists: true,
|
|
27
|
-
// isConnected: true,
|
|
28
|
-
// currentShare: 'C$',
|
|
29
|
-
// isDisposed: false
|
|
30
|
-
// }
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### 3. `SmbClient.getAllClientsStatus()`
|
|
34
|
-
|
|
35
|
-
获取所有活跃客户端的状态
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
// 获取所有客户端状态
|
|
39
|
-
const allStatus = SmbClient.getAllClientsStatus();
|
|
40
|
-
allStatus.forEach((status, clientId) => {
|
|
41
|
-
console.log(`Client ${clientId}:`, status);
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### 4. `SmbClient.getInstance(clientId: string)`
|
|
46
|
-
|
|
47
|
-
获取指定客户端ID的实例对象
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
// 获取现有的客户端实例
|
|
51
|
-
const existingClient = SmbClient.getInstance("my_client_id");
|
|
52
|
-
if (existingClient) {
|
|
53
|
-
await existingClient.listFiles("/");
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### 5. `SmbClient.disposeAllClients()`
|
|
58
|
-
|
|
59
|
-
销毁所有客户端实例
|
|
60
|
-
|
|
61
|
-
```typescript
|
|
62
|
-
// 清理所有客户端
|
|
63
|
-
const disposedCount = await SmbClient.disposeAllClients();
|
|
64
|
-
console.log(`Disposed ${disposedCount} clients`);
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## 使用示例
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
import SmbClient from "react-native-kookit";
|
|
71
|
-
|
|
72
|
-
export class SmbManager {
|
|
73
|
-
private clients: Map<string, SmbClient> = new Map();
|
|
74
|
-
|
|
75
|
-
// 创建命名客户端
|
|
76
|
-
async createNamedClient(
|
|
77
|
-
name: string,
|
|
78
|
-
config: SmbConnectionConfig
|
|
79
|
-
): Promise<SmbClient> {
|
|
80
|
-
const client = await SmbClient.create(name);
|
|
81
|
-
await client.connect(config);
|
|
82
|
-
this.clients.set(name, client);
|
|
83
|
-
return client;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// 检查客户端是否存在且连接
|
|
87
|
-
isClientReady(name: string): boolean {
|
|
88
|
-
const status = SmbClient.getClientStatus(name);
|
|
89
|
-
return status.exists && status.isConnected && !status.isDisposed;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// 安全获取客户端
|
|
93
|
-
getClient(name: string): SmbClient | null {
|
|
94
|
-
if (this.isClientReady(name)) {
|
|
95
|
-
return SmbClient.getInstance(name);
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 销毁指定客户端
|
|
101
|
-
async removeClient(name: string): Promise<boolean> {
|
|
102
|
-
this.clients.delete(name);
|
|
103
|
-
return await SmbClient.disposeClient(name);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// 获取所有客户端状态报告
|
|
107
|
-
getStatusReport(): Record<string, any> {
|
|
108
|
-
const report: Record<string, any> = {};
|
|
109
|
-
const allStatus = SmbClient.getAllClientsStatus();
|
|
110
|
-
|
|
111
|
-
allStatus.forEach((status, clientId) => {
|
|
112
|
-
report[clientId] = {
|
|
113
|
-
...status,
|
|
114
|
-
managed: this.clients.has(clientId),
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
return report;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 清理所有资源
|
|
122
|
-
async cleanup(): Promise<void> {
|
|
123
|
-
this.clients.clear();
|
|
124
|
-
await SmbClient.disposeAllClients();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 使用示例
|
|
129
|
-
const smbManager = new SmbManager();
|
|
130
|
-
|
|
131
|
-
// 创建多个客户端
|
|
132
|
-
const client1 = await smbManager.createNamedClient("server1", {
|
|
133
|
-
host: "192.168.1.100",
|
|
134
|
-
username: "user1",
|
|
135
|
-
password: "pass1",
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const client2 = await smbManager.createNamedClient("server2", {
|
|
139
|
-
host: "192.168.1.101",
|
|
140
|
-
username: "user2",
|
|
141
|
-
password: "pass2",
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// 检查状态
|
|
145
|
-
console.log("Status report:", smbManager.getStatusReport());
|
|
146
|
-
|
|
147
|
-
// 使用特定客户端
|
|
148
|
-
const client = smbManager.getClient("server1");
|
|
149
|
-
if (client) {
|
|
150
|
-
const files = await client.listFiles("/");
|
|
151
|
-
console.log("Files:", files);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// 清理资源
|
|
155
|
-
await smbManager.cleanup();
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## 类型定义
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
export interface SmbClientStatus {
|
|
162
|
-
exists: boolean;
|
|
163
|
-
isConnected: boolean;
|
|
164
|
-
currentShare: string | null;
|
|
165
|
-
isDisposed: boolean;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export interface SmbClientInfo {
|
|
169
|
-
isConnected: boolean;
|
|
170
|
-
currentShare: string | null;
|
|
171
|
-
isDisposed: boolean;
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
这些静态方法使得SmbClient的多实例管理变得更加简单和安全。
|
package/SMB_COMPLETE_GUIDE.md
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
# SMB Client Implementation
|
|
2
|
-
|
|
3
|
-
This document provides comprehensive documentation for the SMB client functionality in react-native-kookit.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The SMB client provides object-oriented access to SMB/CIFS file shares, supporting both Android and iOS platforms with a unified API.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
- **Object-oriented design**: Create multiple SMB client instances
|
|
12
|
-
- **Cross-platform**: Works on both Android and iOS
|
|
13
|
-
- **Progress tracking**: Real-time upload/download progress events
|
|
14
|
-
- **Full file operations**: List, download, upload, delete, create directories
|
|
15
|
-
- **Authentication**: Supports username/password and domain authentication
|
|
16
|
-
- **Share management**: Connect to different shares on the same server
|
|
17
|
-
|
|
18
|
-
## Platform Support
|
|
19
|
-
|
|
20
|
-
### Android
|
|
21
|
-
|
|
22
|
-
- Uses SMBJ library (version 0.13.0)
|
|
23
|
-
- Supports SMB2/3 protocols
|
|
24
|
-
- Full authentication and file operations
|
|
25
|
-
|
|
26
|
-
### iOS
|
|
27
|
-
|
|
28
|
-
- Uses SMBClient library (version 0.3.1)
|
|
29
|
-
- Supports SMB2 protocol
|
|
30
|
-
- Async/await Swift implementation
|
|
31
|
-
|
|
32
|
-
## API Reference
|
|
33
|
-
|
|
34
|
-
### Creating an SMB Client
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
import { SmbClient } from "react-native-kookit";
|
|
38
|
-
|
|
39
|
-
// Create and initialize a new SMB client
|
|
40
|
-
const client = await SmbClient.create();
|
|
41
|
-
|
|
42
|
-
// Or create with custom client ID
|
|
43
|
-
const client = await SmbClient.create("my-smb-client");
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Connection Configuration
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
interface SmbConnectionConfig {
|
|
50
|
-
host: string; // SMB server IP or hostname
|
|
51
|
-
port?: number; // Port (default: 445)
|
|
52
|
-
username: string; // Username for authentication
|
|
53
|
-
password: string; // Password for authentication
|
|
54
|
-
domain?: string; // Domain name (optional)
|
|
55
|
-
share?: string; // Share name to connect to (optional)
|
|
56
|
-
timeout?: number; // Connection timeout in milliseconds (default: 10000)
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Event Handlers
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
client.setEventHandlers({
|
|
64
|
-
onProgress: (progress: {
|
|
65
|
-
transferred: number;
|
|
66
|
-
total: number;
|
|
67
|
-
percentage: number;
|
|
68
|
-
}) => {
|
|
69
|
-
console.log(`Progress: ${progress.percentage}%`);
|
|
70
|
-
},
|
|
71
|
-
onComplete: () => {
|
|
72
|
-
console.log("Operation completed");
|
|
73
|
-
},
|
|
74
|
-
onError: (error: Error) => {
|
|
75
|
-
console.error("SMB error:", error.message);
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Connection Methods
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
// Connect to SMB server
|
|
84
|
-
await client.connect({
|
|
85
|
-
host: "192.168.1.100",
|
|
86
|
-
username: "admin",
|
|
87
|
-
password: "password",
|
|
88
|
-
domain: "WORKGROUP",
|
|
89
|
-
share: "shared",
|
|
90
|
-
timeout: 15000,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Connect to a different share on the same server
|
|
94
|
-
await client.connectShare("documents");
|
|
95
|
-
|
|
96
|
-
// Disconnect from server
|
|
97
|
-
await client.disconnect();
|
|
98
|
-
|
|
99
|
-
// Dispose of the client (cleanup resources)
|
|
100
|
-
await client.dispose();
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### File Operations
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
// List files and directories
|
|
107
|
-
const files = await client.list("/path/to/directory");
|
|
108
|
-
console.log(files); // Array of SmbFileInfo objects
|
|
109
|
-
|
|
110
|
-
// Download a file
|
|
111
|
-
await client.download("/remote/file.txt", "/local/path/file.txt");
|
|
112
|
-
|
|
113
|
-
// Upload a file
|
|
114
|
-
await client.upload("/local/path/file.txt", "/remote/file.txt");
|
|
115
|
-
|
|
116
|
-
// Delete a file
|
|
117
|
-
await client.delete("/remote/file.txt");
|
|
118
|
-
|
|
119
|
-
// Delete a directory
|
|
120
|
-
await client.delete("/remote/directory", true);
|
|
121
|
-
|
|
122
|
-
// Create a directory
|
|
123
|
-
await client.createDirectory("/remote/new_directory");
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### File Information Structure
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
interface SmbFileInfo {
|
|
130
|
-
name: string; // File/directory name
|
|
131
|
-
isDirectory: boolean; // Whether it's a directory
|
|
132
|
-
size: number; // File size in bytes
|
|
133
|
-
lastModified: string; // Last modification date
|
|
134
|
-
attributes?: string; // File attributes (platform-specific)
|
|
135
|
-
}
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Client Management
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
// Get client status
|
|
142
|
-
const status = await SmbClient.getClientStatus("client-id");
|
|
143
|
-
console.log(status); // { exists: boolean, connected: boolean }
|
|
144
|
-
|
|
145
|
-
// List all clients
|
|
146
|
-
const clients = await SmbClient.listClients();
|
|
147
|
-
console.log(clients); // { clients: Record<string, { connected: boolean }>, count: number }
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
## Usage Examples
|
|
151
|
-
|
|
152
|
-
### Basic Connection and File Listing
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
import { SmbClient } from "react-native-kookit";
|
|
156
|
-
|
|
157
|
-
async function basicExample() {
|
|
158
|
-
const client = await SmbClient.create();
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
await client.connect({
|
|
162
|
-
host: "192.168.1.100",
|
|
163
|
-
username: "admin",
|
|
164
|
-
password: "password",
|
|
165
|
-
share: "shared",
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const files = await client.list();
|
|
169
|
-
files.forEach((file) => {
|
|
170
|
-
console.log(
|
|
171
|
-
`${file.isDirectory ? "📁" : "📄"} ${file.name} (${file.size} bytes)`
|
|
172
|
-
);
|
|
173
|
-
});
|
|
174
|
-
} catch (error) {
|
|
175
|
-
console.error("Error:", error.message);
|
|
176
|
-
} finally {
|
|
177
|
-
await client.dispose();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### File Upload with Progress
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
async function uploadWithProgress() {
|
|
186
|
-
const client = await SmbClient.create();
|
|
187
|
-
|
|
188
|
-
client.setEventHandlers({
|
|
189
|
-
onProgress: (progress) => {
|
|
190
|
-
console.log(`Upload progress: ${progress.percentage}%`);
|
|
191
|
-
},
|
|
192
|
-
onComplete: () => {
|
|
193
|
-
console.log("Upload completed!");
|
|
194
|
-
},
|
|
195
|
-
onError: (error) => {
|
|
196
|
-
console.error("Upload failed:", error.message);
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
await client.connect({
|
|
202
|
-
host: "192.168.1.100",
|
|
203
|
-
username: "admin",
|
|
204
|
-
password: "password",
|
|
205
|
-
share: "uploads",
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
await client.upload("/local/document.pdf", "/remote/backup/document.pdf");
|
|
209
|
-
} finally {
|
|
210
|
-
await client.dispose();
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Multiple Share Access
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
async function multiShareExample() {
|
|
219
|
-
const client = await SmbClient.create();
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
// Connect to server
|
|
223
|
-
await client.connect({
|
|
224
|
-
host: "192.168.1.100",
|
|
225
|
-
username: "admin",
|
|
226
|
-
password: "password",
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
// Connect to documents share
|
|
230
|
-
await client.connectShare("documents");
|
|
231
|
-
const docFiles = await client.list();
|
|
232
|
-
console.log("Documents:", docFiles.length, "files");
|
|
233
|
-
|
|
234
|
-
// Switch to media share
|
|
235
|
-
await client.connectShare("media");
|
|
236
|
-
const mediaFiles = await client.list();
|
|
237
|
-
console.log("Media:", mediaFiles.length, "files");
|
|
238
|
-
} finally {
|
|
239
|
-
await client.dispose();
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
## Error Handling
|
|
245
|
-
|
|
246
|
-
The SMB client throws specific errors for different scenarios:
|
|
247
|
-
|
|
248
|
-
```typescript
|
|
249
|
-
try {
|
|
250
|
-
await client.connect(config);
|
|
251
|
-
} catch (error) {
|
|
252
|
-
if (error.message.includes("SMB_CONNECT_ERROR")) {
|
|
253
|
-
// Handle connection errors
|
|
254
|
-
} else if (error.message.includes("SMB_AUTH_ERROR")) {
|
|
255
|
-
// Handle authentication errors
|
|
256
|
-
} else {
|
|
257
|
-
// Handle other errors
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
## Common Error Codes
|
|
263
|
-
|
|
264
|
-
- `SMB_CLIENT_EXISTS`: Client with the same ID already exists
|
|
265
|
-
- `SMB_CLIENT_NOT_FOUND`: Client ID not found
|
|
266
|
-
- `SMB_CONNECT_ERROR`: Connection failed
|
|
267
|
-
- `SMB_LIST_ERROR`: Failed to list directory
|
|
268
|
-
- `SMB_DOWNLOAD_ERROR`: Download operation failed
|
|
269
|
-
- `SMB_UPLOAD_ERROR`: Upload operation failed
|
|
270
|
-
- `SMB_DELETE_ERROR`: Delete operation failed
|
|
271
|
-
- `SMB_CREATE_DIR_ERROR`: Directory creation failed
|
|
272
|
-
|
|
273
|
-
## Best Practices
|
|
274
|
-
|
|
275
|
-
1. **Always dispose clients**: Use `try/finally` blocks to ensure proper cleanup
|
|
276
|
-
2. **Handle connection timeouts**: Set appropriate timeout values based on network conditions
|
|
277
|
-
3. **Use progress events**: Provide user feedback for long-running operations
|
|
278
|
-
4. **Error handling**: Implement comprehensive error handling for network operations
|
|
279
|
-
5. **Connection pooling**: Reuse client instances when possible to reduce overhead
|
|
280
|
-
|
|
281
|
-
## Troubleshooting
|
|
282
|
-
|
|
283
|
-
### Connection Issues
|
|
284
|
-
|
|
285
|
-
- Verify SMB server is accessible and SMB service is running
|
|
286
|
-
- Check firewall settings (default port 445)
|
|
287
|
-
- Ensure correct username/password credentials
|
|
288
|
-
- Try connecting without specifying a share first
|
|
289
|
-
|
|
290
|
-
### Authentication Problems
|
|
291
|
-
|
|
292
|
-
- Verify domain name is correct (or omit if not using domain)
|
|
293
|
-
- Check user permissions on the target share
|
|
294
|
-
- Some servers require specific SMB protocol versions
|
|
295
|
-
|
|
296
|
-
### File Operation Errors
|
|
297
|
-
|
|
298
|
-
- Ensure the share is properly connected before file operations
|
|
299
|
-
- Check file/directory permissions
|
|
300
|
-
- Verify paths use forward slashes (/) as separators
|
|
301
|
-
- Some special characters in filenames may cause issues
|
|
302
|
-
|
|
303
|
-
## Performance Considerations
|
|
304
|
-
|
|
305
|
-
- File operations are async and don't block the UI thread
|
|
306
|
-
- Large file transfers will trigger progress events for better UX
|
|
307
|
-
- Multiple concurrent operations on the same client are queued
|
|
308
|
-
- Consider using separate clients for parallel operations on different shares
|