Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

basic-ftp

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basic-ftp

FTP client for Node.js, supports explicit FTPS over TLS, IPv6, Async/Await, and Typescript.

  • 4.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8M
increased by3.67%
Maintainers
1
Weekly downloads
 
Created

What is basic-ftp?

The basic-ftp npm package is a client for FTP and FTPS that provides an easy and reliable way to interact with FTP servers from Node.js. It allows for file transfers, directory navigation, and other common FTP operations.

What are basic-ftp's main functionalities?

Connect to an FTP server

This code sample demonstrates how to connect to an FTP server using the basic-ftp package. It includes setting up a new FTP client, connecting with credentials, and handling any errors that may occur.

const ftp = require('basic-ftp')

async function connectFTP() {
  const client = new ftp.Client()
  client.ftp.verbose = true
  try {
    await client.access({
      host: 'myftpserver.com',
      user: 'username',
      password: 'password',
      secure: true
    })
    console.log('Connected to the FTP server.')
  }
  catch(err) {
    console.log(err)
  }
  client.close()
}

connectFTP()

List files in a directory

This code sample shows how to list all files in a specific directory on the FTP server. It connects to the server, lists files in the given directory, and then logs the file list.

const ftp = require('basic-ftp')

async function listFiles() {
  const client = new ftp.Client()
  try {
    await client.access({
      host: 'myftpserver.com',
      user: 'username',
      password: 'password',
      secure: true
    })
    const fileList = await client.list('/path/to/directory')
    console.log(fileList)
  }
  catch(err) {
    console.log(err)
  }
  client.close()
}

listFiles()

Download a file

This code sample illustrates how to download a file from the FTP server. It establishes a connection, then downloads the specified file from the server to a local path.

const ftp = require('basic-ftp')
const fs = require('fs')

async function downloadFile() {
  const client = new ftp.Client()
  const localFilePath = 'local/path/to/file.txt'
  const remoteFilePath = 'remote/path/to/file.txt'

  try {
    await client.access({
      host: 'myftpserver.com',
      user: 'username',
      password: 'password',
      secure: true
    })
    await client.download(fs.createWriteStream(localFilePath), remoteFilePath)
    console.log('File downloaded successfully.')
  }
  catch(err) {
    console.log(err)
  }
  client.close()
}

downloadFile()

Upload a file

This code sample demonstrates how to upload a file to the FTP server. It connects to the server and uploads a file from a local path to the specified path on the server.

const ftp = require('basic-ftp')
const fs = require('fs')

async function uploadFile() {
  const client = new ftp.Client()
  const localFilePath = 'local/path/to/file.txt'
  const remoteFilePath = 'remote/path/to/file.txt'

  try {
    await client.access({
      host: 'myftpserver.com',
      user: 'username',
      password: 'password',
      secure: true
    })
    await client.upload(fs.createReadStream(localFilePath), remoteFilePath)
    console.log('File uploaded successfully.')
  }
  catch(err) {
    console.log(err)
  }
  client.close()
}

uploadFile()

Other packages similar to basic-ftp

Keywords

FAQs

Package last updated on 13 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc