cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
460
Views
0
Helpful
0
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee

 

 

Task Name

UCSD - SFTP task with credential policy

Description

 

Prerequisites

Validated on UCSD 6.6

Category

Workflow Task

Components

 

User Inputs

 

Output

Result of operation

 

 

Installation

  1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
  2. Unzip the file on your computer. Should end up with a .WFDX file.
  3. Log in to UCS Director as a user that has "system-admin" privileges.
  4. Navigate to "Policies-->Orchestration" and click on "Import".
  5. Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
  6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
  7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
  8. Click "Submit".
  9. A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment.

 A big thank you for this contribution goes out to: Sabina Al Farah 

 

Workflow example: 
 
Screen Shot 2018-10-18 at 8.13.02 AM.png
 
 
Items at workflow Import: 
 
Screen Shot 2018-10-18 at 8.11.39 AM.png
 
Workflow task Input: 
 
Screen Shot 2018-10-18 at 8.14.20 AM.png
 The code: 
 

 

importPackage(java.io);

importPackage(com.jcraft.jsch);

importPackage(com.cloupia.lib.connector.account.credential);

 

//var host = "10.105.XX.XX";

//var localFile = "/root/hello/mytest.text";

//var remoteDir = "/root/ABC/TEST123";

//var credentialPolicy = "Name of policy";

//file will be copied from "/root/hello/mytest.text on UCSD host to "/root/ABC/TEST123/mytest.text on remotehost

 

 

var host = input.host;

var credentialPolicy = input.credentialPolicy;

var localFile = input.localFile;

var remoteDir = input.remoteDir;

 

var policy = PersistenceUtil.getCredentialPolicyByName(credentialPolicy);

var password = policy.getPassword();

var user = policy.getUserName();

var port = policy.getPort();

 

uploadFileSFTP();

 

//========================

 

function uploadFileSFTP() {

 

       var success = false;

       var session = null;

       var channel = null;

       try {

              var ssh = new JSch();

              session = ssh.getSession(user, host, port);

              session.setPassword(password);

       session.setConfig("StrictHostKeyChecking", "no");

              session.connect();

              channel = session.openChannel("sftp");

              channel.connect();

              logger.addInfo("SFTP connection to " + host + " established ");

 

              var sftp = channel;

 

              var path = "";

              var paths = remoteDir.split("/");

              for (i = 0; i < paths.length; i++) {

                     if (!paths[i].equals("")) {

                            path = path + "/" + paths[i];

                            logger.addInfo("Create Remote Directory " + path);

                            try {

                                   sftp.stat(path);

                            } catch (e) {

                                   // dir does not exist.

                                   sftp.mkdir(path);

                            }

                     }

              }

 

              var localPaths = localFile.split("/");

              var fileName = localPaths[localPaths.length - 1];

              logger.addInfo("Put localFile " + localFile + " into remoteDir " + remoteDir + "/" + fileName);

              sftp.put(localFile, remoteDir + "/" + fileName);

              success = true;

              logger.addInfo("File upload successful !! ");

       } catch (e) {

              logger.addError("Error: " + e.message);

       } finally {

              if (channel !== null) {

                     channel.disconnect();

              }

              if (sftp !== null) {

                     sftp.disconnect();

              }

              if (session !== null) {

                     session.disconnect();

              }

       }

 

       if (!success) {

              ctxt.setFailed("Unable to transfer the file!");

              ctxt.exit();

       }

}

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links