To use this function add it to the class library file named PluginSSHService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: PluginSSHService.ts
Description: Orchestrator Function to Put a File via SSH
Public Function: putFile
public putFile(strHostFQDN: string, strUsername: string, strPassword: string, strRemoteFilePath: string, strLocalFileName: string, strContent: string, intPort: number = 22): boolean {
try {
let strLocalFilePath: string = `/var/run/vco/${strLocalFileName}-${(new Date()).getTime()}.txt`;
let objFile: File = new File(strLocalFilePath);
let objFileWriter: FileWriter = new FileWriter(objFile);
objFileWriter.open();
objFileWriter.write(strContent);
objFileWriter.close();
let objSSHCommand: SSHCommand = new SSHCommand(strHostFQDN, strUsername, strPassword, intPort);
let intExitCode: number = objSSHCommand.putFile(strLocalFilePath, strRemoteFilePath);
objFile.deleteFile();
if (intExitCode !== 0) {
this.objLogger.info(`Error while copying content of ${strLocalFileName} to remote location "${strRemoteFilePath}". Exit code: ${intExitCode}.`);
}
return true;
} catch (objException) {
return false;
}
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
