用ftpclient.retrieveFile()方法,不过得到的是文件大小为0的文件,到底是什么原因?大虾们救救啊!
这是我的代码:
class DownloadThread implements Runnable{
private int port=21;
private String server="nd.epapp.cn";
private String username = "";
private String password = "";
private String localPath;
private String remotePath;
private String loginmail="";
private String domain="";

public DownloadThread(String username,String password,String 
localPath,String remotePath,String loginmail,String domain){
this.username = username;
this.password = password;
this.localPath = localPath;
this.remotePath = remotePath;
this.loginmail = loginmail;
this.domain = domain;
} public void run() { FileOutputStream fileoutput = null;
try {

if (!ftp.isConnected()) {
try {
// ftp.connect("nd.epapp.cn", 21);
ftp.connect(server, port);
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
// Message m1 = new Message();
// m1.what = 1;
// FtpLoad.this.handler.sendMessage(m1); } else {
ftp.login(username, password);
ftp.enterLocalPassiveMode(); // 被动模式
// ftp.setSoTimeout(10);
// ftp.enterLocalActiveMode();
ftp.setFileType(FTP.BINARY_FILE_TYPE);

}



} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// Message m1 = new Message();
// m1.what = 1;
// FtpLoad.this.handler.sendMessage(m1); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } else {

}

FTPFile[] files = null;
try {
files = ftp.listFiles("/");
String statusphone = "";
String statuspicture = "";
String ff = "";
for (int i = 0; i < files.length; i++) {
if (files[i].getName().equals("Phone")) {
statusphone = "phone";
}
if (files[i].getName().equals("Picture")) {
statuspicture = "picture";
}
}
if (statusphone.equals("")) {
ftp.makeDirectory("Phone");
ff = "1";
}
if (statuspicture.equals("")) {
ftp.makeDirectory("Picture");
ff = "1";
}
if (ff.equals("1")) {
files = ftp.listFiles("/");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.e("ftPclient", ftp.isConnected() + "---" + files.length);
fileoutput = new FileOutputStream(new File(localPath));
Notification notification = new Notification();
notification.icon = com.android.dropbox.R.drawable.icon;
Intent intent = new Intent();
intent.setClass(DownloadService.this, DesActivity.class);
intent.putExtra("notificationId", notificationId);
PendingIntent pendingIntent = PendingIntent.getActivity(DownloadService.this, 0, intent, 0);
if (ftp.retrieveFile(remotePath,fileoutput)) {
LogUpLoad.getUpInfo(loginmail,domain,"Download", "AndroidDownloadOneFile:"+remotePath, "1");
String msg = "下载完成";
notification.tickerText = msg;
notification.setLatestEventInfo(DownloadService.this, 
"文件下载", "下载完成通知",  pendingIntent);
intent.putExtra("dialog_msg", msg);
Log.e("notifi", "had done");
}else{
String msg = "出错啦";
notification.tickerText = msg;
notification.setLatestEventInfo(DownloadService.this, 
"文件下载", "出错通知",  pendingIntent);
intent.putExtra("dialog_msg", msg);
Log.e("notifi", "has wrong");
}
notificationManager.notify(notificationId ++, notification);
fileoutput
.close(); } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

}

}