Node.js connect to ftp and download files

后端 未结 2 395
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 15:58

Hello i downloaded this npm module to connect to my ftp : node-ftps

connection class

var FTPS = require(\'ftps\');
var ftps = new F         


        
相关标签:
2条回答
  • 2021-01-12 16:36

    I would advice you to try node-ftp which supports ftps too, Although node-ftps does the same work, it lacks good documentation and examples.

    Checkout here,

    https://github.com/mscdex/node-ftp

    To setup a connection and to access it features, All you need to do is to download a node wrapper called ftp-client which is developed exclusively for the node-ftp module.

    You can install this wrapper by issuing the below command,

    npm install ftp-client
    

    To initialize it use the below command,

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

    And you can find a complete example code here which will walk you through how we can 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.

    https://github.com/noodny/node-ftp-client#examples

    Hope this helps!

    0 讨论(0)
  • 2021-01-12 16:42

    I have recently tried node-ftp and found that is has issues connecting to some newer servers. Particularly I had no ability to connect to a server version SSH-2.0-1.82_sshlib Globalscape

    ssh2-sftp-client worked for me. Pass a debug:yourDebugFunction parameter in the connect options for good debugging output.

    https://www.npmjs.com/package/ssh2-sftp-client

    let sftp = new Client();
     
    sftp.connect({
      host: '127.0.0.1',
      port: '8080',
      username: 'username',
      password: '******'
    }).then(() => {
      return sftp.list('/pathname');
    }).then(data => {
      console.log(data, 'the data info');
    }).catch(err => {
      console.log(err, 'catch error');
    });```
    
    0 讨论(0)
提交回复
热议问题