Skip to content

Commit

Permalink
Protect list command constants in a better way
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickjuchli committed Dec 23, 2023
1 parent b0405ff commit 6db253f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ export interface UploadOptions {
localEndInclusive?: number
}

const LIST_COMMANDS_DEFAULT: readonly string[] = ["LIST -a", "LIST"]
const LIST_COMMANDS_MLSD: readonly string[] = ["MLSD", "LIST -a", "LIST"]
const LIST_COMMANDS_DEFAULT = () => ["LIST -a", "LIST"]
const LIST_COMMANDS_MLSD = () => ["MLSD", "LIST -a", "LIST"]

/**
* High-level API to interact with an FTP server.
*/
export class Client {
prepareTransfer: TransferStrategy
parseList: RawListParser
availableListCommands = LIST_COMMANDS_DEFAULT.slice()
availableListCommands = LIST_COMMANDS_DEFAULT()
/** Low-level API to interact with FTP server. */
readonly ftp: FTPContext
/** Tracks progress of data transfers. */
Expand Down Expand Up @@ -234,7 +234,7 @@ export class Client {
// Use MLSD directory listing if possible. See https://tools.ietf.org/html/rfc3659#section-7.8:
// "The presence of the MLST feature indicates that both MLST and MLSD are supported."
const supportsMLSD = features.has("MLST")
this.availableListCommands = supportsMLSD ? LIST_COMMANDS_MLSD.slice() : LIST_COMMANDS_DEFAULT.slice()
this.availableListCommands = supportsMLSD ? LIST_COMMANDS_MLSD() : LIST_COMMANDS_DEFAULT()
await this.send("TYPE I") // Binary mode
await this.sendIgnoringError("STRU F") // Use file structure
await this.sendIgnoringError("OPTS UTF8 ON") // Some servers expect UTF-8 to be enabled explicitly and setting before login might not have worked.
Expand Down

0 comments on commit 6db253f

Please sign in to comment.