Skip to content

Commit

Permalink
[CopyFilesOverSSH] Migrated to ssh2-sftp-client library (#13312)
Browse files Browse the repository at this point in the history
* [CopyFilesOverSSH] Migrated to ssh2-sftp-client library

* [CopyFilesOverSSH] Addressed code review points
  • Loading branch information
Sergey Dobrodeev authored Aug 3, 2020
1 parent 431cd6d commit 8726073
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
"loc.input.label.targetFolder": "Target folder",
"loc.input.help.targetFolder": "Target folder on the remote machine to where files will be copied. Example: /home/user/MySite.",
"loc.input.label.isWindowsOnTarget": "Target machine running Windows",
"loc.input.help.isWindowsOnTarget": "Indicates that remote machine is running Windows",
"loc.input.help.isWindowsOnTarget": "Target machine running Windows",
"loc.input.label.cleanTargetFolder": "Clean target folder",
"loc.input.help.cleanTargetFolder": "Delete all existing files and subfolders in the target folder before copying.",
"loc.input.label.readyTimeout": "SSH handshake timeout",
"loc.input.help.readyTimeout": "How long (in milliseconds) to wait for the SSH handshake to complete.",
"loc.input.label.overwrite": "Overwrite",
"loc.input.help.overwrite": "Replace existing files in and beneath the target folder.",
"loc.input.label.failOnEmptySource": "Fail if no files found to copy",
"loc.input.help.failOnEmptySource": "Fail if no matching files to be copied are found under the source folder.",
"loc.input.label.flattenFolders": "Flatten folders",
"loc.input.help.flattenFolders": "Flatten the folder structure and copy all files into the specified target folder on the remote machine.",
"loc.input.label.readyTimeout": "SSH handshake timeout",
"loc.input.help.readyTimeout": "How long (in milliseconds) to wait for the SSH handshake to complete.",
"loc.messages.CheckLogForStdErr": "Check the build log for STDERR from the command.",
"loc.messages.CleanTargetFolder": "Cleaning target folder %s on the remote machine",
"loc.messages.CleanTargetFolderFailed": "Failed to clean the target folder on the remote machine. %s",
Expand All @@ -41,5 +41,6 @@
"loc.messages.SourceNotFolder": "Source folder has to be a valid folder path.",
"loc.messages.StartedFileCopy": "Copying file %s to %s on remote machine.",
"loc.messages.UploadFileFailed": "Failed to upload %s to %s on remote machine. %s.",
"loc.messages.UseDefaultPort": "Using port 22 which is the default for SSH since no port was specified."
"loc.messages.UseDefaultPort": "Using port 22 which is the default for SSH since no port was specified.",
"loc.messages.TargetNotCreated": "Unable to create target folder %s."
}
2 changes: 1 addition & 1 deletion Tasks/CopyFilesOverSSHV0/ThirdPartyNotice.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This Azure DevOps extension (CopyFilesOverSSHV0) is based on or incorporates mat
18. path-is-absolute (git+https://github.com/sindresorhus/path-is-absolute.git)
19. q (git://github.com/kriskowal/q.git)
20. readable-stream (git://github.com/isaacs/readable-stream.git)
21. scp2 (git+https://github.com/lepture/node-scp2.git)
21. ssh2-sftp-client (git+https://github.com/theophilusx/ssh2-sftp-client.git)
22. semver (git+https://github.com/npm/node-semver.git)
23. shelljs (git://github.com/arturadib/shelljs.git)
24. ssh2 (git+ssh://git@github.com/mscdex/ssh2.git)
Expand Down
8 changes: 6 additions & 2 deletions Tasks/CopyFilesOverSSHV0/copyfilesoverssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ async function run() {
.replace(/^\//g, "");
}
tl.debug('relativePath = ' + relativePath);
const targetPath = path.posix.join(targetFolder, relativePath);
let targetPath = path.posix.join(targetFolder, relativePath);

if (!path.isAbsolute(targetPath)) {
targetPath = `./${targetPath}`;
}

console.log(tl.loc('StartedFileCopy', fileToCopy, targetPath));
if (!overwrite) {
Expand Down Expand Up @@ -250,7 +254,7 @@ async function run() {
// close the client connection to halt build execution
if (sshHelper) {
tl.debug('Closing the client connection');
sshHelper.closeConnection();
await sshHelper.closeConnection();
}
}
}
Expand Down
181 changes: 77 additions & 104 deletions Tasks/CopyFilesOverSSHV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tasks/CopyFilesOverSSHV0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"homepage": "https://github.com/Microsoft.com/vsts-tasks#readme",
"dependencies": {
"scp2": "^0.5.0",
"ssh2-sftp-client": "^5.1.2",
"ssh2": "^0.8.2",
"minimatch": "^3.0.4",
"azure-pipelines-task-lib": "^2.9.3"
Expand Down
Loading

0 comments on commit 8726073

Please sign in to comment.