Spaces:
Paused
Paused
File size: 6,424 Bytes
8c741f6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | /// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Socket } from "net";
import { ConnectionOptions as TLSConnectionOptions, TLSSocket } from "tls";
import { StringEncoding } from "./StringEncoding";
interface Task {
/** Handles a response for a task. */
readonly responseHandler: ResponseHandler;
/** Resolves or rejects a task. */
readonly resolver: TaskResolver;
/** Call stack when task was run. */
readonly stack: string;
}
export interface TaskResolver {
resolve(args: any): void;
reject(err: Error): void;
}
export interface FTPResponse {
/** FTP response code */
readonly code: number;
/** Whole response including response code */
readonly message: string;
}
export type ResponseHandler = (response: Error | FTPResponse, task: TaskResolver) => void;
/**
* Describes an FTP server error response including the FTP response code.
*/
export declare class FTPError extends Error {
/** FTP response code */
readonly code: number;
constructor(res: FTPResponse);
}
/**
* FTPContext holds the control and data sockets of an FTP connection and provides a
* simplified way to interact with an FTP server, handle responses, errors and timeouts.
*
* It doesn't implement or use any FTP commands. It's only a foundation to make writing an FTP
* client as easy as possible. You won't usually instantiate this, but use `Client`.
*/
export declare class FTPContext {
readonly timeout: number;
/** Debug-level logging of all socket communication. */
verbose: boolean;
/** IP version to prefer (4: IPv4, 6: IPv6, undefined: automatic). */
ipFamily: number | undefined;
/** Options for TLS connections. */
tlsOptions: TLSConnectionOptions;
/** Current task to be resolved or rejected. */
protected _task: Task | undefined;
/** A multiline response might be received as multiple chunks. */
protected _partialResponse: string;
/** The reason why a context has been closed. */
protected _closingError: NodeJS.ErrnoException | undefined;
/** Encoding supported by Node applied to commands, responses and directory listing data. */
protected _encoding: StringEncoding;
/** FTP control connection */
protected _socket: Socket | TLSSocket;
/** FTP data connection */
protected _dataSocket: Socket | TLSSocket | undefined;
/**
* Instantiate an FTP context.
*
* @param timeout - Timeout in milliseconds to apply to control and data connections. Use 0 for no timeout.
* @param encoding - Encoding to use for control connection. UTF-8 by default. Use "latin1" for older servers.
*/
constructor(timeout?: number, encoding?: StringEncoding);
/**
* Close the context.
*/
close(): void;
/**
* Close the context with an error.
*/
closeWithError(err: Error): void;
/**
* Returns true if this context has been closed or hasn't been connected yet. You can reopen it with `access`.
*/
get closed(): boolean;
/**
* Reset this contex and all of its state.
*/
reset(): void;
/**
* Get the FTP control socket.
*/
get socket(): Socket | TLSSocket;
/**
* Set the socket for the control connection. This will only close the current control socket
* if the new one is not an upgrade to the current one.
*/
set socket(socket: Socket | TLSSocket);
/**
* Get the current FTP data connection if present.
*/
get dataSocket(): Socket | TLSSocket | undefined;
/**
* Set the socket for the data connection. This will automatically close the former data socket.
*/
set dataSocket(socket: Socket | TLSSocket | undefined);
/**
* Get the currently used encoding.
*/
get encoding(): StringEncoding;
/**
* Set the encoding used for the control socket.
*
* See https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings for what encodings
* are supported by Node.
*/
set encoding(encoding: StringEncoding);
/**
* Send an FTP command without waiting for or handling the result.
*/
send(command: string): void;
/**
* Send an FTP command and handle the first response. Use this if you have a simple
* request-response situation.
*/
request(command: string): Promise<FTPResponse>;
/**
* Send an FTP command and handle any response until you resolve/reject. Use this if you expect multiple responses
* to a request. This returns a Promise that will hold whatever the response handler passed on when resolving/rejecting its task.
*/
handle(command: string | undefined, responseHandler: ResponseHandler): Promise<any>;
/**
* Log message if set to be verbose.
*/
log(message: string): void;
/**
* Return true if the control socket is using TLS. This does not mean that a session
* has already been negotiated.
*/
get hasTLS(): boolean;
/**
* Removes reference to current task and handler. This won't resolve or reject the task.
* @protected
*/
protected _stopTrackingTask(): void;
/**
* Handle incoming data on the control socket. The chunk is going to be of type `string`
* because we let `socket` handle encoding with `setEncoding`.
* @protected
*/
protected _onControlSocketData(chunk: string): void;
/**
* Send the current handler a response. This is usually a control socket response
* or a socket event, like an error or timeout.
* @protected
*/
protected _passToHandler(response: Error | FTPResponse): void;
/**
* Setup all error handlers for a socket.
* @protected
*/
protected _setupDefaultErrorHandlers(socket: Socket, identifier: string): void;
/**
* Close the control socket. Sends QUIT, then FIN, and ignores any response or error.
*/
protected _closeControlSocket(): void;
/**
* Close a socket, ignores any error.
* @protected
*/
protected _closeSocket(socket: Socket | undefined): void;
/**
* Remove all default listeners for socket.
* @protected
*/
protected _removeSocketListeners(socket: Socket): void;
/**
* Provide a new socket instance.
*
* Internal use only, replaced for unit tests.
*/
_newSocket(): Socket;
}
export {};
|