//从ftp服务器上下载Picture文件到本地目录
private boolean ftpDownLoadPicture(String picName){
boolean bool = false;
String ext = "";
String fileName = "";
String serverName = "202.109.72.212";
String userName = "sofapopjpg11";
String passWord = "sofapopjpg200811";
try {
JFileChooser filechooser = new JFileChooser();
filechooser.setFileFilter(new PicFileFilter());
filechooser.setSelectedFile(new File(picName));
int returnVal = filechooser.showSaveDialog(this);
if(returnVal == filechooser.APPROVE_OPTION){
fileName = filechooser.getSelectedFile().getPath();
int in = fileName.lastIndexOf(".");
if(in>0&&in<fileName.length()-1){
ext = fileName.substring(in+1).toLowerCase();
}
}else return false;
if(ext.equals("")) fileName = fileName.substring(0,fileName.lastIndexOf(" //")+1)+picName;
FtpClient fc = new FtpClient(serverName);
fc.login(userName, passWord);
//fc.cd("test");
int ch;
//开始下载文件
System.out.println("Downloading picture:"+picName+" ... ...");
File file = new File(fileName);
if(file.exists()) file.delete();
RandomAccessFile getFile = new RandomAccessFile(file, "rw");
getFile.seek(0);
fc.binary();//取的是bin文件,所以在get前fc.binary();
TelnetInputStream fget = fc.get(picName);//fc.nameList("")文件列表
DataInputStream puts = new DataInputStream(fget);
byte bytes[] = new byte[10240];
while ( (ch = puts.read(bytes))!= -1) {
getFile.write(bytes,0,ch);
}
// while ( (ch = puts.read()) >= 0) {
// getFile.write(ch);
// }
fget.close();
getFile.close();
fc.closeServer();
System.out.println("Downloaded picture success!");
bool = true;
}
catch (IOException ex) {
ex.printStackTrace();
return bool;
}
return bool;
}
private boolean ftpDownLoadPicture(String picName){
boolean bool = false;
String ext = "";
String fileName = "";
String serverName = "202.109.72.212";
String userName = "sofapopjpg11";
String passWord = "sofapopjpg200811";
try {
JFileChooser filechooser = new JFileChooser();
filechooser.setFileFilter(new PicFileFilter());
filechooser.setSelectedFile(new File(picName));
int returnVal = filechooser.showSaveDialog(this);
if(returnVal == filechooser.APPROVE_OPTION){
fileName = filechooser.getSelectedFile().getPath();
int in = fileName.lastIndexOf(".");
if(in>0&&in<fileName.length()-1){
ext = fileName.substring(in+1).toLowerCase();
}
}else return false;
if(ext.equals("")) fileName = fileName.substring(0,fileName.lastIndexOf(" //")+1)+picName;
FtpClient fc = new FtpClient(serverName);
fc.login(userName, passWord);
//fc.cd("test");
int ch;
//开始下载文件
System.out.println("Downloading picture:"+picName+" ... ...");
File file = new File(fileName);
if(file.exists()) file.delete();
RandomAccessFile getFile = new RandomAccessFile(file, "rw");
getFile.seek(0);
fc.binary();//取的是bin文件,所以在get前fc.binary();
TelnetInputStream fget = fc.get(picName);//fc.nameList("")文件列表
DataInputStream puts = new DataInputStream(fget);
byte bytes[] = new byte[10240];
while ( (ch = puts.read(bytes))!= -1) {
getFile.write(bytes,0,ch);
}
// while ( (ch = puts.read()) >= 0) {
// getFile.write(ch);
// }
fget.close();
getFile.close();
fc.closeServer();
System.out.println("Downloaded picture success!");
bool = true;
}
catch (IOException ex) {
ex.printStackTrace();
return bool;
}
return bool;
}