Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ftp-sync_2.0.4.zip
Binary file not shown.
31 changes: 24 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ define(function (require, exports, module) {
var projectRoot = ProjectManager.getProjectRoot().fullPath;
var file = FileSystem.getFileForPath(projectRoot + '.ftpsync_settings');

// Replace date object with equivalent time since
function replacePwd(key, value) {
if (key === "pwd") return undefined;
return value;
Expand All @@ -77,6 +78,10 @@ define(function (require, exports, module) {
// settings file exists so parse
console.log('[ftp-sync] parsed .ftpsync_settings');
ftpSettings = $.parseJSON(text);
if (ftpSettings.lastSyncDate === undefined) {
ftpSettings.lastSyncDate = 0;
}

if (ftpSettings.connect === undefined) ftpSettings.connect = 'FTP';
callback();
});
Expand All @@ -89,6 +94,7 @@ define(function (require, exports, module) {
});
}


// handle FTP-SFTP select
function handleSelect() {

Expand Down Expand Up @@ -168,6 +174,19 @@ define(function (require, exports, module) {
});
}

function handleDisconnect (event, completed) {
// close dialog on disconnect
console.log ("Disconnect called with completed status " + completed);

if (completed) {
ftpSettings.lastSyncDate = new Date().getTime();
saveSettings();
}

Dialogs.cancelModalDialogIfOpen("ftp-dialog");

}

// general event handler of node-side events
function handleEvent(event, msg) {

Expand All @@ -191,7 +210,7 @@ define(function (require, exports, module) {
$dlg.find(".spinner").removeClass("spin");
inProcess = false;
}

if (msg) { // ignore when msg undefined
var $status = $dlg.find("#status");
msg.split('\n').forEach(function (line) {
Expand All @@ -201,11 +220,6 @@ define(function (require, exports, module) {
$status.html(line);
});
}

// close dialog on disconnect
if (event.type == "ftpsync:disconnected") {
Dialogs.cancelModalDialogIfOpen("ftp-dialog");
}
}


Expand Down Expand Up @@ -244,6 +258,9 @@ define(function (require, exports, module) {
if (ftpSettings.connect === 'SFTP') $dlg.find('#sftp-btn').trigger('click');

});

// read document date cache on dialog box creation as the
// user may flip between projects
}

function getDefaultKeyPath() {
Expand Down Expand Up @@ -294,7 +311,7 @@ define(function (require, exports, module) {

// listen for events
$(ftpDomain.connection).on("ftpsync:connected", handleEvent);
$(ftpDomain.connection).on("ftpsync:disconnected", handleEvent);
$(ftpDomain.connection).on("ftpsync:disconnected", handleDisconnect);
$(ftpDomain.connection).on("ftpsync:uploaded", handleEvent);
$(ftpDomain.connection).on("ftpsync:chkdir", handleEvent);
$(ftpDomain.connection).on("ftpsync:mkdir", handleEvent);
Expand Down
27 changes: 22 additions & 5 deletions src/node/FTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function FTP(domainManager) {
FTP.prototype.connect = function(opts, cb) {
var self = this;
this.ftp = new this.JSFtp(opts);
this.lastSyncDate = opts.lastSyncDate;
this.lastSyncDateAsDate = new Date(opts.lastSyncDate);

console.log("Set last sync date to " + this.lastSyncDateAsDate);

this.ftp.auth(opts.user, opts.pwd, function(err, data) {
if (err) {
self._domainManager.emitEvent('ftpsync', 'error', err.toString());
Expand Down Expand Up @@ -49,17 +54,29 @@ FTP.prototype.stat = function(remotePath, cb) {
};

FTP.prototype.exists = function(localPath, remotePath, cb) {
// Get information about the local file
var fsInfo = fs.statSync(localPath);
var size = fsInfo.size;

// Treat the file as if it exists if it hasn't been modified since the last sync date
if (fsInfo.mtime.getTime() <= this.lastSyncDate) {
return cb(true);
}
else {
console.log("File " + localPath + " modified on " + fsInfo.mtime + "; after last sync on " + this.lastSyncDateAsDate);
return cb(false);
}

/*var escapedRemotePath = remotePath.replace(/\s/g, "\\ ");
// stat whether same size file exists or not
this.ftp.ls(remotePath, function(err, data) {
this.ftp.ls(escapedRemotePath, function(err, data) {
if (err) return cb(err);
// irrespective of FTP 200 code, data gives us file info
if (data.length === 0) return cb(false)

// return filesize whether filesize the same
var size = fs.statSync(localPath).size;
// Compare local and remote file sizes
if (size === parseInt(data[0].size, 10)) return cb(true);
cb(false);
});
});*/
};

FTP.prototype.put = function(localPath, remotePath, cb) {
Expand Down
4 changes: 2 additions & 2 deletions src/node/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ maxerr: 50, node: true, white: true */
// console.log('final called');
if (emitOK === undefined) emitOK = true;
ftp.disconnect();
if (emitOK) _domainManager.emitEvent("ftpsync", "disconnected");
_domainManager.emitEvent("ftpsync", "disconnected", emitOK)
console.log('disconnected');
// reset flags
processOps = false;
Expand All @@ -76,7 +76,7 @@ maxerr: 50, node: true, white: true */
if (op) {
if (haltCalled) {
ops = [];
return final();
return final(false);
}
var func = op[0];
func(op[1], op[2]);
Expand Down