@elaraai/east-node-io 0.0.1-beta.0 → 0.0.1-beta.2
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/dist/compression/gzip.d.ts +108 -0
- package/dist/compression/gzip.d.ts.map +1 -0
- package/dist/compression/gzip.js +153 -0
- package/dist/compression/gzip.js.map +1 -0
- package/dist/compression/index.d.ts +308 -0
- package/dist/compression/index.d.ts.map +1 -0
- package/dist/compression/index.js +289 -0
- package/dist/compression/index.js.map +1 -0
- package/dist/compression/tar.d.ts +115 -0
- package/dist/compression/tar.d.ts.map +1 -0
- package/dist/compression/tar.js +254 -0
- package/dist/compression/tar.js.map +1 -0
- package/dist/compression/types.d.ts +124 -0
- package/dist/compression/types.d.ts.map +1 -0
- package/dist/compression/types.js +106 -0
- package/dist/compression/types.js.map +1 -0
- package/dist/compression/zip.d.ts +121 -0
- package/dist/compression/zip.d.ts.map +1 -0
- package/dist/compression/zip.js +200 -0
- package/dist/compression/zip.js.map +1 -0
- package/dist/connection/index.d.ts +78 -0
- package/dist/connection/index.d.ts.map +1 -0
- package/dist/connection/index.js +134 -0
- package/dist/connection/index.js.map +1 -0
- package/dist/format/csv.d.ts +210 -0
- package/dist/format/csv.d.ts.map +1 -0
- package/dist/format/csv.js +729 -0
- package/dist/format/csv.js.map +1 -0
- package/dist/format/index.d.ts +641 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +463 -0
- package/dist/format/index.js.map +1 -0
- package/dist/format/types.d.ts +176 -0
- package/dist/format/types.d.ts.map +1 -0
- package/dist/format/types.js +122 -0
- package/dist/format/types.js.map +1 -0
- package/dist/format/xlsx.d.ts +178 -0
- package/dist/format/xlsx.d.ts.map +1 -0
- package/dist/format/xlsx.js +313 -0
- package/dist/format/xlsx.js.map +1 -0
- package/dist/format/xml.d.ts +302 -0
- package/dist/format/xml.d.ts.map +1 -0
- package/dist/format/xml.js +602 -0
- package/dist/format/xml.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/nosql/index.d.ts +503 -0
- package/dist/nosql/index.d.ts.map +1 -0
- package/dist/nosql/index.js +483 -0
- package/dist/nosql/index.js.map +1 -0
- package/dist/nosql/mongodb.d.ts +306 -0
- package/dist/nosql/mongodb.d.ts.map +1 -0
- package/dist/nosql/mongodb.js +552 -0
- package/dist/nosql/mongodb.js.map +1 -0
- package/dist/nosql/redis.d.ts +268 -0
- package/dist/nosql/redis.d.ts.map +1 -0
- package/dist/nosql/redis.js +371 -0
- package/dist/nosql/redis.js.map +1 -0
- package/dist/nosql/types.d.ts +70 -0
- package/dist/nosql/types.d.ts.map +1 -0
- package/dist/nosql/types.js +79 -0
- package/dist/nosql/types.js.map +1 -0
- package/dist/sql/index.d.ts +777 -0
- package/dist/sql/index.d.ts.map +1 -0
- package/dist/sql/index.js +515 -0
- package/dist/sql/index.js.map +1 -0
- package/dist/sql/mysql.d.ts +238 -0
- package/dist/sql/mysql.d.ts.map +1 -0
- package/dist/sql/mysql.js +396 -0
- package/dist/sql/mysql.js.map +1 -0
- package/dist/sql/postgres.d.ts +237 -0
- package/dist/sql/postgres.d.ts.map +1 -0
- package/dist/sql/postgres.js +381 -0
- package/dist/sql/postgres.js.map +1 -0
- package/dist/sql/sqlite.d.ts +217 -0
- package/dist/sql/sqlite.d.ts.map +1 -0
- package/dist/sql/sqlite.js +366 -0
- package/dist/sql/sqlite.js.map +1 -0
- package/dist/sql/types.d.ts +205 -0
- package/dist/sql/types.d.ts.map +1 -0
- package/dist/sql/types.js +175 -0
- package/dist/sql/types.js.map +1 -0
- package/dist/storage/index.d.ts +304 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +234 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/s3.d.ts +373 -0
- package/dist/storage/s3.d.ts.map +1 -0
- package/dist/storage/s3.js +502 -0
- package/dist/storage/s3.js.map +1 -0
- package/dist/storage/types.d.ts +117 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +94 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/transfer/ftp.d.ts +333 -0
- package/dist/transfer/ftp.d.ts.map +1 -0
- package/dist/transfer/ftp.js +437 -0
- package/dist/transfer/ftp.js.map +1 -0
- package/dist/transfer/index.d.ts +456 -0
- package/dist/transfer/index.d.ts.map +1 -0
- package/dist/transfer/index.js +414 -0
- package/dist/transfer/index.js.map +1 -0
- package/dist/transfer/sftp.d.ts +333 -0
- package/dist/transfer/sftp.d.ts.map +1 -0
- package/dist/transfer/sftp.js +436 -0
- package/dist/transfer/sftp.js.map +1 -0
- package/dist/transfer/types.d.ts +108 -0
- package/dist/transfer/types.d.ts.map +1 -0
- package/dist/transfer/types.js +110 -0
- package/dist/transfer/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +8 -8
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* FTP platform functions for East Node IO.
|
|
7
|
+
*
|
|
8
|
+
* Provides FTP and FTPS file transfer operations for East programs,
|
|
9
|
+
* including upload, download, list, and delete operations.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
import { East, BlobType, ArrayType, NullType } from "@elaraai/east";
|
|
14
|
+
import { EastError } from "@elaraai/east/internal";
|
|
15
|
+
import { Client as FtpClient } from "basic-ftp";
|
|
16
|
+
import { Readable } from "node:stream";
|
|
17
|
+
import { createHandle, getConnection, closeHandle, closeAllHandles } from '../connection/index.js';
|
|
18
|
+
import { FtpConfigType, ConnectionHandleType, StringType, FileInfoType } from "./types.js";
|
|
19
|
+
/**
|
|
20
|
+
* Connects to an FTP server.
|
|
21
|
+
*
|
|
22
|
+
* Creates a connection to an FTP or FTPS server and returns an opaque handle
|
|
23
|
+
* for use in file transfer operations.
|
|
24
|
+
*
|
|
25
|
+
* This is a platform function for the East language, enabling FTP file transfer
|
|
26
|
+
* operations in East programs running on Node.js.
|
|
27
|
+
*
|
|
28
|
+
* @param config - FTP connection configuration
|
|
29
|
+
* @returns Connection handle (opaque string)
|
|
30
|
+
*
|
|
31
|
+
* @throws {EastError} When connection fails due to:
|
|
32
|
+
* - Invalid hostname or port (location: "ftp_connect")
|
|
33
|
+
* - Authentication failure (location: "ftp_connect")
|
|
34
|
+
* - Network errors (location: "ftp_connect")
|
|
35
|
+
* - SSL/TLS errors for FTPS (location: "ftp_connect")
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { East, StringType, BlobType } from "@elaraai/east";
|
|
40
|
+
* import { Transfer } from "@elaraai/east-node-io";
|
|
41
|
+
*
|
|
42
|
+
* const uploadToFtp = East.function([StringType, BlobType], NullType, ($, filename, data) => {
|
|
43
|
+
* const config = $.let({
|
|
44
|
+
* host: "ftp.example.com",
|
|
45
|
+
* port: 21n,
|
|
46
|
+
* user: "username",
|
|
47
|
+
* password: "password",
|
|
48
|
+
* secure: false,
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const conn = $.let(Transfer.FTP.connect(config));
|
|
52
|
+
* $(Transfer.FTP.put(conn, filename, data));
|
|
53
|
+
* $(Transfer.FTP.close(conn));
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* const compiled = East.compileAsync(uploadToFtp.toIR(), Transfer.FTP.Implementation);
|
|
57
|
+
* await compiled("file.txt", fileData);
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* - Supports both FTP and FTPS (FTP over SSL/TLS)
|
|
62
|
+
* - Connection is maintained until explicitly closed
|
|
63
|
+
* - All operations are asynchronous (use East.compileAsync)
|
|
64
|
+
*/
|
|
65
|
+
export const ftp_connect = East.asyncPlatform("ftp_connect", [FtpConfigType], ConnectionHandleType);
|
|
66
|
+
/**
|
|
67
|
+
* Uploads a file to an FTP server.
|
|
68
|
+
*
|
|
69
|
+
* Uploads binary data to the FTP server at the specified remote path.
|
|
70
|
+
* Overwrites existing files with the same path.
|
|
71
|
+
*
|
|
72
|
+
* This is a platform function for the East language, enabling FTP file transfer
|
|
73
|
+
* operations in East programs running on Node.js.
|
|
74
|
+
*
|
|
75
|
+
* @param handle - Connection handle from ftp_connect()
|
|
76
|
+
* @param remotePath - Remote file path on the FTP server
|
|
77
|
+
* @param data - Binary data to upload
|
|
78
|
+
* @returns Null on success
|
|
79
|
+
*
|
|
80
|
+
* @throws {EastError} When upload fails due to:
|
|
81
|
+
* - Invalid connection handle (location: "ftp_put")
|
|
82
|
+
* - Permission denied (location: "ftp_put")
|
|
83
|
+
* - Invalid remote path (location: "ftp_put")
|
|
84
|
+
* - Network errors (location: "ftp_put")
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { East, StringType, BlobType, NullType } from "@elaraai/east";
|
|
89
|
+
* import { Transfer } from "@elaraai/east-node-io";
|
|
90
|
+
*
|
|
91
|
+
* const uploadFile = East.function([StringType, BlobType], NullType, ($, filename, data) => {
|
|
92
|
+
* const config = $.let({
|
|
93
|
+
* host: "ftp.example.com",
|
|
94
|
+
* port: 21n,
|
|
95
|
+
* user: "username",
|
|
96
|
+
* password: "password",
|
|
97
|
+
* secure: false,
|
|
98
|
+
* });
|
|
99
|
+
* const conn = $.let(Transfer.FTP.connect(config));
|
|
100
|
+
* $(Transfer.FTP.put(conn, `/uploads/${filename}`, data));
|
|
101
|
+
* $(Transfer.FTP.close(conn));
|
|
102
|
+
* return $.return(null);
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* const compiled = East.compileAsync(uploadFile.toIR(), Transfer.FTP.Implementation);
|
|
106
|
+
* await compiled("file.txt", fileData);
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* - Creates parent directories if they don't exist
|
|
111
|
+
* - Overwrites existing files
|
|
112
|
+
* - Binary mode transfer
|
|
113
|
+
*/
|
|
114
|
+
export const ftp_put = East.asyncPlatform("ftp_put", [ConnectionHandleType, StringType, BlobType], NullType);
|
|
115
|
+
/**
|
|
116
|
+
* Downloads a file from an FTP server.
|
|
117
|
+
*
|
|
118
|
+
* Retrieves binary data from the FTP server at the specified remote path.
|
|
119
|
+
* Returns the file data as a Blob (Uint8Array).
|
|
120
|
+
*
|
|
121
|
+
* This is a platform function for the East language, enabling FTP file transfer
|
|
122
|
+
* operations in East programs running on Node.js.
|
|
123
|
+
*
|
|
124
|
+
* @param handle - Connection handle from ftp_connect()
|
|
125
|
+
* @param remotePath - Remote file path on the FTP server
|
|
126
|
+
* @returns Binary data as Blob
|
|
127
|
+
*
|
|
128
|
+
* @throws {EastError} When download fails due to:
|
|
129
|
+
* - Invalid connection handle (location: "ftp_get")
|
|
130
|
+
* - File not found (location: "ftp_get")
|
|
131
|
+
* - Permission denied (location: "ftp_get")
|
|
132
|
+
* - Network errors (location: "ftp_get")
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { East, StringType, BlobType } from "@elaraai/east";
|
|
137
|
+
* import { Transfer } from "@elaraai/east-node-io";
|
|
138
|
+
*
|
|
139
|
+
* const downloadFile = East.function([StringType], BlobType, ($, filename) => {
|
|
140
|
+
* const config = $.let({
|
|
141
|
+
* host: "ftp.example.com",
|
|
142
|
+
* port: 21n,
|
|
143
|
+
* user: "username",
|
|
144
|
+
* password: "password",
|
|
145
|
+
* secure: false,
|
|
146
|
+
* });
|
|
147
|
+
* const conn = $.let(Transfer.FTP.connect(config));
|
|
148
|
+
* const data = $.let(Transfer.FTP.get(conn, `/downloads/${filename}`));
|
|
149
|
+
* $(Transfer.FTP.close(conn));
|
|
150
|
+
* return $.return(data);
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* const compiled = East.compileAsync(downloadFile.toIR(), Transfer.FTP.Implementation);
|
|
154
|
+
* const fileData = await compiled("file.txt"); // Returns Uint8Array
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @remarks
|
|
158
|
+
* - Binary mode transfer
|
|
159
|
+
* - Entire file is loaded into memory
|
|
160
|
+
*/
|
|
161
|
+
export const ftp_get = East.asyncPlatform("ftp_get", [ConnectionHandleType, StringType], BlobType);
|
|
162
|
+
/**
|
|
163
|
+
* Lists files in an FTP directory.
|
|
164
|
+
*
|
|
165
|
+
* Retrieves a list of files and directories at the specified remote path.
|
|
166
|
+
* Returns metadata for each file including name, size, and modification time.
|
|
167
|
+
*
|
|
168
|
+
* This is a platform function for the East language, enabling FTP file transfer
|
|
169
|
+
* operations in East programs running on Node.js.
|
|
170
|
+
*
|
|
171
|
+
* @param handle - Connection handle from ftp_connect()
|
|
172
|
+
* @param remotePath - Remote directory path on the FTP server
|
|
173
|
+
* @returns Array of file information metadata
|
|
174
|
+
*
|
|
175
|
+
* @throws {EastError} When listing fails due to:
|
|
176
|
+
* - Invalid connection handle (location: "ftp_list")
|
|
177
|
+
* - Directory not found (location: "ftp_list")
|
|
178
|
+
* - Permission denied (location: "ftp_list")
|
|
179
|
+
* - Network errors (location: "ftp_list")
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* import { East, StringType, ArrayType } from "@elaraai/east";
|
|
184
|
+
* import { Transfer } from "@elaraai/east-node-io";
|
|
185
|
+
*
|
|
186
|
+
* const listFiles = East.function([StringType], ArrayType(Transfer.FTP.Types.FileInfo), ($, remotePath) => {
|
|
187
|
+
* const config = $.let({
|
|
188
|
+
* host: "ftp.example.com",
|
|
189
|
+
* port: 21n,
|
|
190
|
+
* user: "username",
|
|
191
|
+
* password: "password",
|
|
192
|
+
* secure: false,
|
|
193
|
+
* });
|
|
194
|
+
* const conn = $.let(Transfer.FTP.connect(config));
|
|
195
|
+
* const files = $.let(Transfer.FTP.list(conn, remotePath));
|
|
196
|
+
* $(Transfer.FTP.close(conn));
|
|
197
|
+
* return $.return(files);
|
|
198
|
+
* });
|
|
199
|
+
*
|
|
200
|
+
* const compiled = East.compileAsync(listFiles.toIR(), Transfer.FTP.Implementation);
|
|
201
|
+
* const uploads = await compiled("/uploads"); // [{name: "file.txt", size: 1024n, ...}, ...]
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @remarks
|
|
205
|
+
* - Returns both files and directories
|
|
206
|
+
* - Use isDirectory field to distinguish between files and directories
|
|
207
|
+
*/
|
|
208
|
+
export const ftp_list = East.asyncPlatform("ftp_list", [ConnectionHandleType, StringType], ArrayType(FileInfoType));
|
|
209
|
+
/**
|
|
210
|
+
* Deletes a file from an FTP server.
|
|
211
|
+
*
|
|
212
|
+
* Removes a file from the FTP server at the specified remote path.
|
|
213
|
+
* Does not delete directories.
|
|
214
|
+
*
|
|
215
|
+
* This is a platform function for the East language, enabling FTP file transfer
|
|
216
|
+
* operations in East programs running on Node.js.
|
|
217
|
+
*
|
|
218
|
+
* @param handle - Connection handle from ftp_connect()
|
|
219
|
+
* @param remotePath - Remote file path to delete
|
|
220
|
+
* @returns Null on success
|
|
221
|
+
*
|
|
222
|
+
* @throws {EastError} When deletion fails due to:
|
|
223
|
+
* - Invalid connection handle (location: "ftp_delete")
|
|
224
|
+
* - File not found (location: "ftp_delete")
|
|
225
|
+
* - Permission denied (location: "ftp_delete")
|
|
226
|
+
* - Network errors (location: "ftp_delete")
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* import { East, StringType, NullType } from "@elaraai/east";
|
|
231
|
+
* import { Transfer } from "@elaraai/east-node-io";
|
|
232
|
+
*
|
|
233
|
+
* const deleteFile = East.function([StringType], NullType, ($, filename) => {
|
|
234
|
+
* const config = $.let({
|
|
235
|
+
* host: "ftp.example.com",
|
|
236
|
+
* port: 21n,
|
|
237
|
+
* user: "username",
|
|
238
|
+
* password: "password",
|
|
239
|
+
* secure: false,
|
|
240
|
+
* });
|
|
241
|
+
* const conn = $.let(Transfer.FTP.connect(config));
|
|
242
|
+
* $(Transfer.FTP.delete(conn, `/uploads/${filename}`));
|
|
243
|
+
* $(Transfer.FTP.close(conn));
|
|
244
|
+
* return $.return(null);
|
|
245
|
+
* });
|
|
246
|
+
*
|
|
247
|
+
* const compiled = East.compileAsync(deleteFile.toIR(), Transfer.FTP.Implementation);
|
|
248
|
+
* await compiled("old-file.txt");
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
251
|
+
* @remarks
|
|
252
|
+
* - Only deletes files, not directories
|
|
253
|
+
* - Throws error if file doesn't exist
|
|
254
|
+
*/
|
|
255
|
+
export const ftp_delete = East.asyncPlatform("ftp_delete", [ConnectionHandleType, StringType], NullType);
|
|
256
|
+
/**
|
|
257
|
+
* Closes an FTP connection.
|
|
258
|
+
*
|
|
259
|
+
* Closes the FTP connection and releases all resources.
|
|
260
|
+
* The handle becomes invalid after this operation.
|
|
261
|
+
*
|
|
262
|
+
* @param handle - Connection handle from ftp_connect()
|
|
263
|
+
* @returns Null on success
|
|
264
|
+
*
|
|
265
|
+
* @throws {EastError} When handle is invalid (location: "ftp_close")
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* import { East, NullType } from "@elaraai/east";
|
|
270
|
+
* import { Transfer } from "@elaraai/east-node-io";
|
|
271
|
+
*
|
|
272
|
+
* const cleanup = East.function([], NullType, $ => {
|
|
273
|
+
* const config = $.let({
|
|
274
|
+
* host: "ftp.example.com",
|
|
275
|
+
* port: 21n,
|
|
276
|
+
* user: "username",
|
|
277
|
+
* password: "password",
|
|
278
|
+
* secure: false,
|
|
279
|
+
* });
|
|
280
|
+
* const conn = $.let(Transfer.FTP.connect(config));
|
|
281
|
+
* // ... do work ...
|
|
282
|
+
* $(Transfer.FTP.close(conn));
|
|
283
|
+
* return $.return(null);
|
|
284
|
+
* });
|
|
285
|
+
*
|
|
286
|
+
* const compiled = East.compileAsync(cleanup.toIR(), Transfer.FTP.Implementation);
|
|
287
|
+
* await compiled();
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
export const ftp_close = East.platform("ftp_close", [ConnectionHandleType], NullType);
|
|
291
|
+
/**
|
|
292
|
+
* Closes all FTP connections.
|
|
293
|
+
*
|
|
294
|
+
* Closes all active FTP connections and releases all resources.
|
|
295
|
+
* Useful for test cleanup to ensure all connections are closed.
|
|
296
|
+
*
|
|
297
|
+
* @returns Null on success
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* import { East, NullType } from "@elaraai/east";
|
|
302
|
+
* import { Transfer } from "@elaraai/east-node-io";
|
|
303
|
+
*
|
|
304
|
+
* const cleanupAll = East.function([], NullType, $ => {
|
|
305
|
+
* // ... test code that may have left connections open ...
|
|
306
|
+
* $(Transfer.FTP.closeAll());
|
|
307
|
+
* return $.return(null);
|
|
308
|
+
* });
|
|
309
|
+
*
|
|
310
|
+
* const compiled = East.compileAsync(cleanupAll.toIR(), Transfer.FTP.Implementation);
|
|
311
|
+
* await compiled();
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* @internal
|
|
315
|
+
*/
|
|
316
|
+
export const ftp_close_all = East.asyncPlatform("ftp_close_all", [], NullType);
|
|
317
|
+
/**
|
|
318
|
+
* Node.js implementation of FTP platform functions.
|
|
319
|
+
*
|
|
320
|
+
* Provides the runtime implementations for FTP operations using basic-ftp.
|
|
321
|
+
* Pass this to East.compileAsync() to enable FTP functionality.
|
|
322
|
+
*/
|
|
323
|
+
export const FtpImpl = [
|
|
324
|
+
ftp_connect.implement(async (config) => {
|
|
325
|
+
try {
|
|
326
|
+
const client = new FtpClient();
|
|
327
|
+
client.ftp.verbose = false;
|
|
328
|
+
await client.access({
|
|
329
|
+
host: config.host,
|
|
330
|
+
port: Number(config.port),
|
|
331
|
+
user: config.user,
|
|
332
|
+
password: config.password,
|
|
333
|
+
secure: config.secure ? "implicit" : false,
|
|
334
|
+
});
|
|
335
|
+
return createHandle(client, async () => {
|
|
336
|
+
await Promise.resolve(client.close());
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
throw new EastError(`FTP connection failed: ${err.message}`, {
|
|
341
|
+
location: { filename: "ftp_connect", line: 0n, column: 0n },
|
|
342
|
+
cause: err
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}),
|
|
346
|
+
ftp_put.implement(async (handle, remotePath, data) => {
|
|
347
|
+
try {
|
|
348
|
+
const client = getConnection(handle);
|
|
349
|
+
// Convert Uint8Array to readable stream
|
|
350
|
+
const stream = Readable.from(Buffer.from(data));
|
|
351
|
+
await client.uploadFrom(stream, remotePath);
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
throw new EastError(`FTP upload failed: ${err.message}`, {
|
|
356
|
+
location: { filename: "ftp_put", line: 0n, column: 0n },
|
|
357
|
+
cause: err
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}),
|
|
361
|
+
ftp_get.implement(async (handle, remotePath) => {
|
|
362
|
+
try {
|
|
363
|
+
const client = getConnection(handle);
|
|
364
|
+
// Download to buffer
|
|
365
|
+
const chunks = [];
|
|
366
|
+
const writable = new (await import('stream')).Writable({
|
|
367
|
+
write(chunk, _encoding, callback) {
|
|
368
|
+
chunks.push(chunk);
|
|
369
|
+
callback();
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
await client.downloadTo(writable, remotePath);
|
|
373
|
+
// Concatenate all chunks
|
|
374
|
+
const buffer = Buffer.concat(chunks);
|
|
375
|
+
return new Uint8Array(buffer);
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
throw new EastError(`FTP download failed: ${err.message}`, {
|
|
379
|
+
location: { filename: "ftp_get", line: 0n, column: 0n },
|
|
380
|
+
cause: err
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}),
|
|
384
|
+
ftp_list.implement(async (handle, remotePath) => {
|
|
385
|
+
try {
|
|
386
|
+
const client = getConnection(handle);
|
|
387
|
+
const files = await client.list(remotePath);
|
|
388
|
+
// Convert to East FileInfoType format
|
|
389
|
+
return files.map((file) => ({
|
|
390
|
+
name: file.name,
|
|
391
|
+
path: remotePath + (remotePath.endsWith('/') ? '' : '/') + file.name,
|
|
392
|
+
size: BigInt(file.size),
|
|
393
|
+
isDirectory: file.isDirectory,
|
|
394
|
+
modifiedTime: file.modifiedAt?.toISOString() || new Date().toISOString(),
|
|
395
|
+
}));
|
|
396
|
+
}
|
|
397
|
+
catch (err) {
|
|
398
|
+
throw new EastError(`FTP list failed: ${err.message}`, {
|
|
399
|
+
location: { filename: "ftp_list", line: 0n, column: 0n },
|
|
400
|
+
cause: err
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}),
|
|
404
|
+
ftp_delete.implement(async (handle, remotePath) => {
|
|
405
|
+
try {
|
|
406
|
+
const client = getConnection(handle);
|
|
407
|
+
await client.remove(remotePath);
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
catch (err) {
|
|
411
|
+
throw new EastError(`FTP delete failed: ${err.message}`, {
|
|
412
|
+
location: { filename: "ftp_delete", line: 0n, column: 0n },
|
|
413
|
+
cause: err
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}),
|
|
417
|
+
// note: this one doesn't produce a Promise
|
|
418
|
+
ftp_close.implement((handle) => {
|
|
419
|
+
try {
|
|
420
|
+
const client = getConnection(handle);
|
|
421
|
+
client.close();
|
|
422
|
+
closeHandle(handle);
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
catch (err) {
|
|
426
|
+
throw new EastError(`FTP close failed: ${err.message}`, {
|
|
427
|
+
location: { filename: "ftp_close", line: 0n, column: 0n },
|
|
428
|
+
cause: err
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}),
|
|
432
|
+
ftp_close_all.implement(async () => {
|
|
433
|
+
await closeAllHandles();
|
|
434
|
+
return null;
|
|
435
|
+
}),
|
|
436
|
+
];
|
|
437
|
+
//# sourceMappingURL=ftp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ftp.js","sourceRoot":"","sources":["../../src/transfer/ftp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,SAAS,EAAiB,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC,aAAa,CAAC,EAAE,oBAAoB,CAAC,CAAC;AAEpG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,oBAAoB,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;AAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,MAAM,OA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