Any way to specify absolute paths in FTP URLs?

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();
+5
source share
2 answers

I really found out that there is a semi-standard way to do this that worked for me.

: "% 2F"

: " URL- FTP" :

, URL- ftp://myname@host.dom/%2Fetc/motd "    FTP-ing " host.dom ", " myname ",    ( , ),    " CWD/etc ", " RETR motd ".

   " ftp://myname@host.dom/etc/motd ", " CWD .. ",    " RETR motd "; " CWD "     " myname ".

,    " ftp://myname@host.dom//etc/motd ", " CWD "    , " CWD .. ", " RETR motd".

+5

, FTP apache commons "cd" , .

, URL- , .

-ACE

+1

All Articles