Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. package com.rs2lite.dev.ftp;
  2.  
  3. import java.io.InputStream;
  4. import java.io.OutputStream;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8.  
  9. import com.rs2lite.dev.gui.ControlFrame;
  10.  
  11. public class FTPClientConnection {
  12. public final String host;
  13. public final String user;
  14. protected final String password;
  15. protected URLConnection urlc;
  16.  
  17. public FTPClientConnection(String host, String user, String password) {
  18. this.host = host;
  19. this.user = user;
  20. this.password = password;
  21. this.urlc = null;
  22. }
  23. protected URL makeURL(String targetfile) throws MalformedURLException {
  24. if (user == null)
  25. return new URL("ftp://"+ host+ "/"+ targetfile+ ";type=i");
  26. else
  27. return new URL("ftp://"+ user+ ":"+ password+ "@"+ host+ "/"+ targetfile+ ";type=i");
  28. }
  29.  
  30. protected InputStream openDownloadStream(String targetfile) throws Exception {
  31. URL url = makeURL(targetfile);
  32. urlc = url.openConnection();
  33. InputStream is = urlc.getInputStream();
  34. return is;
  35. }
  36.  
  37. protected OutputStream openUploadStream(String targetfile) throws Exception {
  38. URL url = makeURL(targetfile);
  39. ControlFrame.getInstance().getLoggerPanel().appendLine("Opening upload to "+url.getHost()+"...");
  40. urlc = url.openConnection();
  41. OutputStream os = urlc.getOutputStream();
  42. ControlFrame.getInstance().getLoggerPanel().appendLine("Connected.");
  43. return os;
  44. }
  45.  
  46. protected void close() {
  47. urlc = null;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement