For example, to download ftp://ftp.xx.com/index.html:
Import Sun.Net.ftp.ftpclient; Import Java.io. *; Import Sun.Net. *;
/ ** *
Title: p> *
Description: p> *
Copyright: Copyright (c) 2004 p> *
Company: p> * @ Author petehero * @version 1.0 * /
Public class ftpdown {
Public ftpdown () {
} Public static void main (string [] args) {try {ftpclient fc = new ftpclient ("ftp.xx.com"); fc.login ("UserName", "888888"); int Ch; file fi = new file ("c: //index.html"); randomaccessfile getfile = new randomaccessfile (FI, "RW"); getFile.seek (0); telnetinputstream fget = fc.get ("index.html"); DataInputStream Puts = New DataInputStream (FGET); while ((ch = puts.read ())> = 0) {getfile.write (ch);} fget.close (); getFile.close (); fc.closeserver ();} catch IOEXCEPTION EX) {
EX.PrintStackTrace ();
}
If the file is in a certain directory, add fc.cd ("foodir");