|
private final String directoryRoot = "PU_";
public boolean ConnectNRU() {
mConnect = false;
deviceId = mpu.getServerParam().iDeviceID;
deviceString = String.format("%08X", deviceId);
// 尝试连接三次
for (int i = 0; i < 3; i++) {
try {
mFtp4j.connect(bvpu_FtpInfo.szAddr, bvpu_FtpInfo.iPort);
mFtp4j.login(bvpu_FtpInfo.szUserName, bvpu_FtpInfo.szPassword);
try {
mFtp4j.createDirectory(directoryRoot
+ String.format("%08X", deviceId));
} catch (Exception e) {
}
mFtp4j.changeDirectory(directoryRoot
+ String.format("%08X", deviceId));
mConnect = true;
} catch (Exception e) {
Log.e(TAG, "连接失败---->" + e.toString());
if (mOnResultHandler != null && i == 2) {
if (mTaskType == TASK_TYPE_DOWNLOAD) {
mOnResultHandler
.onDownloadResult(mTaskToken, 400, null);
} else if (mTaskType == TASK_TYPE_UPLOAD) {
mOnResultHandler.onUploadResult(mTaskToken, 400, null,
null);
}
}
}
if (mConnect) {
break;
}
}
return mConnect;
}
|
|