FTP下载文件

import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

import sun.net.TelnetInputStream;
import sun.net.ftp.FtpClient;

public class FtpDownload {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			// FTP客户端
			FtpClient fc = new FtpClient("10.42.24.83");
			fc.login("test", "test");
			fc.binary();

			System.out.println("rsp:" + fc.getResponseString());

			int ch;
			File fi = new File("d:\\temp\\ums.cap");
			RandomAccessFile getFile = new RandomAccessFile(fi, "rw");
			getFile.seek(0);

			// 获取需要下载的文件
			TelnetInputStream fget = fc.get("ums.cap");
			DataInputStream puts = new DataInputStream(fget);
			while ((ch = puts.read()) >= 0) {
				getFile.write(ch);
			}
			fget.close();
			getFile.close();
			fc.closeServer();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
}

 

你可能感兴趣的:(java,.net,sun)