Cache via sftp. Supports caching files and redownloading them
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.
md5
or md5sum
installed on the server.npm i sftp-cache
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)
}
})()