比如要下载ftp://[url=ftp://ftp.xx.com]ftp.xx.com/index.html则:
import sun.net.ftp.FtpClient;
import java.io.*;
import sun.net.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <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();
}
}
}
如果文件在某个目录下,则加入fc.cd("foodir");