Last active
August 29, 2015 14:03
-
-
Save victorkurauchi/7640b5f699bf43ffedcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsftp = require("jsftp"); | |
var Ftp = function($host, $port, $user, $pass) { | |
this.instance = null; | |
this.host = $host; | |
this.port = $port; | |
this.user = $user; | |
this.pass = $pass; | |
} | |
Ftp.prototype.auth = function(callback) { | |
var self = this; | |
var ftp = new jsftp({ | |
host: self.host, | |
port: self.port, // defaults to 21 | |
user: self.user, // defaults to "anonymous" | |
pass: self.pass // defaults to "@anonymous" | |
}); | |
ftp.auth(ftp.user, ftp.pass, function(err, result) { | |
if (err) throw err; | |
self.instance = ftp; | |
callback(err, result); | |
}); | |
} | |
Ftp.prototype.getFile = function(path, callback) { | |
var str = ''; // Will store the contents of the file | |
this.instance.get(path, function(err, socket) { | |
if (err) return; | |
socket.on('data', function(d) { | |
str += d.toString(); | |
//console.log('doing...'); | |
}); | |
socket.on('close', function(hadErr) { | |
if (hadErr) | |
console.error('There was an error retrieving the file.'); | |
else | |
callback(err, str); | |
}); | |
socket.resume(); | |
}); | |
} | |
module.exports = Ftp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment