Skip to content

Commit

Permalink
Interpret dot second arg as copy from remote to local
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas committed Aug 21, 2024
1 parent 6729871 commit 1bd8a30
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/tasks/copy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var fs = require('fs'),
sftp = require('../sftp');
sftp = require('../sftp'),
path = require('path');

function resolveRemotePath(env, path) {
return path[0] == '/' ? path : env.current_path + '/' + path;
Expand All @@ -11,9 +12,13 @@ exports.run = function(stage, args) {
if (!args[0])
return console.log('File required, either local or remote.')

if (fs.existsSync(args[0])) { // local to remote
sftp.put(stage, args[0], resolveRemotePath(stage.env, args[1] || args[0]))
var from = args[0];
var to = args[1] || args[0];

if ((!to || to != '.') && fs.existsSync(from)) { // local to remote
sftp.put(stage, from, resolveRemotePath(stage.env, to))
} else {
sftp.get(stage, resolveRemotePath(stage.env, args[0]), args[1] || args[0])
if (to == '.') to = path.resolve('./' + path.basename(from));
sftp.get(stage, resolveRemotePath(stage.env, from), to)
}
}

0 comments on commit 1bd8a30

Please sign in to comment.