<commit_before>var __hasProp = {}.hasOwnProperty,
	__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
	FS = require('fs-plus'),
	Path = require('path'),
	events = require('events'),
	FTP,
	SFTP,
	Directory = require('./directory');

module.exports = (function () {

	__extends(Client, events.EventEmitter);

	function Client () {
		this.info = null;
		this.connector = null;
		this._current = null;
		this._queue = [];

		this.root = new Directory({
			name: '/',
			path: '/',
			client: this,
			isExpanded: true
		});
	}

	__extends(Progress, events.EventEmitter);

	function Progress () {
		this.progress = -1;
		this._start = 0;
	}

	Progress.prototype.setProgress = function (progress) {
		progress = parseFloat(progress) || -1;

		if (this.progress == -1 && progress > -1)
			this._start = (new Date).getTime();

		this.progress = progress;
		this.emit('progress', this.progress);

		if (this.progress == 1)
			this.emit('done');
	}

	Progress.prototype.isDone = function () {
		return this.progress >= 1;
	}

	Progress.prototype.getEta = function () {
		if (this.progress == -1)
			return Infinity;
		var now = (new Date).getTime(),
			elapse = now - this._start,
			remaining = elapse * 1 / this.progress;
		//return 1 * delta / this.progress;
		return remaining - elapse;
	}

	Client.prototype.readConfig = function (callback) {
		var self = this;

		function e (err) {
			if (typeof callback === 'function')
				callback.apply(self, [err]);
		}

		FS.readFile(atom.project.resolve('.ftpconfig'), 'utf8', function (err, data) {
			if (err)
				return e(err);

			var json;
			try {
				json = JSON.parse(data);
			} catch (err) {
				throw "Parse error in `.ftpconfig` JSON : " + err;
				//return e('Parse error in .ftpconfg\'s JSON :\n  '+ err);
			}

			self.info = json;
			self.root.name = '';
			self.root.path = '/' + self.info.remote.replace(/^\/+/, '');

			if (typeof callback === 'function')
				callback.apply(self, [err, json]);
		});
	}

	Client.prototype.isConnected = function (onconnect) {
		return this.connector && this.connector.isConnected();
	}

	Client.prototype.onceConnected = function (onconnect) {
		var self = this;
		if (self.connector && self.connector.isConnected()) {
			onconnect.apply(self);
			return true;
		} else if (typeof onconnect === 'function') {
			self.readConfig(function () {
				self.connect(true);
			});
			self.once('connected', onconnect);
			return false;
		}
	}

	Client.prototype.connect = function (reconnect) {
		var self = this;

		if (reconnect !== true)
			self.disconnect();

		if (!self.info)
			return;

		var info;
		switch (self.info.protocol) {
			case 'ftp':
				info = {
					host: self.info.host || '',
					port: self.info.port || 21,
					user: self.info.user || '',
					password: self.info.pass || '',
					secure: self.info.secure || '',
					secureOptions: self.info.secureOptions || '',
					connTimeout: self.info.timeout || 10000,
					pasvTimeout: self.info.timeout || 10000,
					keepalive: self.info.keepalive || 10000,
					debug: function (str) {
						var log = str.match(/^\[connection\] (>|<) '(.*?)(\\r\\n)?'$/);
						if (!log) return;
						if (log[2].match(/^PASS /))
							log[2] = 'PASS ******';
						self.emit('debug', log[1] +' '+ log[2]);
						console.debug(log[1] +' '+ log[2]);
					}
				};
				if (!FTP) FTP = require('./connectors/ftp');
				self.connector = new FTP(self);
				break;
			case 'sftp':
				info = {
					host: self.info.host || '',
					port: self.info.port || 21,
					username: self.info.user || '',
					readyTimeout: self.info.connTimeout || 10000,
					pingInterval: self.info.keepalive || 10000
				};
				if (self.info.pass)
					info.password = <PASSWORD>;

				var pk;
				if (self.info.privatekey && (pk = FS.readFileSync(self.info.privatekey)))
					info.privateKey = pk;

				if (self.info.passphrase)
					info.passphrase = self.info.passphrase;

				if (self.info.agent)
					info.agent = self.info.agent;

				if (self.info.hosthash)
					info.hostHash = self.info.hosthash;

				if (self.info.ignorehost)
					info.hostVerifier = function () { return true; }<commit_msg>added option to get ssh-agent socket from environment var<commit_after>var __hasProp = {}.hasOwnProperty,
	__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
	FS = require('fs-plus'),
	Path = require('path'),
	events = require('events'),
	FTP,
	SFTP,
	Directory = require('./directory');

module.exports = (function () {

	__extends(Client, events.EventEmitter);

	function Client () {
		this.info = null;
		this.connector = null;
		this._current = null;
		this._queue = [];

		this.root = new Directory({
			name: '/',
			path: '/',
			client: this,
			isExpanded: true
		});
	}

	__extends(Progress, events.EventEmitter);

	function Progress () {
		this.progress = -1;
		this._start = 0;
	}

	Progress.prototype.setProgress = function (progress) {
		progress = parseFloat(progress) || -1;

		if (this.progress == -1 && progress > -1)
			this._start = (new Date).getTime();

		this.progress = progress;
		this.emit('progress', this.progress);

		if (this.progress == 1)
			this.emit('done');
	}

	Progress.prototype.isDone = function () {
		return this.progress >= 1;
	}

	Progress.prototype.getEta = function () {
		if (this.progress == -1)
			return Infinity;
		var now = (new Date).getTime(),
			elapse = now - this._start,
			remaining = elapse * 1 / this.progress;
		//return 1 * delta / this.progress;
		return remaining - elapse;
	}

	Client.prototype.readConfig = function (callback) {
		var self = this;

		function e (err) {
			if (typeof callback === 'function')
				callback.apply(self, [err]);
		}

		FS.readFile(atom.project.resolve('.ftpconfig'), 'utf8', function (err, data) {
			if (err)
				return e(err);

			var json;
			try {
				json = JSON.parse(data);
			} catch (err) {
				throw "Parse error in `.ftpconfig` JSON : " + err;
				//return e('Parse error in .ftpconfg\'s JSON :\n  '+ err);
			}

			self.info = json;
			self.root.name = '';
			self.root.path = '/' + self.info.remote.replace(/^\/+/, '');

			if (typeof callback === 'function')
				callback.apply(self, [err, json]);
		});
	}

	Client.prototype.isConnected = function (onconnect) {
		return this.connector && this.connector.isConnected();
	}

	Client.prototype.onceConnected = function (onconnect) {
		var self = this;
		if (self.connector && self.connector.isConnected()) {
			onconnect.apply(self);
			return true;
		} else if (typeof onconnect === 'function') {
			self.readConfig(function () {
				self.connect(true);
			});
			self.once('connected', onconnect);
			return false;
		}
	}

	Client.prototype.connect = function (reconnect) {
		var self = this;

		if (reconnect !== true)
			self.disconnect();

		if (!self.info)
			return;

		var info;
		switch (self.info.protocol) {
			case 'ftp':
				info = {
					host: self.info.host || '',
					port: self.info.port || 21,
					user: self.info.user || '',
					password: self.info.pass || '',
					secure: self.info.secure || '',
					secureOptions: self.info.secureOptions || '',
					connTimeout: self.info.timeout || 10000,
					pasvTimeout: self.info.timeout || 10000,
					keepalive: self.info.keepalive || 10000,
					debug: function (str) {
						var log = str.match(/^\[connection\] (>|<) '(.*?)(\\r\\n)?'$/);
						if (!log) return;
						if (log[2].match(/^PASS /))
							log[2] = 'PASS ******';
						self.emit('debug', log[1] +' '+ log[2]);
						console.debug(log[1] +' '+ log[2]);
					}
				};
				if (!FTP) FTP = require('./connectors/ftp');
				self.connector = new FTP(self);
				break;
			case 'sftp':
				info = {
					host: self.info.host || '',
					port: self.info.port || 21,
					username: self.info.user || '',
					readyTimeout: self.info.connTimeout || 10000,
					pingInterval: self.info.keepalive || 10000
				};
				if (self.info.pass)
					info.password = self.<PASSWORD>;

				var pk;
				if (self.info.privatekey && (pk = FS.readFileSync(self.info.privatekey)))
					info.privateKey = pk;

				if (self.info.passphrase)
					info.passphrase = self.info.passphrase;

				if (self.info.agent)
					info.agent = self.info.agent;

				if (info.agent == 'env')                                                                                
					info.agent = process.env.SSH_AUTH_SOCK   

				if (self.info.hosthash)
					info.hostHash = self.info.hosthash;

				if (self.info.ignorehost)
					info.hostVerifier = function () { return true; }
{'fraction_non_alphanumeric': 0.1722783389450056, 'fraction_numerical': 0.010325476992143659, 'mean_word_length': 2.835987946620749, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '860458', 'n_tokens_mistral': 3647, 'n_tokens_neox': 2944, 'n_words': 659}