Ftp клиент на javascript

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

License

noodny/node-ftp-client

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

node-ftp-client is a wrapper for the popular FTP client module for node.js — node-ftp, which provides an easy way of manipulating FTP transfers.

To crate an instance of the wrapper use the following code:

var ftpClient = require('ftp-client'), client = new ftpClient(config, options);

where config contains the ftp server configuration (these are the default values):

 host: 'localhost', port: 21, user: 'anonymous', password: 'anonymous@' >

and the options object may contain the following keys:

  • logging (String): ‘none’, ‘basic’, ‘debug’ — level of logging for all the tasks — use ‘debug’ in case of any issues
  • overwrite (String): ‘none’, ‘older’, ‘all’ — determines which files should be overwritten when downloading/uploading — ‘older’ compares the date of modification of local and remote files

After creating the new object you have to manually connect to the server by using the connect method:

And passing the callback which should be executed when the client is ready.

  • download( < String >remoteDir, < String >localDir, < Object >options, < Function >callback) — downloads the contents of remoteDir to localDir if both exist, and executes the callback if one is supplied with the following object as a parameter:
 downloadedFiles: [(filename)], errors:  (filename): (error) > >

options is an object with the following possible keys * overwrite (String): ‘none’, ‘older’, ‘all’ — determines which files should be overwritten

  • upload( < mixed >source, < String >remoteDir, < Object >options, < Function >callback) — expands the source paths using the glob module, uploads all found files and directories to the specified remoteDir , and executes the callback if one is supplied with the following object as a parameter:
 uploadedFiles: [(filename)], uploadedDirectories: [(dirname)], errors:  (filename/dirname): (error) > >

source can be a string or an array of strings, and options is an object with the following possible keys * overwrite (String): ‘none’, ‘older’, ‘all’ — determines which files should be overwritten * baseDir (String) — local base path relative to the remote directory, e.g. if you want to upload file uploads/sample.js to public_html/uploads , baseDir has to be set to uploads

In this example we connect to a server, and simultaneously upload all files from the test directory, overwriting only older files found on the server, and download files from /public_html/test directory.

var ftpClient = require('./lib/client.js'), config =  host: 'localhost', port: 21, user: 'anonymous', password: 'anonymous@' >, options =  logging: 'basic' >, client = new ftpClient(config, options); client.connect(function ()  client.upload(['test/**'], '/public_html/test',  baseDir: 'test', overwrite: 'older' >, function (result)  console.log(result); >); client.download('/public_html/test2', 'test2/',  overwrite: 'all' >, function (result)  console.log(result); >); >);
  • Methods chaining
  • Queuing downloads/uploads with async in a single session
  • Connecting in constructor, with possibility to end the connection manually

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

An FTP client module for node.js

License

mscdex/node-ftp

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

node-ftp is an FTP client module for node.js that provides an asynchronous interface for communicating with an FTP server.

var Client = require('ftp'); var c = new Client(); c.on('ready', function()  c.list(function(err, list)  if (err) throw err; console.dir(list); c.end(); >); >); // connect to localhost:21 as anonymous c.connect();
var Client = require('ftp'); var fs = require('fs'); var c = new Client(); c.on('ready', function()  c.get('foo.txt', function(err, stream)  if (err) throw err; stream.once('close', function()  c.end(); >); stream.pipe(fs.createWriteStream('foo.local-copy.txt')); >); >); // connect to localhost:21 as anonymous c.connect();
var Client = require('ftp'); var fs = require('fs'); var c = new Client(); c.on('ready', function()  c.put('foo.txt', 'foo.remote-copy.txt', function(err)  if (err) throw err; c.end(); >); >); // connect to localhost:21 as anonymous c.connect();
  • greeting(< string >msg) — Emitted after connection. msg is the text the server sent upon connection.
  • ready() — Emitted when connection and authentication were sucessful.
  • close(< boolean >hadErr) — Emitted when the connection has fully closed.
  • end() — Emitted when the connection has ended.
  • error(< Error >err) — Emitted when an error occurs. In case of protocol-level errors, err contains a ‘code’ property that references the related 3-digit FTP response code.

