Skip to content

Commit f8e1c29

Browse files
Ivan Duplenskikhivanduplenskikh
Ivan Duplenskikh
authored andcommitted
WIP ref put files on a remote server
1 parent 47187cc commit f8e1c29

File tree

10 files changed

+58
-79
lines changed

10 files changed

+58
-79
lines changed

Tasks/CopyFilesOverSSHV0/copyfilesoverssh.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as minimatch from 'minimatch';
55
import * as utils from './utils';
66
import { SshHelper } from './sshhelper';
77

8+
import { existsSync } from "fs";
9+
810
// This method will find the list of matching files for the specified contents
911
// This logic is the same as the one used by CopyFiles task except for allowing dot folders to be copied
1012
// This will be useful to put in the task-lib
@@ -249,7 +251,7 @@ async function run() {
249251
const results = await Promise.allSettled(filesToCopy.map(async (fileToCopy) => {
250252
tl.debug('fileToCopy = ' + fileToCopy);
251253

252-
let relativePath;
254+
let relativePath: string;
253255

254256
if (flattenFolders) {
255257
relativePath = path.basename(fileToCopy);
@@ -277,8 +279,7 @@ async function run() {
277279
}
278280

279281
targetPath = utils.unixyPath(targetPath);
280-
// looks like scp can only handle one file at a time reliably
281-
return sshHelper.uploadFile(fileToCopy, targetPath);
282+
return await sshHelper.uploadFile(fileToCopy, targetPath);
282283
}));
283284

284285
var errors = results.filter(p => p.status === 'rejected') as PromiseRejectedResult[];

Tasks/CopyFilesOverSSHV0/package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/CopyFilesOverSSHV0/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
},
1818
"homepage": "https://github.com/Microsoft.com/vsts-tasks#readme",
1919
"dependencies": {
20-
"ssh2": "^1.15.0",
21-
"ssh2-sftp-client": "^9.1.0",
22-
"minimatch": "^3.0.4",
20+
"@types/mocha": "^5.2.7",
2321
"azure-pipelines-task-lib": "^5.0.0-preview.0",
24-
"@types/mocha": "^5.2.7"
22+
"minimatch": "^3.0.4",
23+
"ssh2": "^1.15.0",
24+
"ssh2-sftp-client": "^10.0.3"
2525
},
2626
"devDependencies": {
2727
"typescript": "4.0.2"

Tasks/CopyFilesOverSSHV0/sshhelper.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,15 @@ export class SshHelper {
101101
async uploadFile(sourceFile: string, dest: string) : Promise<string> {
102102
tl.debug('Upload ' + sourceFile + ' to ' + dest + ' on remote machine.');
103103

104-
return new Promise(async (resolve, reject) => {
105-
if (!this.sftpClient) {
106-
reject(tl.loc('ConnectionNotSetup'));
107-
return;
108-
}
109-
110-
try {
111-
if (this.sshConfig.useFastPut) {
112-
await this.sftpClient.fastPut(sourceFile, dest);
113-
} else {
114-
await this.sftpClient.put(sourceFile, dest);
115-
}
104+
if (!this.sftpClient) {
105+
return Promise.reject(tl.loc('ConnectionNotSetup'));
106+
}
116107

117-
resolve(dest);
118-
} catch (err) {
119-
reject(tl.loc('UploadFileFailed', sourceFile, dest, err));
120-
}
121-
});
108+
if (this.sshConfig.useFastPut) {
109+
return await this.sftpClient.fastPut(sourceFile, dest);
110+
} else {
111+
return await this.sftpClient.put(sourceFile, dest);
112+
}
122113
}
123114

124115
async uploadFolder(sourceFolder: string, destFolder: string) : Promise<string> {
@@ -132,6 +123,7 @@ export class SshHelper {
132123

133124
try {
134125
await this.sftpClient.uploadDir(sourceFolder, destFolder);
126+
return resolve(destFolder);
135127
} catch (err) {
136128
reject(tl.loc('UploadFolderFailed', sourceFolder, destFolder, err));
137129
}
@@ -219,7 +211,7 @@ export class SshHelper {
219211
}
220212
}
221213
}).on('data', (data) => {
222-
console.log(data);
214+
console.log(data.toString());
223215
}).stderr.on('data', (data) => {
224216
stdErrWritten = true;
225217
tl.debug('stderr = ' + data);

_generated/CopyFilesOverSSHV0/copyfilesoverssh.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as minimatch from 'minimatch';
55
import * as utils from './utils';
66
import { SshHelper } from './sshhelper';
77

8+
import { existsSync } from "fs";
9+
810
// This method will find the list of matching files for the specified contents
911
// This logic is the same as the one used by CopyFiles task except for allowing dot folders to be copied
1012
// This will be useful to put in the task-lib
@@ -249,7 +251,7 @@ async function run() {
249251
const results = await Promise.allSettled(filesToCopy.map(async (fileToCopy) => {
250252
tl.debug('fileToCopy = ' + fileToCopy);
251253

252-
let relativePath;
254+
let relativePath: string;
253255

254256
if (flattenFolders) {
255257
relativePath = path.basename(fileToCopy);
@@ -277,8 +279,7 @@ async function run() {
277279
}
278280

279281
targetPath = utils.unixyPath(targetPath);
280-
// looks like scp can only handle one file at a time reliably
281-
return sshHelper.uploadFile(fileToCopy, targetPath);
282+
return await sshHelper.uploadFile(fileToCopy, targetPath);
282283
}));
283284

284285
var errors = results.filter(p => p.status === 'rejected') as PromiseRejectedResult[];

_generated/CopyFilesOverSSHV0/package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_generated/CopyFilesOverSSHV0/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
},
1818
"homepage": "https://github.com/Microsoft.com/vsts-tasks#readme",
1919
"dependencies": {
20-
"ssh2": "^1.15.0",
21-
"ssh2-sftp-client": "^9.1.0",
22-
"minimatch": "^3.0.4",
20+
"@types/mocha": "^5.2.7",
2321
"azure-pipelines-task-lib": "^5.0.0-preview.0",
24-
"@types/mocha": "^5.2.7"
22+
"minimatch": "^3.0.4",
23+
"ssh2": "^1.15.0",
24+
"ssh2-sftp-client": "^10.0.3"
2525
},
2626
"devDependencies": {
2727
"typescript": "4.0.2"

_generated/CopyFilesOverSSHV0/sshhelper.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,15 @@ export class SshHelper {
101101
async uploadFile(sourceFile: string, dest: string) : Promise<string> {
102102
tl.debug('Upload ' + sourceFile + ' to ' + dest + ' on remote machine.');
103103

104-
return new Promise(async (resolve, reject) => {
105-
if (!this.sftpClient) {
106-
reject(tl.loc('ConnectionNotSetup'));
107-
return;
108-
}
109-
110-
try {
111-
if (this.sshConfig.useFastPut) {
112-
await this.sftpClient.fastPut(sourceFile, dest);
113-
} else {
114-
await this.sftpClient.put(sourceFile, dest);
115-
}
104+
if (!this.sftpClient) {
105+
return Promise.reject(tl.loc('ConnectionNotSetup'));
106+
}
116107

117-
resolve(dest);
118-
} catch (err) {
119-
reject(tl.loc('UploadFileFailed', sourceFile, dest, err));
120-
}
121-
});
108+
if (this.sshConfig.useFastPut) {
109+
return await this.sftpClient.fastPut(sourceFile, dest);
110+
} else {
111+
return await this.sftpClient.put(sourceFile, dest);
112+
}
122113
}
123114

124115
async uploadFolder(sourceFolder: string, destFolder: string) : Promise<string> {
@@ -132,6 +123,7 @@ export class SshHelper {
132123

133124
try {
134125
await this.sftpClient.uploadDir(sourceFolder, destFolder);
126+
return resolve(destFolder);
135127
} catch (err) {
136128
reject(tl.loc('UploadFolderFailed', sourceFolder, destFolder, err));
137129
}
@@ -219,7 +211,7 @@ export class SshHelper {
219211
}
220212
}
221213
}).on('data', (data) => {
222-
console.log(data);
214+
console.log(data.toString());
223215
}).stderr.on('data', (data) => {
224216
stdErrWritten = true;
225217
tl.debug('stderr = ' + data);

_generated/CopyFilesOverSSHV0_Node20/copyfilesoverssh.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as minimatch from 'minimatch';
55
import * as utils from './utils';
66
import { SshHelper } from './sshhelper';
77

8+
import { existsSync } from "fs";
9+
810
// This method will find the list of matching files for the specified contents
911
// This logic is the same as the one used by CopyFiles task except for allowing dot folders to be copied
1012
// This will be useful to put in the task-lib
@@ -249,7 +251,7 @@ async function run() {
249251
const results = await Promise.allSettled(filesToCopy.map(async (fileToCopy) => {
250252
tl.debug('fileToCopy = ' + fileToCopy);
251253

252-
let relativePath;
254+
let relativePath: string;
253255

254256
if (flattenFolders) {
255257
relativePath = path.basename(fileToCopy);
@@ -277,8 +279,7 @@ async function run() {
277279
}
278280

279281
targetPath = utils.unixyPath(targetPath);
280-
// looks like scp can only handle one file at a time reliably
281-
return sshHelper.uploadFile(fileToCopy, targetPath);
282+
return await sshHelper.uploadFile(fileToCopy, targetPath);
282283
}));
283284

284285
var errors = results.filter(p => p.status === 'rejected') as PromiseRejectedResult[];

_generated/CopyFilesOverSSHV0_Node20/sshhelper.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,15 @@ export class SshHelper {
101101
async uploadFile(sourceFile: string, dest: string) : Promise<string> {
102102
tl.debug('Upload ' + sourceFile + ' to ' + dest + ' on remote machine.');
103103

104-
return new Promise(async (resolve, reject) => {
105-
if (!this.sftpClient) {
106-
reject(tl.loc('ConnectionNotSetup'));
107-
return;
108-
}
109-
110-
try {
111-
if (this.sshConfig.useFastPut) {
112-
await this.sftpClient.fastPut(sourceFile, dest);
113-
} else {
114-
await this.sftpClient.put(sourceFile, dest);
115-
}
104+
if (!this.sftpClient) {
105+
return Promise.reject(tl.loc('ConnectionNotSetup'));
106+
}
116107

117-
resolve(dest);
118-
} catch (err) {
119-
reject(tl.loc('UploadFileFailed', sourceFile, dest, err));
120-
}
121-
});
108+
if (this.sshConfig.useFastPut) {
109+
return await this.sftpClient.fastPut(sourceFile, dest);
110+
} else {
111+
return await this.sftpClient.put(sourceFile, dest);
112+
}
122113
}
123114

124115
async uploadFolder(sourceFolder: string, destFolder: string) : Promise<string> {
@@ -132,6 +123,7 @@ export class SshHelper {
132123

133124
try {
134125
await this.sftpClient.uploadDir(sourceFolder, destFolder);
126+
return resolve(destFolder);
135127
} catch (err) {
136128
reject(tl.loc('UploadFolderFailed', sourceFolder, destFolder, err));
137129
}
@@ -219,7 +211,7 @@ export class SshHelper {
219211
}
220212
}
221213
}).on('data', (data) => {
222-
console.log(data);
214+
console.log(data.toString());
223215
}).stderr.on('data', (data) => {
224216
stdErrWritten = true;
225217
tl.debug('stderr = ' + data);

0 commit comments

Comments
 (0)