1- import { createReadStream , createWriteStream , mkdir , readdir , stat , open , close , unlink } from "fs"
1+ import { close , createReadStream , createWriteStream , mkdir , open , readdir , stat , unlink } from "fs"
22import { basename , join } from "path"
33import { Readable , Writable } from "stream"
44import { connect as connectTLS , ConnectionOptions as TLSConnectionOptions } from "tls"
55import { promisify } from "util"
66import { FileInfo } from "./FileInfo"
77import { FTPContext , FTPError , FTPResponse } from "./FtpContext"
8+ import { describeAddress , describeTLS , upgradeSocket } from "./netUtils"
9+ import { isMultiline , positiveCompletion } from "./parseControlResponse"
810import { parseList as parseListAutoDetect } from "./parseList"
11+ import { parseMLSxDate } from "./parseListMLSD"
912import { ProgressHandler , ProgressTracker } from "./ProgressTracker"
1013import { StringWriter } from "./StringWriter"
11- import { parseMLSxDate } from "./parseListMLSD"
12- import { describeAddress , describeTLS , upgradeSocket } from "./netUtils"
13- import { uploadFrom , downloadTo , enterPassiveModeIPv6 , enterPassiveModeIPv4 , UploadCommand , enterPassiveModeIPv4_forceControlHostIP } from "./transfer"
14- import { isMultiline , positiveCompletion } from "./parseControlResponse"
14+ import { downloadTo , enterPassiveModeIPv4 , enterPassiveModeIPv4_forceControlHostIP , enterPassiveModeIPv6 , UploadCommand , uploadFrom } from "./transfer"
1515
1616// Use promisify to keep the library compatible with Node 8.
1717const fsReadDir = promisify ( readdir )
@@ -50,11 +50,15 @@ export interface UploadOptions {
5050}
5151
5252export interface ClientOptions {
53+ /** Allow the FTP server to use a different host for transfers. */
5354 allowSeparateTransferHost : boolean
55+ /** The upper bound for directory listings. */
56+ maxListingBytes : number
5457}
5558
5659const defaultClientOptions : ClientOptions = {
57- allowSeparateTransferHost : true
60+ allowSeparateTransferHost : true ,
61+ maxListingBytes : 20 * 1024 * 1024
5862}
5963const LIST_COMMANDS_DEFAULT = ( ) => [ "LIST -a" , "LIST" ]
6064const LIST_COMMANDS_MLSD = ( ) => [ "MLSD" , "LIST -a" , "LIST" ]
@@ -70,18 +74,21 @@ export class Client {
7074 readonly ftp : FTPContext
7175 /** Tracks progress of data transfers. */
7276 protected _progressTracker : ProgressTracker
77+ protected options : ClientOptions
7378
7479 /**
7580 * Instantiate an FTP client.
7681 *
7782 * @param timeout Timeout in milliseconds, use 0 for no timeout. Optional, default is 30 seconds.
7883 */
79- constructor ( timeout = 30000 , options : ClientOptions = defaultClientOptions ) {
84+ constructor ( timeout = 30000 , userOptions : Partial < ClientOptions > = defaultClientOptions ) {
85+ const options : ClientOptions = { ...defaultClientOptions , ...userOptions }
8086 this . ftp = new FTPContext ( timeout )
8187 this . prepareTransfer = this . _enterFirstCompatibleMode ( [
8288 enterPassiveModeIPv6 ,
8389 options . allowSeparateTransferHost ? enterPassiveModeIPv4 : enterPassiveModeIPv4_forceControlHostIP
8490 ] )
91+ this . options = options
8592 this . parseList = parseListAutoDetect
8693 this . _progressTracker = new ProgressTracker ( )
8794 }
@@ -589,7 +596,7 @@ export class Client {
589596 * @protected
590597 */
591598 protected async _requestListWithCommand ( command : string ) : Promise < FileInfo [ ] > {
592- const buffer = new StringWriter ( )
599+ const buffer = new StringWriter ( this . options . maxListingBytes )
593600 await downloadTo ( buffer , {
594601 ftp : this . ftp ,
595602 tracker : this . _progressTracker ,
0 commit comments