* Note: As with the ‘error’ event, any error objects passed to callbacks will have a ‘code’ property for protocol-level errors.

  • (constructor)() — Creates and returns a new FTP client instance.
  • connect(< object >config) — (void) — Connects to an FTP server. Valid config properties:
    • host — string — The hostname or IP address of the FTP server. Default: ‘localhost’
    • port — integer — The port of the FTP server. Default: 21
    • secure — mixed — Set to true for both control and data connection encryption, ‘control’ for control connection encryption only, or ‘implicit’ for implicitly encrypted control connection (this mode is deprecated in modern times, but usually uses port 990) Default: false
    • secureOptions — object — Additional options to be passed to tls.connect() . Default: (none)
    • user — string — Username for authentication. Default: ‘anonymous’
    • password — string — Password for authentication. Default: ‘anonymous@’
    • connTimeout — integer — How long (in milliseconds) to wait for the control connection to be established. Default: 10000
    • pasvTimeout — integer — How long (in milliseconds) to wait for a PASV data connection to be established. Default: 10000
    • keepalive — integer — How often (in milliseconds) to send a ‘dummy’ (NOOP) command to keep the connection alive. Default: 10000

    Required «standard» commands (RFC 959)

    • list([< string >path, ][< boolean >useCompression, ]< function >callback) — (void) — Retrieves the directory listing of path . path defaults to the current working directory. useCompression defaults to false. callback has 2 parameters: < Error >err, < array >list. list is an array of objects with these properties:
    * type - _string_ - A single character denoting the entry type: 'd' for directory, '-' for file (or 'l' for symlink on **\*NIX only**). * name - _string_ - The name of the entry. * size - _string_ - The size of the entry in bytes. * date - _Date_ - The last modified date of the entry. * rights - _object_ - The various permissions for this entry **(*NIX only)**. * user - _string_ - An empty string or any combination of 'r', 'w', 'x'. * group - _string_ - An empty string or any combination of 'r', 'w', 'x'. * other - _string_ - An empty string or any combination of 'r', 'w', 'x'. * owner - _string_ - The user name or ID that this entry belongs to **(*NIX only)**. * group - _string_ - The group name or ID that this entry belongs to **(*NIX only)**. * target - _string_ - For symlink entries, this is the symlink's target **(*NIX only)**. * sticky - _boolean_ - True if the sticky bit is set for this entry **(*NIX only)**. 

    Optional «standard» commands (RFC 959)

    • mkdir(< string >path, [< boolean >recursive, ]< function >callback) — (void) — Creates a new directory, path , on the server. recursive is for enabling a ‘mkdir -p’ algorithm and defaults to false. callback has 1 parameter: < Error >err.
    • rmdir(< string >path, [< boolean >recursive, ]< function >callback) — (void) — Removes a directory, path , on the server. If recursive , this call will delete the contents of the directory if it is not empty. callback has 1 parameter: < Error >err.
    • cdup(< function >callback) — (void) — Changes the working directory to the parent of the current directory. callback has 1 parameter: < Error >err.
    • pwd(< function >callback) — (void) — Retrieves the current working directory. callback has 2 parameters: < Error >err, < string >cwd.
    • system(< function >callback) — (void) — Retrieves the server’s operating system. callback has 2 parameters: < Error >err, < string >OS.
    • listSafe([< string >path, ][< boolean >useCompression, ]< function >callback) — (void) — 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.

    Extended commands (RFC 3659)

    • size(< string >path, < function >callback) — (void) — Retrieves the size of path . callback has 2 parameters: < Error >err, < integer >numBytes.
    • lastMod(< string >path, < function >callback) — (void) — Retrieves the last modified date and time for path . callback has 2 parameters: < Error >err, < Date >lastModified.
    • restart(< integer >byteOffset, < function >callback) — (void) — Sets the file byte offset for the next file transfer action (get/put) to byteOffset . callback has 1 parameter: < Error >err.

    Источник

    Читайте также:  Навигация для страниц php
Оцените статью