首页 > 解决方案 > 无法在 JMeter 中使用 SSH SFTP 采样器获取文件

问题描述

我是 JMeter 的新手并尝试连接 sftp 服务器我正在粘贴 JMeter 的日志我不确定为什么我会收到此错误如果用户名或密码有问题然后我可以使用相同的详细信息进行连接在 FileZilla 中。请帮帮我。

2019-01-01 20:23:07,423 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2019-01-01 20:23:07,424 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2019-01-01 20:23:07,425 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2019-01-01 20:23:07,581 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : FTP Users
2019-01-01 20:23:07,581 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group FTP Users.
2019-01-01 20:23:07,581 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2019-01-01 20:23:07,581 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 perThread=1000.0 delayedStart=false
2019-01-01 20:23:07,582 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2019-01-01 20:23:07,582 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2019-01-01 20:23:07,583 INFO o.a.j.t.JMeterThread: Thread started: FTP Users 1-1
2019-01-01 20:23:07,587 ERROR o.a.j.p.s.s.AbstractSSHSampler: SSH connexion error
com.jcraft.jsch.JSchException: java.net.UnknownHostException: sftp://xx.x.x.xx

标签: jmeterjmeter-pluginsjmeter-5.0

解决方案


很可能您正坐在公司代理服务器后面,这是访问 Internet 甚至可能是Intranet资源所需的。

可以将JMeter 配置为使用企业代理,但是SSH Sampler既不尊重 JMeter 代理配置,也不提供自己的代理设置。

所以目前我能想到的实现场景的唯一方法是在JSR223 Sampler中编写与 SSH 相关的代码

示例代码类似于:

def jsch = new com.jcraft.jsch.JSch()

def session = jsch.getSession('your_username', 'your_host', 22) //replace 22 with your port for custom SSH server ports
def proxy = new com.jcraft.jsch.ProxyHTTP("your_corporate_proxy_host", 3128) // replace 3128 with your corporate proxy port
proxy.setUserPasswd('corporate_proxy_username', 'corporate_proxy_password')
session.setProxy(proxy)
session.setConfig("StrictHostKeyChecking", "no")
session.setPassword('your_ssh_password')

session.connect()

def channel = session.openChannel("sftp")

((com.jcraft.jsch.ChannelSftp) channel).get('remote_file', 'local_file')

session.disconnect()

参考:


推荐阅读