Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Micro Focus Expert
Micro Focus Expert
1549 views

Testing SFTP in StormRunner Load

SFTP is an abbreviation of "Secure shell File Transfer Protocol".

If you need to use SFTP to generate load in StormRunner Load (SRL), you can choose any protocol with which you are familiar. For example: Java, TruAPI, .NET, JMeter, etc. Refer to https://admhelp.microfocus.com/srl/en/latest/Content/Storm/t_manage_scripts.htm for details about the supported protocols in SRL.

Below is a very simple example to demonstrate how to perform SFTP testing with the Java protocol.

  1. In VuGen, create a new “Java Vuser” script.

vugen_java.png

  1. From Maven repository, download the latest jsch (which is a pure Java implementation of SSH2) jar file. (The latest version is currently 0.1.55.)
  1. In VuGen, right click the “Extra Files” node in Solution Explorer and select “Add Files to Script…” to add the downloaded “jsch-0.1.55.jar”.vugen_adddeps.png

            If you want to use key based authentication, you can also add your key file into the script.

  1. Configure settings for your SFTP server (for example: host, port, username, etc.). In the example below, settings are added into the ‘Additional Attributes’ section in Runtime Settings.vugen_additionalattr.png
  2. Update “Actions” to read your SFTP settings and import com.jcraft.jsch.*.

vugen_readsetting.png

  1. You are now ready to add codes to implement real SFTP steps. For demonstration purposes, we’ll only show a very basic flow: connect to the SFTP server and then download a file.
  • Connect SSH session
       JSch jsch = new JSch();
       Session session = jsch.getSession(username, server, port);
       session.setPassword(password);
       session.connect();

If you need to use key based authentication, you can use “addIdentity” to configure it.

       JSch jsch = new JSch();   
       jsch.addIdentity("./mykey.pem");
       Session session = jsch.getSession(username, server, port);
       session.connect();

If you encounter an error related to an unknown host, you can disable it with the code below.

       Properties config = new Properties();
       config.put("StrictHostKeyChecking", "no");            
       session.setConfig(config);      
  • Connect SFTP

Once an SSH session is successfully created, an SFTP connection can be established.

      Channel channel = session.openChannel("sftp");
      channel.setXForwarding(false);
      channel.connect();

      lr.output_message("connected to " + server);
      lr.end_transaction("connect server", lr.AUTO);

      ChannelSftp sftp = (ChannelSftp)channel;
  • Download the file

With the above ‘sftp’, we can easily perform various ftp operations (for example: cd, get, put, etc.).

      SecureRandom srand = new SecureRandom();
      int rand = srand.nextInt(10000000);
      sftp.get(target_dir + "/" + filename, filename + "." + rand, null, ChannelSftp.OVERWRITE);

Above code downloads the file and saves it into the current directory with a unique number as the name suffix.

  • Cleanup
     channel.disconnect(); 
     session.disconnect(); 

For detailed usage of jsch, refer to http://www.jcraft.com/jsch/examples/ and http://www.docjar.org/docs/api/com/jcraft/jsch/package-index.html.

  1. Replay and debug your script in VuGen to make sure it works as expected.
  2. Once the script is ready, use the menu options “File” > “Manage Zip Files” > “Export to Zip File…” to create the script zip file and then upload it to SRL.

That’s it!

If you want to try SRL, go to http://software.microfocus.com/srl.

 

The StormRunner Load team.

Tags (3)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.