import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import javax.swing.JOptionPane;
import javax.swing.ProgressMonitorInputStream;
import TIp.Jframet;
import doFile.ZipToFile;
import sun.net.TelnetInputStream;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;
public class FtpZipOption {
/**
*
* 从ftp服务器 下载zip文件
*
* @param
*
*@throws Exception
**/
public static void downLoadZipFile(String wantFileName ) throws Exception {
/*new Thread(){
public void run(){
Jframet jf = new Jframet("正在链接ftp,qing'shao'h", "确定");
jf.jb.setVisible(false);
}
}.start();*/
String[] localFileNameArray = getLocalFileNameArray("c:\\BaseMap");// 得到所有已经下载的tb文件名
File downFile=new File("c:\\BaseMap");
if(!downFile.exists()) downFile.mkdir();
if (ifToDownLoadFile(wantFileName, localFileNameArray)) {// 判断是否需要下载
String str; // 输出信息字符串
/**
*
* 和服务器建立连接
*/
FtpClient ftp = new FtpClient("172.18.2.66"); // 根据服务器ip建立连接
//JOptionPane.showMessageDialog(null, "");
str = ftp.getResponseString(); // 获得响应信息
/**
*
* 登陆到Ftp服务器
*/
ftp.login("admin", "1"); // 根据用户名和密码登录服务器
str = ftp.getResponseString();
System.out.println("登录:" + str);
/**
*
* 打开并定位到服务器目录
*/
ftp.cd("mapdata2"); // 打开服务器上的文件目录
str = ftp.getResponseString();
System.out.println("打开服务器目录:" + str);
ftp.binary();// 转化为二进制的文件
TelnetInputStream ftpIn = ftp.get(wantFileName + ".zip");// 找到要读取的文件
/*Jframet jf=new Jframet("正在下载地图,请稍候...","确定");
jf.jb.setVisible(false);*/
long fileLength=FtpZipOption.getFileSize("wantFileName.zip");
System.out.println(fileLength);
byte[] buf = new byte[204800];
int bufsize = 0;
File f=new File("c:\\BaseMap");
if(!f.exists()) f.mkdirs();
String toLocalPath = "c:\\BaseMap\\" + wantFileName + ".zip";
/*File f=new File(toLocalPath);
f.mkdirs();*/
FileOutputStream ftpOut = new FileOutputStream(toLocalPath);
int readLine=0;
while ((bufsize = ftpIn.read(buf, 0, buf.length)) != -1) {
//System.out.println(bufsize);
ftpOut.write(buf, 0, bufsize);
readLine=+bufsize;
}
System.out.println(readLine);
ftpOut.close();
ftpIn.close();
ZipToFile ziptofile=new ZipToFile();
String PostFilePath = "c:\\BaseMap";
ziptofile.zipToFile(toLocalPath, PostFilePath);
// JOptionPane.showMessageDialog(null, "下载" + wantFileName + ".zip完成!");
System.out.println("下载" + wantFileName + ".zip完成!");
/* jf.jl.setText("下载地图成功");
jf.jb.setVisible(true);*/
} else {
}
}
public static long getFileSize(String filename) throws IOException {
String str