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.
- In VuGen, create a new “Java Vuser” script.
- 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.)
- 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”.
If you want to use key based authentication, you can also add your key file into the script.
- 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.
- Update “Actions” to read your SFTP settings and import com.jcraft.jsch.*.
- 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.
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.
- Replay and debug your script in VuGen to make sure it works as expected.
- 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.
If you want to try SRL, go to http://software.microfocus.com/srl.
The StormRunner Load team.