Skip to content

Commit

Permalink
Merge pull request #3239 from Microsoft/users/xzhe/StringLocforFtpUpload
Browse files Browse the repository at this point in the history
string localization for task FtpUpload
  • Loading branch information
xzhe authored Dec 13, 2016
2 parents 5f08ac8 + 964b7c4 commit 45a4712
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@
"loc.input.label.preservePaths": "Preserve file paths",
"loc.input.help.preservePaths": "If selected, the relative local directory structure is recreated under the remote directory where files are uploaded. Otherwise, files are uploaded directly to the remote directory without creating additional subdirectories.<p>For example, suppose your source folder is: <b>`/home/user/source/`</b> and contains the file: <b>`foo/bar/foobar.txt`</b>, and your remote directory is: <b>`/uploads/`</b>.<br>If selected, the file is uploaded to: <b>`/uploads/foo/bar/foobar.txt`</b>. Otherwise, to: <b>`/uploads/foobar.txt`</b>.",
"loc.input.label.trustSSL": "Trust server certificate",
"loc.input.help.trustSSL": "Selecting this option results in the FTP server's SSL certificate being trusted with ftps://, even if it is self-signed or cannot be validated by a Certificate Authority (CA)."
"loc.input.help.trustSSL": "Selecting this option results in the FTP server's SSL certificate being trusted with ftps://, even if it is self-signed or cannot be validated by a Certificate Authority (CA).",
"loc.messages.FTPConnected": "connected: %s",
"loc.messages.CleanRemoteDir": "cleaning remote directory: %s",
"loc.messages.UploadRemoteDir": "uploading files to remote directory: %s",
"loc.messages.UploadSucceedMsg": "FTP upload successful %s",
"loc.messages.UploadSucceedRes": "FTP upload successful",
"loc.messages.DisconnectHost": "disconnecting from: %s",
"loc.messages.Disconnected": "disconnected",
"loc.messages.ConnectPort": "connecting to: %s:%s"
}
19 changes: 11 additions & 8 deletions Tasks/FtpUpload/ftpuploadtask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tl = require('vsts-task-lib/task');
import url = require('url');
import Q = require('q');
import path = require('path');

var Client = require('ftp');

Expand Down Expand Up @@ -28,6 +29,8 @@ export class FtpOptions {
}

function doWork() {
tl.setResourcePath(path.join( __dirname, 'task.json'));

var ftpOptions: FtpOptions = new FtpOptions();
var ftpClient: any = new Client();
var ftpHelper: ftputils.FtpHelper = new ftputils.FtpHelper(ftpOptions, ftpClient);
Expand All @@ -40,34 +43,34 @@ function doWork() {

ftpClient.on('greeting', (message: string) => {
tl.debug('ftp client greeting');
console.log('connected: ' + message);
console.log(tl.loc('FTPConnected', message));
});

ftpClient.on('ready', async () => {
tl.debug('ftp client ready');
try {
if (ftpOptions.clean) {
console.log('cleaning remote directory: ' + ftpOptions.remotePath);
console.log(tl.loc('CleanRemoteDir', ftpOptions.remotePath));
await ftpHelper.cleanRemote(ftpOptions.remotePath);
}

console.log('uploading files to remote directory: ' + ftpOptions.remotePath);
console.log(tl.loc('UploadRemoteDir', ftpOptions.remotePath));
await ftpHelper.uploadFiles(files);
uploadSuccessful = true;
console.log('FTP upload successful ' + ftpHelper.progressTracking.getSuccessStatusMessage());
console.log(tl.loc('UploadSucceedMsg', ftpHelper.progressTracking.getSuccessStatusMessage()));

tl.setResult(tl.TaskResult.Succeeded, 'FTP upload successful');
tl.setResult(tl.TaskResult.Succeeded, tl.loc('UploadSucceedRes'));
} catch (err) {
failTask(err);
} finally {
console.log('disconnecting from: ', ftpOptions.serverEndpointUrl.host);
console.log(tl.loc('DisconnectHost', ftpOptions.serverEndpointUrl.host));
ftpClient.end();
ftpClient.destroy();
}
});

ftpClient.on('close', (hadErr: boolean) => {
console.log('disconnected');
console.log(tl.loc('Disconnected'));
tl.debug('ftp client close, hadErr:' + hadErr);
});

Expand Down Expand Up @@ -104,7 +107,7 @@ function doWork() {
tl.debug('port not specifided, using default: ' + port);
}

console.log('connecting to: ' + hostName + ':' + port);
console.log(tl.loc('ConnectPort', hostName, port));
ftpClient.connect({ 'host': hostName, 'port': port, 'user': ftpOptions.username, 'password': ftpOptions.password, 'secure': secure, 'secureOptions': secureOptions });
}

Expand Down
12 changes: 11 additions & 1 deletion Tasks/FtpUpload/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 5
"Patch": 6
},
"instanceNameFormat": "FTP Upload: $(rootFolder)",
"groups": [
Expand Down Expand Up @@ -107,5 +107,15 @@
"target": "ftpuploadtask.js",
"argumentFormat": ""
}
},
"messages": {
"FTPConnected": "connected: %s",
"CleanRemoteDir": "cleaning remote directory: %s",
"UploadRemoteDir": "uploading files to remote directory: %s",
"UploadSucceedMsg": "FTP upload successful %s",
"UploadSucceedRes": "FTP upload successful",
"DisconnectHost": "disconnecting from: %s",
"Disconnected": "disconnected",
"ConnectPort": "connecting to: %s:%s"
}
}
12 changes: 11 additions & 1 deletion Tasks/FtpUpload/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 5
"Patch": 6
},
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
"groups": [
Expand Down Expand Up @@ -107,5 +107,15 @@
"target": "ftpuploadtask.js",
"argumentFormat": ""
}
},
"messages": {
"FTPConnected": "ms-resource:loc.messages.FTPConnected",
"CleanRemoteDir": "ms-resource:loc.messages.CleanRemoteDir",
"UploadRemoteDir": "ms-resource:loc.messages.UploadRemoteDir",
"UploadSucceedMsg": "ms-resource:loc.messages.UploadSucceedMsg",
"UploadSucceedRes": "ms-resource:loc.messages.UploadSucceedRes",
"DisconnectHost": "ms-resource:loc.messages.DisconnectHost",
"Disconnected": "ms-resource:loc.messages.Disconnected",
"ConnectPort": "ms-resource:loc.messages.ConnectPort"
}
}

0 comments on commit 45a4712

Please sign in to comment.