Naturally Pacifist Marsupials
    Have ideas to improve npm?Join in the discussion! »

    sftp-cache

    0.1.0 • Public • Published

    SFTP-CACHE

    npm npm

    Maintainability Contributor Covenant

    Use a directory on any ssh/sftp enabled server as a cache directory.

    The main goal is to allow caching of heavy project assets like videos to avoid unnecessary reconversions while deploying.

    Features

    • Download from cache directory and refill it again
    • Compare file by missing on other end, modification date, file size and md5 hash
    • Keeps file modification date
    • Client: Windows, Linux, OSX
    • Server: Any host supporting sftp. MD5 hash comparision also needs md5 or md5sum installed on the server.

    Installation

    npm i sftp-cache

    Usage

    const { join } = require('path')
    
    const sftpCache = require('sftp-cache')
    
    ;(async () => {
      try {
        await sftpCache({
          connection: {
            // All options: https://github.com/mscdex/ssh2#client-methods
            host: 'your.host.io',
            username: 'your-sft-user',
            password: '5up3r53cr37Pa$$w0rd'
            // Please do not store your credentials in your code. You can use environment variables & https://www.npmjs.com/package/dotenv
          },
          localDir: join(__dirname, 'assets'),
          remoteDir: '/home/your-sftp-user/sftp-cache-storage/assets',
          dirsToCache: [
            // Make sure paths are relative to localDir
            join('public', 'assets', 'videos'),
            join('node_modules', '.cache')
          ],
          // Tell it what to do:
          // cache: Uploads changed files from local to remote
          // download: Download changed files from remote to local
          syncDirection: 'cache'
        })
        console.log('success!')
      } catch (err) {
        console.log('failed!')
        console.error(err)
        process.exit(1)
      }
    })()

    Install

    npm i sftp-cache

    DownloadsWeekly Downloads

    5

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    15.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar