tough-cookie-ftp-store

1.0.0 • Public • Published

Tough Cookie FTP Store

npm version npm downloads Commitizen friendly semantic-release Build Status Coverage Status license

Installation

npm install tough-cookie-ftp-store --save

Usage

const { CookieJar, Cookie } = require('tough-cookie');
const { FtpCookieStore } = require('tough-cookie-ftp-store');

const ftpConfig = {
  host: 'example.com',
  port: 21,
  user: 'my-username',
  password: 'my-secret-password',
  secure: false
};

const filePath = '/cookies/my-cookies.json';

const main = async () => {
  // create client
  const store = new FtpCookieStore(filePath, {
    timeout: 30000, // ftp connection timeout, in ms (30 seconds)
    debug: false
  });

  // connect to ftp server
  await store.connect(ftpConfig);

  // create a cookie jar
  const cookieJar = new CookieJar(store);

  // set an example cookie
  const cookie = Cookie.parse('foo=bar; Domain=example.com; Path=/');

  // put cookie to cookie jar
  await cookieJar.setCookie(cookie, 'http://example.com', (error, cookie) => {
    // handle errors
    if (error) {
      console.log(error);
    }

    // show cookie
    console.log(cookie);

    // kill ftp connection
    store.disconnect();
  });
}

License

GNU General Public License v3.0

Readme

Keywords

Package Sidebar

Install

npm i tough-cookie-ftp-store

Weekly Downloads

1

Version

1.0.0

License

GPL-3.0

Unpacked Size

52.9 kB

Total Files

11

Last publish

Collaborators

  • ridvanaltun