SFTP Using Jmeter

3,371 views
Skip to first unread message

sethi....@gmail.com

unread,
May 26, 2014, 8:16:30 AM5/26/14
to jmeter-...@googlegroups.com
Hi,

I need to use SFTP using JMeter.

Kindly Suggest.

Regards,
Shilpa.

gli...@gmail.com

unread,
May 27, 2014, 3:44:03 AM5/27/14
to jmeter-...@googlegroups.com, sethi....@gmail.com
Hi Shilpa,

The easiest option is using JMeter SSH Sampler (you'll need to compile it and drop to JMeter classpath (usually /lib or /lib/ext folder). 

If it doesn't provide functionality you need you can consider using ant-jsch or Jsch library (both of them provide exec and file SSH2 channels so it's possible to execute SSH commands and download/upload files using them). Again you'll need to add required jar(s) to JMeter classpath, restart JMeter and use i.e. Beanshell Sampler. 

Relevant Beanshell Code to perform file upload looks as follows:

import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.optional.ssh.Scp;


boolean useKeyAuthentication = true;
String username = "user";
String password = "secret";
String host = "127.0.0.1";
String remotePath = "/home/user/file.to.upload";
String localPath = "C:\\Users\\me\\Desktop\\file.to.upload";
int sshPort = 22;


Scp scp = new Scp();
Project p = new Project();
scp
.setProject(p);
StringBuilder remote = new StringBuilder();
if (useKeyAuthentication) {
    scp
.setKeyfile("/path/to/private/key/file");
    scp
.setPassphrase("passphrase");
    remote
.append(username).append("@").append(host).append(":").append(remotePath);
} else {
    remote
.append(username).append(":").append(password);
    remote
.append("@").append(host).append(":").append(remotePath);
}
scp
.setFile(localPath);
scp
.setRemoteTofile(remote.toString());
scp
.setPort(sshPort);
scp
.setTrust(true);
scp
.execute();

See How to use BeanShell: JMeter's favorite built-in component guide for more details on extending JMeter with Beanshell scripting and a kind of Beanshell cookbook. 

Hope this helps.  

rbas...@gmail.com

unread,
Mar 13, 2017, 8:20:32 AM3/13/17
to jmeter-plugins, sethi....@gmail.com, gli...@gmail.com
Hi,

Can you please suggest the version of meter being referred here?
and can you please provide the snippet for download file as well?

Regards,
-Ravi

gli...@gmail.com

unread,
Mar 13, 2017, 9:16:14 AM3/13/17
to jmeter-plugins, sethi....@gmail.com, rbas...@gmail.com
Given you have JMeter SSH Sampler plugin installed you should have SSH SFTP  sampler which provides file upload and download functionality (it is capable of listing and deleting files and folders as well)



The easiest way of installing the plugin and keeping it up-to-date is using JMeter Plugins Manager 




See Load Testing FTP and SFTP Servers Using JMeter guide for detailed information and configuration instructions.



Reply all
Reply to author
Forward
0 new messages