new Thread(){
@Override
public void run() {
try {
FTPClient ftpClient = new FTPClient();
FileInputStream fis;
ftpClient.setConnectTimeout(3000);
if(p.getString("ip2","") == "" || p.getString("port2","") == ""){
handler.sendEmptyMessage(CodeList.DATA_PARSING_FAILURE_4);
return;
}
ftpClient.connect(p.getString("ip2",""), Integer.parseInt(p.getString("port2","")));
boolean isLogin = ftpClient.login(p.getString("ftpuser",""), p.getString("ftppwd",""));
int replyCode = ftpClient.getReplyCode();
ftpClient.enterLocalPassiveMode();
if (isLogin && FTPReply.isPositiveCompletion(replyCode)) {
if(ftpClient.changeWorkingDirectory("/ypwj/"+ PowerBean.area_id+"/")){
}else{
ftpClient.makeDirectory("/ypwj/"+PowerBean.area_id+"/");
ftpClient.changeWorkingDirectory("/ypwj/"+PowerBean.area_id+"/");
}
File d = new File(path);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
fis = new FileInputStream(d);
String fn = new String(fileName.getBytes("GBK"),"iso-8859-1");
ftpClient.storeFile(fn, fis);
Log.v("ccc","成功");
ftpClient.logout();
ftpClient.disconnect();
handler.sendEmptyMessage(CodeList.UPLOAD_SUCCESS);
}else{
handler.sendEmptyMessage(CodeList.DATA_PARSING_FAILURE_5);
}
} catch (IOException e) {
handler.sendEmptyMessage(CodeList.DATA_PARSING_FAILURE_4);
e.printStackTrace();
}
}
}.start();
new Thread() {
@Override
public void run() {
try {
FTPClient ftpClient = new FTPClient();
FileInputStream fis;
ftpClient.setConnectTimeout(3000);
if (p.getString("ip2", "") == "" || p.getString("port2", "") == "") {
handler.sendEmptyMessage(CodeList.DATA_PARSING_FAILURE_4);
return;
}
ftpClient.connect(p.getString("ip2", ""), Integer.parseInt(p.getString("port2", "")));
boolean isLogin = ftpClient.login(p.getString("ftpuser", ""), p.getString("ftppwd", ""));
int replyCode = ftpClient.getReplyCode();
ftpClient.enterLocalPassiveMode();
if (isLogin && FTPReply.isPositiveCompletion(replyCode)) {
String p = arr.get(fileCurrent).getPath();
ftpClient.changeWorkingDirectory(p.substring(0, p.lastIndexOf("/") + 1));
ftpClient.setControlEncoding("GBK");
FTPFile[] ftpFiles = ftpClient.listFiles();
boolean flag = false;
for (FTPFile ftpFile : ftpFiles) {
if (ftpFile.getName().equals(arr.get(fileCurrent).getName())) {
ftpClient.enterLocalPassiveMode();
File f = new File(Environment.getExternalStorageDirectory(), "sounds");
File d = new File(f, arr.get(fileCurrent).getName());
OutputStream outputStream = new FileOutputStream(d);
flag = ftpClient.retrieveFile(new String(ftpFile.getName().getBytes("GB2312"), "ISO-8859-1"), outputStream);
outputStream.close();
flag = true;
break;
}
}
if (flag) {
handler.sendEmptyMessage(CodeList.FTP_DOWNLOAD_SUCCESS);
} else {
handler.sendEmptyMessage(CodeList.FTP_DOWNLOAD_ERROR);
}
} else {
handler.sendEmptyMessage(CodeList.DATA_PARSING_FAILURE_5);
}
} catch (IOException e) {
handler.sendEmptyMessage(CodeList.DATA_PARSING_FAILURE_4);
e.printStackTrace();
}
}
}.start();