Skip to content

ridvanaltun/tough-cookie-ftp-store

Repository files navigation

Tough Cookie FTP Store

npm version npm downloads Commitizen friendly semantic-release Build 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

About

A JSON file store implementation for tough-cookie module.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published