Guest User

Untitled

a guest
Oct 15th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package tgactool;
  2.  
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. public class FTPclientConn {
  7.  
  8. public final String host;
  9. public final String user;
  10. protected final String password;
  11. protected URLConnection urlc;
  12.  
  13. public FTPclientConn(String _host, String _user, String _password) {
  14. host= _host; user= _user; password= _password;
  15. urlc = null;
  16. }
  17. protected URL makeURL(String targetfile) throws MalformedURLException {
  18. if (user== null)
  19. return new URL("ftp://"+ host+ "/"+ targetfile+ ";type=i");
  20. else
  21. return new URL("ftp://"+ user+ ":"+ password+ "@"+ host+ "/"+ targetfile+ ";type=i");
  22. }
  23.  
  24. protected InputStream openDownloadStream(String targetfile) throws Exception {
  25. URL url= makeURL(targetfile);
  26. urlc = url.openConnection();
  27. InputStream is = urlc.getInputStream();
  28. return is;
  29. }
  30.  
  31. protected OutputStream openUploadStream(String targetfile) throws Exception {
  32. URL url= makeURL(targetfile);
  33. urlc = url.openConnection();
  34. OutputStream os = urlc.getOutputStream();
  35. return os;
  36. }
  37.  
  38. protected void close() {
  39. urlc= null;
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment