molex-ftp-client 1.2.0 → 1.2.1
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.md +9 -0
- package/README.md +61 -25
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.2.1] - 2026-02-02
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Improved README documentation
|
|
7
|
+
- Better examples for `ensureDir()`, `ensureParentDir()`, and `uploadFile()`
|
|
8
|
+
- Added architecture section explaining modular structure
|
|
9
|
+
- Enhanced feature list highlighting directory management capabilities
|
|
10
|
+
- Reorganized API documentation for better clarity
|
|
11
|
+
|
|
3
12
|
## [1.2.0] - 2026-02-02
|
|
4
13
|
|
|
5
14
|
### Changed
|
package/README.md
CHANGED
|
@@ -12,9 +12,11 @@ Lightweight FTP client built with native Node.js TCP sockets (net module).
|
|
|
12
12
|
- ✅ **Configurable timeouts** - Prevent hanging connections
|
|
13
13
|
- ✅ **Event-based** - Listen to FTP responses and events
|
|
14
14
|
- ✅ **Upload/download** files with Buffer support
|
|
15
|
-
- ✅ **
|
|
15
|
+
- ✅ **Smart directory management** - Auto-create nested directories
|
|
16
|
+
- ✅ **Directory operations** (list, cd, mkdir, pwd, ensureDir)
|
|
16
17
|
- ✅ **File operations** (delete, rename, size, exists, modifiedTime)
|
|
17
18
|
- ✅ **Connection statistics** - Track command count and status
|
|
19
|
+
- ✅ **Clean architecture** - Modular structure with separation of concerns
|
|
18
20
|
|
|
19
21
|
## Installation
|
|
20
22
|
|
|
@@ -113,6 +115,27 @@ await client.upload(buffer, '/path/file.bin');
|
|
|
113
115
|
|
|
114
116
|
Returns: `Promise<void>`
|
|
115
117
|
|
|
118
|
+
#### `uploadFile(data, remotePath, ensureDir)`
|
|
119
|
+
|
|
120
|
+
Upload file and optionally ensure parent directory exists. This is the recommended method when uploading to deep paths.
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
// Upload with automatic directory creation (recommended)
|
|
124
|
+
await client.uploadFile('data', '/deep/nested/path/file.txt', true);
|
|
125
|
+
|
|
126
|
+
// Upload without directory creation
|
|
127
|
+
await client.uploadFile('data', '/file.txt', false);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Parameters:**
|
|
131
|
+
- `data` (string|Buffer): File content
|
|
132
|
+
- `remotePath` (string): Remote file path
|
|
133
|
+
- `ensureDir` (boolean): Create parent directories if needed (default: false)
|
|
134
|
+
|
|
135
|
+
**Why use this?** Simplifies uploads to nested paths by automatically creating any missing parent directories.
|
|
136
|
+
|
|
137
|
+
Returns: `Promise<void>`
|
|
138
|
+
|
|
116
139
|
#### `download(remotePath)`
|
|
117
140
|
|
|
118
141
|
Download file from server.
|
|
@@ -177,24 +200,6 @@ console.log(`Last modified: ${date.toISOString()}`);
|
|
|
177
200
|
|
|
178
201
|
Returns: `Promise<Date>`
|
|
179
202
|
|
|
180
|
-
#### `uploadFile(data, remotePath, ensureDir)`
|
|
181
|
-
|
|
182
|
-
Upload file and optionally ensure parent directory exists.
|
|
183
|
-
|
|
184
|
-
```javascript
|
|
185
|
-
// Upload with automatic directory creation
|
|
186
|
-
await client.uploadFile('data', '/deep/nested/path/file.txt', true);
|
|
187
|
-
|
|
188
|
-
// Upload without directory creation (default behavior)
|
|
189
|
-
await client.uploadFile('data', '/file.txt');
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
- `data` (string|Buffer): File content
|
|
193
|
-
- `remotePath` (string): Remote file path
|
|
194
|
-
- `ensureDir` (boolean): Create parent directories if needed (default: false)
|
|
195
|
-
|
|
196
|
-
Returns: `Promise<void>`
|
|
197
|
-
|
|
198
203
|
### Directory Operations
|
|
199
204
|
|
|
200
205
|
#### `list(path)`
|
|
@@ -241,31 +246,42 @@ Returns: `Promise<void>`
|
|
|
241
246
|
|
|
242
247
|
#### `ensureDir(dirPath, recursive)`
|
|
243
248
|
|
|
244
|
-
Ensure directory exists, creating it (and parent directories) if necessary.
|
|
249
|
+
Ensure directory exists, creating it (and parent directories) if necessary. Idempotent - safe to call multiple times.
|
|
245
250
|
|
|
246
251
|
```javascript
|
|
247
|
-
// Create nested directories recursively
|
|
252
|
+
// Create nested directories recursively (default)
|
|
248
253
|
await client.ensureDir('/deep/nested/path');
|
|
249
254
|
|
|
250
|
-
// Create single directory (
|
|
255
|
+
// Create single directory only (will fail if parent doesn't exist)
|
|
251
256
|
await client.ensureDir('/newdir', false);
|
|
257
|
+
|
|
258
|
+
// Idempotent - no error if directory already exists
|
|
259
|
+
await client.ensureDir('/existing/path'); // No error
|
|
252
260
|
```
|
|
253
261
|
|
|
262
|
+
**Parameters:**
|
|
254
263
|
- `dirPath` (string): Directory path to ensure exists
|
|
255
264
|
- `recursive` (boolean): Create parent directories if needed (default: true)
|
|
256
265
|
|
|
266
|
+
**Use case:** Preparing directory structure before multiple file uploads.
|
|
267
|
+
|
|
257
268
|
Returns: `Promise<void>`
|
|
258
269
|
|
|
259
270
|
#### `ensureParentDir(filePath)`
|
|
260
271
|
|
|
261
|
-
Ensure the parent directory exists for a given file path.
|
|
272
|
+
Ensure the parent directory exists for a given file path. Recursively creates all missing parent directories.
|
|
262
273
|
|
|
263
274
|
```javascript
|
|
264
275
|
// Ensures /path/to exists before uploading
|
|
265
276
|
await client.ensureParentDir('/path/to/file.txt');
|
|
266
277
|
await client.upload('data', '/path/to/file.txt');
|
|
278
|
+
|
|
279
|
+
// Tip: Use uploadFile() instead for convenience
|
|
280
|
+
await client.uploadFile('data', '/path/to/file.txt', true); // Equivalent
|
|
267
281
|
```
|
|
268
282
|
|
|
283
|
+
**Use case:** Manual directory management before upload. Consider using `uploadFile()` with `ensureDir=true` for a simpler approach.
|
|
284
|
+
|
|
269
285
|
Returns: `Promise<void>`
|
|
270
286
|
|
|
271
287
|
### Utilities
|
|
@@ -415,9 +431,9 @@ async function backupFile() {
|
|
|
415
431
|
await client.rename('/backup/data.json', '/backup/data.old.json');
|
|
416
432
|
}
|
|
417
433
|
|
|
418
|
-
// Upload new backup
|
|
434
|
+
// Upload new backup (with automatic directory creation)
|
|
419
435
|
const newData = JSON.stringify({ timestamp: Date.now(), data: [1, 2, 3] });
|
|
420
|
-
await client.
|
|
436
|
+
await client.uploadFile(newData, '/backup/data.json', true);
|
|
421
437
|
console.log('Backup uploaded successfully');
|
|
422
438
|
|
|
423
439
|
// Verify
|
|
@@ -439,6 +455,26 @@ async function backupFile() {
|
|
|
439
455
|
backupFile();
|
|
440
456
|
```
|
|
441
457
|
|
|
458
|
+
## Architecture
|
|
459
|
+
|
|
460
|
+
The library is organized with clean separation of concerns:
|
|
461
|
+
|
|
462
|
+
```
|
|
463
|
+
molex-ftp-client/
|
|
464
|
+
├── index.js # Entry point - exports FTPClient
|
|
465
|
+
├── lib/
|
|
466
|
+
│ ├── FTPClient.js # Main class definition & public API
|
|
467
|
+
│ ├── connection.js # Connection & authentication logic
|
|
468
|
+
│ ├── commands.js # FTP command implementations
|
|
469
|
+
│ └── utils.js # Helper functions (parsing, paths)
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
**Benefits:**
|
|
473
|
+
- 📁 **Modular structure** - Easy to maintain and extend
|
|
474
|
+
- 🔍 **Clear responsibilities** - Each file has a single purpose
|
|
475
|
+
- 🧪 **Testable** - Isolated components for unit testing
|
|
476
|
+
- 📖 **Readable** - Simple entry point with organized implementation
|
|
477
|
+
|
|
442
478
|
## License
|
|
443
479
|
|
|
444
480
|
ISC © Tony Wiedman / MolexWorks
|