I use the Java and URLConnection URL classes to upload a file to the server using FTP. I do not need to do anything other than just upload the file, so I would like to avoid any external libraries, and I am afraid to use the unsupported class sun.net.ftp.
Can absolute paths be used in an FTP connection string? I would like to put my files in something like "/ ftptransfers / ...", but the FTP path refers to the user's home directory.
Example download code:
URL url = new URL("ftp://username:password@host/file.txt");
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
OutputStream out = uc.getOutputStream() ;
out.write("THIS DATA WILL BE WRITTEN TO FILE".getBytes());
out.close();
Brian source
share