Skip to main content

create ftp folder using URLConnection

No replies
jeremygwa
Offline
Joined: 2006-01-17
Points: 0

All,

How do I create a ftp folder on the server by using an URL "ftp://" type string?

Thanks in advance for any help.

Jeremy

#----------------------------

class FTPclient {
public final String host;
public final String user;
protected final String password;
protected URLConnection urlc;

public FTPclient(String _host, String _user, String _password) {
host= _host; user= _user; password= _password;
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);
urlc = url.openConnection();
OutputStream os = urlc.getOutputStream();
return os;
}

protected void close() {
urlc= null;
}
}