Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MashukeAlam/ed65b9247822ba8a0875310548db28c2 to your computer and use it in GitHub Desktop.
Save MashukeAlam/ed65b9247822ba8a0875310548db28c2 to your computer and use it in GitHub Desktop.
var Client = require('ftp');
const fs = require('fs');
var c = new Client();
const checkPdf = (file) => {
return file.name.endsWith('.pdf');
}
c.on('ready', function() {
c.list("/CamScanner", function(err, list) {
if (err) throw err;
list = list.filter(checkPdf);
list = list.sort((a, b) => b.date - a.date);
console.dir(list[0]);
c.get(`/CamScanner/${list[0].name}`, function(err, stream) {
if (err) throw err;
stream.once('close', function() { c.end(); });
stream.pipe(fs.createWriteStream('local-copy.pdf'));
});
});
});
c.connect({host: "192.168.0.100", port: 2221, user: "android", password: "android"});
/*
This code expects camscanner files in your mobile's /CamScanner directory.
It filters them by .pdf files then sorts them by date to get the latest one then downloads it.
All of this happens via FTP
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment