Created
May 13, 2014 04:26
-
-
Save noppoMan/ab1caaf6ee4d4617d81d to your computer and use it in GitHub Desktop.
This is applied modification to use -i option at ssh connection for compiled source(~/.atom/compile-cache/coffee/*) of atom remote-sync package.
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
(function() { | |
var MessagePanelView, PlainMessageView, SSHConnection, ScpTransport, mkdirp, path, _ref; | |
_ref = require("atom-message-panel"), MessagePanelView = _ref.MessagePanelView, PlainMessageView = _ref.PlainMessageView; | |
SSHConnection = require("ssh2"); | |
mkdirp = require("mkdirp"); | |
path = require("path"); | |
module.exports = ScpTransport = (function() { | |
function ScpTransport(logger) { | |
this.logger = logger; | |
this.connections = {}; | |
} | |
ScpTransport.prototype.upload = function(rootDirectory, relativeFilePath, settings, callback) { | |
var errorHandler, localFilePath, targetFilePath; | |
localFilePath = path.join(rootDirectory, relativeFilePath); | |
targetFilePath = path.join(settings.target, relativeFilePath); | |
errorHandler = (function(_this) { | |
return function(err) { | |
_this.logger.error(err); | |
return callback(); | |
}; | |
})(this); | |
this._getConnection(settings.hostname, settings.port, settings.username, settings.password, settings.privateKey, (function(_this) { | |
return function(err, c) { | |
if (err) { | |
return errorHandler(err); | |
} | |
_this.logger.log("Uploading: " + relativeFilePath); | |
return c.sftp(function(err, sftp) { | |
if (err) { | |
return errorHandler(err); | |
} | |
return c.exec("mkdir -p \"" + (path.dirname(targetFilePath)) + "\"", function(err) { | |
if (err) { | |
return errorHandler(err); | |
} | |
return sftp.fastPut(localFilePath, targetFilePath, function(err) { | |
if (err) { | |
return errorHandler(err); | |
} | |
_this.logger.log("Uploaded: " + relativeFilePath); | |
sftp.end(); | |
return callback(); | |
}); | |
}); | |
}); | |
}; | |
})(this)); | |
return this.connections = {}; | |
}; | |
ScpTransport.prototype.download = function(rootDirectory, relativeFilePath, settings, callback) { | |
var errorHandler, localFilePath, targetFilePath; | |
localFilePath = path.join(rootDirectory, relativeFilePath); | |
targetFilePath = path.join(settings.target, relativeFilePath); | |
errorHandler = (function(_this) { | |
return function(err) { | |
_this.logger.error(err); | |
return callback(); | |
}; | |
})(this); | |
return this._getConnection(settings.hostname, settings.port, settings.username, settings.password, settings.privateKey, (function(_this) { | |
return function(err, c) { | |
if (err) { | |
return errorHandler(err); | |
} | |
_this.logger.log("Downloading: " + relativeFilePath); | |
return c.sftp(function(err, sftp) { | |
if (err) { | |
return errorHandler(err); | |
} | |
return mkdirp(path.dirname(localFilePath), function(err) { | |
if (err) { | |
return errorHandler(err); | |
} | |
return sftp.fastGet(targetFilePath, localFilePath, function(err) { | |
if (err) { | |
return errorHandler(err); | |
} | |
_this.logger.log("Downloaded: " + relativeFilePath); | |
sftp.end(); | |
return callback(); | |
}); | |
}); | |
}); | |
}; | |
})(this)); | |
}; | |
ScpTransport.prototype.fetchFileTree = function(settings, callback) { | |
return this._getConnection(settings.hostname, settings.port, settings.username, settings.password, settings.privateKey, (function(_this) { | |
return function(err, c) { | |
if (err) { | |
return callback(err); | |
} | |
return c.exec("find \"" + settings.target + "\" -type f", function(err, result) { | |
var buf; | |
if (err) { | |
return callback(err); | |
} | |
buf = ""; | |
result.on("data", function(data) { | |
return buf += data.toString(); | |
}); | |
return result.on("end", function() { | |
var files, targetRegexp; | |
targetRegexp = new RegExp("^" + settings.target + "/"); | |
files = buf.split("\n").filter(function(f) { | |
return targetRegexp.test(f); | |
}).map(function(f) { | |
return f.replace(targetRegexp, ""); | |
}); | |
return callback(null, files); | |
}); | |
}); | |
}; | |
})(this)); | |
}; | |
ScpTransport.prototype._getConnection = function(hostname, port, username, password, privateKey, callback) { | |
var connection, key, wasReady; | |
key = "" + username + "@" + hostname + ":" + port; | |
if (this.connections[key]) { | |
return callback(null, this.connections[key]); | |
} | |
this.logger.log("Connecting: " + key); | |
connection = new SSHConnection; | |
wasReady = false; | |
connection.on("ready", function() { | |
wasReady = true; | |
return callback(null, connection); | |
}); | |
connection.on("error", (function(_this) { | |
return function(err) { | |
if (!wasReady) { | |
callback(err); | |
} | |
return _this.connections[key] = void 0; | |
}; | |
})(this)); | |
connection.on("end", (function(_this) { | |
return function() { | |
return _this.connections[key] = void 0; | |
}; | |
})(this)); | |
var sshInfo = { | |
host: hostname, | |
port: port, | |
username: username | |
}; | |
if(privateKey) | |
{ | |
sshInfo.privateKey = require('fs').readFileSync(privateKey); | |
}else{ | |
sshInfo.password = password; | |
} | |
connection.connect(sshInfo); | |
return this.connections[key] = connection; | |
}; | |
return ScpTransport; | |
})(); | |
}).call(this); |
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
{ | |
"transport": "scp", | |
"hostname": "xx.xx.xx.xx", | |
"username": "jack", | |
"privateKey": "/path/to/your/key", | |
"target": "/path/to/your/remote", | |
"ignore": [ | |
".git/**" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment