Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs2lite.dev.ftp;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import com.rs2lite.dev.gui.ControlFrame;
- public class FTPClientConnection {
- public final String host;
- public final String user;
- protected final String password;
- protected URLConnection urlc;
- public FTPClientConnection(String host, String user, String password) {
- this.host = host;
- this.user = user;
- this.password = password;
- this.urlc = null;
- }
- protected URL makeURL(String targetfile) throws MalformedURLException {
- if (user == null)
- return new URL("ftp://"+ host+ "/"+ targetfile+ ";type=i");
- else
- return new URL("ftp://"+ user+ ":"+ password+ "@"+ host+ "/"+ targetfile+ ";type=i");
- }
- protected InputStream openDownloadStream(String targetfile) throws Exception {
- URL url = makeURL(targetfile);
- urlc = url.openConnection();
- InputStream is = urlc.getInputStream();
- return is;
- }
- protected OutputStream openUploadStream(String targetfile) throws Exception {
- URL url = makeURL(targetfile);
- ControlFrame.getInstance().getLoggerPanel().appendLine("Opening upload to "+url.getHost()+"...");
- urlc = url.openConnection();
- OutputStream os = urlc.getOutputStream();
- ControlFrame.getInstance().getLoggerPanel().appendLine("Connected.");
- return os;
- }
- protected void close() {
- urlc = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement