@guestbell/fast-ftp / Exports / AsyncClient
-
Client
↳
AsyncClient
- abort
- addListener
- append
- ascii
- binary
- cdup
- connect
- cwd
- delete
- destroy
- emit
- end
- eventNames
- get
- getMaxListeners
- lastMod
- list
- listSafe
- listenerCount
- listeners
- logout
- mkdir
- off
- on
- once
- prependListener
- prependOnceListener
- put
- pwd
- rawListeners
- removeAllListeners
- removeListener
- rename
- restart
- rmdir
- setMaxListeners
- site
- size
- status
- system
• deleteAsync: (path
: string
) => Promise
<void
>
▸ (path
): Promise
<void
>
Name | Type |
---|---|
path |
string |
Promise
<void
>
• listAsync: (path
: string
) => Promise
<ListingElement
[]>
▸ (path
): Promise
<ListingElement
[]>
Name | Type |
---|---|
path |
string |
Promise
<ListingElement
[]>
• mkdirAsync: (path
: string
) => Promise
<void
>
▸ (path
): Promise
<void
>
Name | Type |
---|---|
path |
string |
Promise
<void
>
• putAsync: (path
: string
, remotePath
: string
) => Promise
<void
>
▸ (path
, remotePath
): Promise
<void
>
Name | Type |
---|---|
path |
string |
remotePath |
string |
Promise
<void
>
• renameAsync: (oldName
: string
, newName
: string
) => Promise
<void
>
▸ (oldName
, newName
): Promise
<void
>
Name | Type |
---|---|
oldName |
string |
newName |
string |
Promise
<void
>
• rmdirAsync: (path
: string
, recursive?
: boolean
) => Promise
<void
>
▸ (path
, recursive?
): Promise
<void
>
Name | Type |
---|---|
path |
string |
recursive? |
boolean |
Promise
<void
>
▸ abort(callback
): void
Aborts the current data transfer (e.g. from get(), put(), or list())
Name | Type |
---|---|
callback |
(error : Error ) => void |
void
Client.abort
node_modules/@types/ftp/index.d.ts:217
▸ addListener(eventName
, listener
): AsyncClient
Alias for emitter.on(eventName, listener)
.
Since
v0.1.26
Name | Type |
---|---|
eventName |
string | symbol |
listener |
(...args : any []) => void |
Client.addListener
node_modules/@types/node/events.d.ts:354
▸ append(input
, destPath
, useCompression
, callback
): void
Same as put(), except if destPath already exists, it will be appended to instead of overwritten.
Name | Type | Description |
---|---|---|
input |
string | Buffer | ReadableStream |
can be a ReadableStream, a Buffer, or a path to a local file. |
destPath |
string |
|
useCompression |
boolean |
defaults to false. |
callback |
(error : Error ) => void |
- |
void
Client.append
node_modules/@types/ftp/index.d.ts:190
▸ append(input
, destPath
, callback
): void
Name | Type |
---|---|
input |
string | Buffer | ReadableStream |
destPath |
string |
callback |
(error : Error ) => void |
void
Client.append
node_modules/@types/ftp/index.d.ts:191
▸ ascii(callback
): void
Sets the transfer data type to ASCII.
Name | Type |
---|---|
callback |
(error : Error ) => void |
void
Client.ascii
node_modules/@types/ftp/index.d.ts:233
▸ binary(callback
): void
Sets the transfer data type to binary (default at time of connection).
Name | Type |
---|---|
callback |
(error : Error ) => void |
void
Client.binary
node_modules/@types/ftp/index.d.ts:238
▸ cdup(callback
): void
Optional "standard" commands (RFC 959) Changes the working directory to the parent of the current directory
Name | Type |
---|---|
callback |
(error : Error ) => void |
void
Client.cdup
node_modules/@types/ftp/index.d.ts:258
▸ connect(config?
): void
Connects to an FTP server.
Name | Type |
---|---|
config? |
Options |
void
Client.connect
node_modules/@types/ftp/index.d.ts:147
▸ cwd(path
, callback
): void
Changes the current working directory to path. callback has 2 parameters: < Error >err, < string >currentDir. Note: currentDir is only given if the server replies with the path in the response text.
Name | Type |
---|---|
path |
string |
callback |
(error : Error , currentDir? : string ) => void |
void
Client.cwd
node_modules/@types/ftp/index.d.ts:212
▸ delete(path
, callback
): void
Delete a file on the server
Name | Type |
---|---|
path |
string |
callback |
(error : Error ) => void |
void
Client.delete
node_modules/@types/ftp/index.d.ts:206
▸ destroy(): void
Closes the connection to the server immediately.
void
Client.destroy
node_modules/@types/ftp/index.d.ts:157
▸ emit(eventName
, ...args
): boolean
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Since
v0.1.26
Name | Type |
---|---|
eventName |
string | symbol |
...args |
any [] |
boolean
Client.emit
node_modules/@types/node/events.d.ts:610
▸ end(): void
Closes the connection to the server after any/all enqueued commands have been executed.
void
Client.end
node_modules/@types/ftp/index.d.ts:152
▸ eventNames(): (string
| symbol
)[]
Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbol
s.
const EventEmitter = require('events');
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
Since
v6.0.0
(string
| symbol
)[]
Client.eventNames
node_modules/@types/node/events.d.ts:669
▸ get(path
, callback
): void
Retrieves a file at path from the server. useCompression defaults to false
Name | Type |
---|---|
path |
string |
callback |
(error : Error , stream : ReadableStream ) => void |
void
Client.get
node_modules/@types/ftp/index.d.ts:172
▸ get(path
, useCompression
, callback
): void
Name | Type |
---|---|
path |
string |
useCompression |
boolean |
callback |
(error : Error , stream : ReadableStream ) => void |
void
Client.get
node_modules/@types/ftp/index.d.ts:173
▸ getMaxListeners(): number
Returns the current max listener value for the EventEmitter
which is either
set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Since
v1.0.0
number
Client.getMaxListeners
node_modules/@types/node/events.d.ts:526
▸ lastMod(path
, callback
): void
Extended commands (RFC 3659) Retrieves the last modified date and time for path
Name | Type |
---|---|
path |
string |
callback |
(error : Error , lastMod : Date ) => void |
void
Client.lastMod
node_modules/@types/ftp/index.d.ts:293
▸ list(path
, useCompression
, callback
): void
Retrieves the directory listing of path.
Name | Type | Description |
---|---|---|
path |
string |
defaults to the current working directory. |
useCompression |
boolean |
defaults to false. |
callback |
(error : Error , listing : ListingElement []) => void |
- |
void
Client.list
node_modules/@types/ftp/index.d.ts:164
▸ list(path
, callback
): void
Name | Type |
---|---|
path |
string |
callback |
(error : Error , listing : ListingElement []) => void |
void
Client.list
node_modules/@types/ftp/index.d.ts:165
▸ list(useCompression
, callback
): void
Name | Type |
---|---|
useCompression |
boolean |
callback |
(error : Error , listing : ListingElement []) => void |
void
Client.list
node_modules/@types/ftp/index.d.ts:166
▸ list(callback
): void
Name | Type |
---|---|
callback |
(error : Error , listing : ListingElement []) => void |
void
Client.list
node_modules/@types/ftp/index.d.ts:167
▸ listSafe(path
, useCompression
, callback
): void
Optional "standard" commands (RFC 959) Similar to list(), except the directory is temporarily changed to path to retrieve the directory listing. This is useful for servers that do not handle characters like spaces and quotes in directory names well for the LIST command. This function is "optional" because it relies on pwd() being available.
Name | Type |
---|---|
path |
string |
useCompression |
boolean |
callback |
(error : Error , listing : ListingElement []) => void |
void
Client.listSafe
node_modules/@types/ftp/index.d.ts:278
▸ listSafe(path
, callback
): void
Name | Type |
---|---|
path |
string |
callback |
(error : Error , listing : ListingElement []) => void |
void
Client.listSafe
node_modules/@types/ftp/index.d.ts:279
▸ listSafe(useCompression
, callback
): void
Name | Type |
---|---|
useCompression |
boolean |
callback |
(error : Error , listing : ListingElement []) => void |
void
Client.listSafe
node_modules/@types/ftp/index.d.ts:280
▸ listSafe(callback
): void
Name | Type |
---|---|
callback |
(error : Error , listing : ListingElement []) => void |
void
Client.listSafe
node_modules/@types/ftp/index.d.ts:281
▸ listenerCount(eventName
): number
Returns the number of listeners listening to the event named eventName
.
Since
v3.2.0
Name | Type | Description |
---|---|---|
eventName |
string | symbol |
The name of the event being listened for |
number
Client.listenerCount
node_modules/@types/node/events.d.ts:616
▸ listeners(eventName
): Function
[]
Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
Since
v0.1.26
Name | Type |
---|---|
eventName |
string | symbol |
Function
[]
Client.listeners
node_modules/@types/node/events.d.ts:539
▸ logout(callback
): void
Logout the user from the server.
Name | Type |
---|---|
callback |
(error : Error ) => void |
void
Client.logout
node_modules/@types/ftp/index.d.ts:201
▸ mkdir(path
, recursive
, callback
): void
Optional "standard" commands (RFC 959) Creates a new directory, path, on the server. recursive is for enabling a 'mkdir -p' algorithm and defaults to false
Name | Type |
---|---|
path |
string |
recursive |
boolean |
callback |
(error : Error ) => void |
void
Client.mkdir
node_modules/@types/ftp/index.d.ts:244
▸ mkdir(path
, callback
): void
Name | Type |
---|---|
path |
string |
callback |
(error : Error ) => void |
void
Client.mkdir
node_modules/@types/ftp/index.d.ts:245
▸ off(eventName
, listener
): AsyncClient
Alias for emitter.removeListener()
.
Since
v10.0.0
Name | Type |
---|---|
eventName |
string | symbol |
listener |
(...args : any []) => void |
Client.off
node_modules/@types/node/events.d.ts:499
▸ on(event
, listener
): AsyncClient
Name | Type |
---|---|
event |
"error" |
listener |
(error : Error ) => void |
Client.on
node_modules/@types/ftp/index.d.ts:119
▸ on(event
, listener
): AsyncClient
Name | Type |
---|---|
event |
"greeting" |
listener |
(msg : string ) => void |
Client.on
node_modules/@types/ftp/index.d.ts:120
▸ on(event
, listener
): AsyncClient
Name | Type |
---|---|
event |
"ready" |
listener |
() => void |
Client.on
node_modules/@types/ftp/index.d.ts:121
▸ on(event
, listener
): AsyncClient
Name | Type |
---|---|
event |
"end" |
listener |
() => void |
Client.on
node_modules/@types/ftp/index.d.ts:122
▸ on(event
, listener
): AsyncClient
Name | Type |
---|---|
event |
"close" |
listener |
(hadErr : boolean ) => void |
Client.on
node_modules/@types/ftp/index.d.ts:123
▸ on(event
, listener
): AsyncClient
Name | Type |
---|---|
event |
string |
listener |
() => void |
Client.on
node_modules/@types/ftp/index.d.ts:124
▸ once(eventName
, listener
): AsyncClient
Adds a one-timelistener
function for the event named eventName
. The
next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependOnceListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Since
v0.3.0
Name | Type | Description |
---|---|---|
eventName |
string | symbol |
The name of the event. |
listener |
(...args : any []) => void |
The callback function |
Client.once
node_modules/@types/node/events.d.ts:414
▸ prependListener(eventName
, listener
): AsyncClient
Adds the listener
function to the beginning of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
Since
v6.0.0
Name | Type | Description |
---|---|---|
eventName |
string | symbol |
The name of the event. |
listener |
(...args : any []) => void |
The callback function |
Client.prependListener
node_modules/@types/node/events.d.ts:634
▸ prependOnceListener(eventName
, listener
): AsyncClient
Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
Since
v6.0.0
Name | Type | Description |
---|---|---|
eventName |
string | symbol |
The name of the event. |
listener |
(...args : any []) => void |
The callback function |
Client.prependOnceListener
node_modules/@types/node/events.d.ts:650
▸ put(input
, destPath
, useCompression
, callback
): void
Sends data to the server to be stored as destPath.
Name | Type | Description |
---|---|---|
input |
string | Buffer | ReadableStream |
can be a ReadableStream, a Buffer, or a path to a local file. |
destPath |
string |
|
useCompression |
boolean |
defaults to false. |
callback |
(error : Error ) => void |
- |
void
Client.put
node_modules/@types/ftp/index.d.ts:181
▸ put(input
, destPath
, callback
): void
Name | Type |
---|---|
input |
string | Buffer | ReadableStream |
destPath |
string |
callback |
(error : Error ) => void |
void
Client.put
node_modules/@types/ftp/index.d.ts:182
▸ pwd(callback
): void
Optional "standard" commands (RFC 959) Retrieves the current working directory
Name | Type |
---|---|
callback |
(error : Error , path : string ) => void |
void
Client.pwd
node_modules/@types/ftp/index.d.ts:264
▸ rawListeners(eventName
): Function
[]
Returns a copy of the array of listeners for the event named eventName
,
including any wrappers (such as those created by .once()
).
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
Since
v9.4.0
Name | Type |
---|---|
eventName |
string | symbol |
Function
[]
Client.rawListeners
node_modules/@types/node/events.d.ts:569
▸ removeAllListeners(event?
): AsyncClient
Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter
instance was created by some other
component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Since
v0.1.26
Name | Type |
---|---|
event? |
string | symbol |
Client.removeAllListeners
node_modules/@types/node/events.d.ts:510
▸ removeListener(eventName
, listener
): AsyncClient
Removes the specified listener
from the listener array for the event namedeventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
removeListener()
will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified eventName
, then removeListener()
must be
called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that anyremoveListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
will not remove them fromemit()
in progress. Subsequent events behave as expected.
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
Because listeners are managed using an internal array, calling this will
change the position indices of any listener registered after the listener
being removed. This will not impact the order in which listeners are called,
but it means that any copies of the listener array as returned by
the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
event (as in the example below), removeListener()
will remove the most
recently added instance. In the example the once('ping')
listener is removed:
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
Returns a reference to the EventEmitter
, so that calls can be chained.
Since
v0.1.26
Name | Type |
---|---|
eventName |
string | symbol |
listener |
(...args : any []) => void |
Client.removeListener
node_modules/@types/node/events.d.ts:494
▸ rename(oldPath
, newPath
, callback
): void
Renames oldPath to newPath on the server
Name | Type |
---|---|
oldPath |
string |
newPath |
string |
callback |
(error : Error ) => void |
void
Client.rename
node_modules/@types/ftp/index.d.ts:196
▸ restart(byteOffset
, callback
): void
Extended commands (RFC 3659) Sets the file byte offset for the next file transfer action (get/put) to byteOffset
Name | Type |
---|---|
byteOffset |
number |
callback |
(error : Error ) => void |
void
Client.restart
node_modules/@types/ftp/index.d.ts:299
▸ rmdir(path
, recursive
, callback
): void
Optional "standard" commands (RFC 959) Removes a directory, path, on the server. If recursive, this call will delete the contents of the directory if it is not empty
Name | Type |
---|---|
path |
string |
recursive |
boolean |
callback |
(error : Error ) => void |
void
Client.rmdir
node_modules/@types/ftp/index.d.ts:251
▸ rmdir(path
, callback
): void
Name | Type |
---|---|
path |
string |
callback |
(error : Error ) => void |
void
Client.rmdir
node_modules/@types/ftp/index.d.ts:252
▸ setMaxListeners(n
): AsyncClient
By default EventEmitter
s will print a warning if more than 10
listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners()
method allows the limit to be
modified for this specific EventEmitter
instance. The value can be set toInfinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Since
v0.3.5
Name | Type |
---|---|
n |
number |
Client.setMaxListeners
node_modules/@types/node/events.d.ts:520
▸ site(command
, callback
): void
Sends command (e.g. 'CHMOD 755 foo', 'QUOTA') using SITE. callback has 3 parameters: < Error >err, < _string >responseText, < integer >responseCode.
Name | Type |
---|---|
command |
string |
callback |
(error : Error , responseText : string , responseCode : number ) => void |
void
Client.site
node_modules/@types/ftp/index.d.ts:223
▸ size(path
, callback
): void
Extended commands (RFC 3659) Retrieves the size of path
Name | Type |
---|---|
path |
string |
callback |
(error : Error , size : number ) => void |
void
Client.size
node_modules/@types/ftp/index.d.ts:287
▸ status(callback
): void
Retrieves human-readable information about the server's status.
Name | Type |
---|---|
callback |
(error : Error , status : string ) => void |
void
Client.status
node_modules/@types/ftp/index.d.ts:228
▸ system(callback
): void
Optional "standard" commands (RFC 959) Retrieves the server's operating system.
Name | Type |
---|---|
callback |
(error : Error , OS : string ) => void |
void
Client.system
node_modules/@types/ftp/index.d.ts:270