[NODE] FTP Client 사용

2023. 12. 29. 23:21카테고리 없음

 

1. NODE 에서 npm client 사용방법

FTP를 사용하기 위하여 패키지를 install 처리한다. 

npm install ftp

다운로드 cilient

const FTPClient = require('ftp');
let ftp_client = new FTPClient();
const fs = require("fs");
let ftpConfig = {
     host: "localhost",
     port: 21,
     user: 'test',
     password: 'test',
}
//create a connection to ftp server
ftp_client.connect(ftpConfig);
ftp_client.on('ready', function() {
    ftp_client.get('foo.txt', function(err, stream) {
      if (err) throw err;
      stream.once('close', function() { ftp_client.end(); });
      stream.pipe(fs.createWriteStream('foo.local-copy.txt'));
    });
  });

업로드 client

const FTPClient = require('ftp');
let ftp_client = new FTPClient();
let ftpConfig = {
     host: "localhost",
     port: 21,
     user: 'test',
     password: 'test',
}
//create a connection to ftp server
ftp_client.connect(ftpConfig);
ftp_client.on('ready', function() {
    ftp_client.put('foo.txt', 'foo.remote-copy.txt', function(err) {
      if (err) throw err;
      ftp_client.end();
    });
  });

파일리스트

const FTPClient = require('ftp');
let ftp_client = new FTPClient();
let ftpConfig = {
     host: "localhost",
     port: 21,
     user: 'test',
     password: 'test',
}
//create a connection to ftp server
ftp_client.connect(ftpConfig);
ftp_client.on('ready', function() { 
    ftp_client.list(function(err, list) {
      if (err) throw err;
      console.dir(list);
      ftp_client.end();
    });
  });

https://topcode.in/ftp-client-node/

 

Node.js FTP Client Tutorial - Top Code | How to build ftp client in Node.js

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

topcode.in

 

반응형