///
///
import { Readable, Writable } from "stream";
import { ConnectionOptions as TLSConnectionOptions } from "tls";
import { FileInfo } from "./FileInfo";
import { FTPContext, FTPResponse } from "./FtpContext";
import { ProgressHandler, ProgressTracker } from "./ProgressTracker";
import { UploadCommand } from "./transfer";
export interface AccessOptions {
/** Host the client should connect to. Optional, default is "localhost". */
readonly host?: string;
/** Port the client should connect to. Optional, default is 21. */
readonly port?: number;
/** Username to use for login. Optional, default is "anonymous". */
readonly user?: string;
/** Password to use for login. Optional, default is "guest". */
readonly password?: string;
/** Use FTPS over TLS. Optional, default is false. True is preferred explicit TLS, "implicit" supports legacy, non-standardized implicit TLS. */
readonly secure?: boolean | "implicit";
/** TLS options as in [tls.connect(options)](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback), optional. */
readonly secureOptions?: TLSConnectionOptions;
}
/** Prepares a data connection for transfer. */
export type TransferStrategy = (ftp: FTPContext) => Promise;
/** Parses raw directoy listing data. */
export type RawListParser = (rawList: string) => FileInfo[];
export interface UploadOptions {
/** Offset in the local file to start uploading from. */
localStart?: number;
/** Final byte position to include in upload from the local file. */
localEndInclusive?: number;
}
/**
* High-level API to interact with an FTP server.
*/
export declare class Client {
prepareTransfer: TransferStrategy;
parseList: RawListParser;
availableListCommands: string[];
/** Low-level API to interact with FTP server. */
readonly ftp: FTPContext;
/** Tracks progress of data transfers. */
protected _progressTracker: ProgressTracker;
/**
* Instantiate an FTP client.
*
* @param timeout Timeout in milliseconds, use 0 for no timeout. Optional, default is 30 seconds.
*/
constructor(timeout?: number);
/**
* Close the client and all open socket connections.
*
* Close the client and all open socket connections. The client can’t be used anymore after calling this method,
* you have to either reconnect with `access` or `connect` or instantiate a new instance to continue any work.
* A client is also closed automatically if any timeout or connection error occurs.
*/
close(): void;
/**
* Returns true if the client is closed and can't be used anymore.
*/
get closed(): boolean;
/**
* Connect (or reconnect) to an FTP server.
*
* This is an instance method and thus can be called multiple times during the lifecycle of a `Client`
* instance. Whenever you do, the client is reset with a new control connection. This also implies that
* you can reopen a `Client` instance that has been closed due to an error when reconnecting with this
* method. In fact, reconnecting is the only way to continue using a closed `Client`.
*
* @param host Host the client should connect to. Optional, default is "localhost".
* @param port Port the client should connect to. Optional, default is 21.
*/
connect(host?: string, port?: number): Promise;
/**
* As `connect` but using implicit TLS. Implicit TLS is not an FTP standard and has been replaced by
* explicit TLS. There are still FTP servers that support only implicit TLS, though.
*/
connectImplicitTLS(host?: string, port?: number, tlsOptions?: TLSConnectionOptions): Promise;
/**
* Handles the first reponse by an FTP server after the socket connection has been established.
*/
private _handleConnectResponse;
/**
* Send an FTP command and handle the first response.
*/
send(command: string, ignoreErrorCodesDEPRECATED?: boolean): Promise;
/**
* Send an FTP command and ignore an FTP error response. Any other kind of error or timeout will still reject the Promise.
*
* @param command
*/
sendIgnoringError(command: string): Promise;
/**
* Upgrade the current socket connection to TLS.
*
* @param options TLS options as in `tls.connect(options)`, optional.
* @param command Set the authentication command. Optional, default is "AUTH TLS".
*/
useTLS(options?: TLSConnectionOptions, command?: string): Promise;
/**
* Login a user with a password.
*
* @param user Username to use for login. Optional, default is "anonymous".
* @param password Password to use for login. Optional, default is "guest".
*/
login(user?: string, password?: string): Promise;
/**
* Set the usual default settings.
*
* Settings used:
* * Binary mode (TYPE I)
* * File structure (STRU F)
* * Additional settings for FTPS (PBSZ 0, PROT P)
*/
useDefaultSettings(): Promise;
/**
* Convenience method that calls `connect`, `useTLS`, `login` and `useDefaultSettings`.
*
* This is an instance method and thus can be called multiple times during the lifecycle of a `Client`
* instance. Whenever you do, the client is reset with a new control connection. This also implies that
* you can reopen a `Client` instance that has been closed due to an error when reconnecting with this
* method. In fact, reconnecting is the only way to continue using a closed `Client`.
*/
access(options?: AccessOptions): Promise;
/**
* Get the current working directory.
*/
pwd(): Promise;
/**
* Get a description of supported features.
*
* This sends the FEAT command and parses the result into a Map where keys correspond to available commands
* and values hold further information. Be aware that your FTP servers might not support this
* command in which case this method will not throw an exception but just return an empty Map.
*/
features(): Promise