1 18 19 package org.apache.jmeter.protocol.ftp.sampler; 20 21 import org.apache.jmeter.config.ConfigTestElement; 22 import org.apache.jmeter.samplers.AbstractSampler; 23 import org.apache.jmeter.samplers.Entry; 24 import org.apache.jmeter.samplers.SampleResult; 25 26 31 public class FTPSampler extends AbstractSampler 32 { 33 public final static String SERVER = "FTPSampler.server"; 34 public final static String FILENAME = "FTPSampler.filename"; 35 36 public FTPSampler() 37 { 38 } 39 40 public String getUsername() 41 { 42 return getPropertyAsString(ConfigTestElement.USERNAME); 43 } 44 45 public String getPassword() 46 { 47 return getPropertyAsString(ConfigTestElement.PASSWORD); 48 } 49 50 public void setServer(String newServer) 51 { 52 this.setProperty(SERVER, newServer); 53 } 54 public String getServer() 55 { 56 return getPropertyAsString(SERVER); 57 } 58 public void setFilename(String newFilename) 59 { 60 this.setProperty(FILENAME, newFilename); 61 } 62 public String getFilename() 63 { 64 return getPropertyAsString(FILENAME); 65 } 66 67 74 public String getLabel() 75 { 76 return ("ftp://" + this.getServer() + "/" + this.getFilename()); 77 } 78 79 public SampleResult sample(Entry e) 80 { 81 SampleResult res = new SampleResult(); 82 boolean isSuccessful = false; 83 res.setSampleLabel(getLabel()); 85 res.sampleStart(); 88 try 89 { 90 FtpClient ftp = new FtpClient(); 91 ftp.connect(getServer(), getUsername(), getPassword()); 92 ftp.setPassive(true); 93 String s = ftp.get(getFilename()); 95 res.setResponseData(s.getBytes()); 96 ftp.disconnect(); 98 isSuccessful = true; 99 } 100 catch (java.net.ConnectException cex) 101 { 102 res.setResponseData(cex.toString().getBytes()); 106 } 107 catch (Exception ex) 108 { 109 res.setResponseData(ex.toString().getBytes()); 111 } 112 113 res.sampleEnd(); 114 115 res.setSuccessful(isSuccessful); 117 118 return res; 119 } 120 } 121
| Popular Tags
|