| 316 | } |
| 317 | |
| 318 | public void exists(JSONArray args, CallbackContext callback) { |
| 319 | cordova |
| 320 | .getThreadPool() |
| 321 | .execute( |
| 322 | new Runnable() { |
| 323 | public void run() { |
| 324 | String ftpId = args.optString(0); |
| 325 | String path = args.optString(1); |
| 326 | try { |
| 327 | if (ftpId == null || ftpId.isEmpty()) { |
| 328 | callback.error("FTP ID is required."); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | if (path == null || path.isEmpty()) { |
| 333 | path = "/"; |
| 334 | } |
| 335 | |
| 336 | FTPClient ftp = ftpProfiles.get(ftpId); |
| 337 | if (ftp == null) { |
| 338 | callback.error("FTP client not found."); |
| 339 | return; |
| 340 | } |
| 341 | |
| 342 | // check if file or directory exists |
| 343 | FTPFile[] ftpFiles = ftp.listFiles(path); |
| 344 | if (ftpFiles.length > 0) { |
| 345 | callback.success(1); |
| 346 | } else { |
| 347 | callback.success(0); |
| 348 | } |
| 349 | } catch (ParserInitializationException e) { |
| 350 | Log.e("FTP", "FTPClient (" + ftpId + ") path: " + path, e); |
| 351 | callback.error(e.getMessage()); |
| 352 | Log.e("FTP", "FTPClient (" + ftpId + ") path: " + path, e); |
| 353 | } catch (FTPConnectionClosedException e) { |
| 354 | Log.e("FTP", "FTPClient (" + ftpId + ") path: " + path, e); |
| 355 | callback.error(e.getMessage()); |
| 356 | } catch (IOException e) { |
| 357 | Log.e("FTP", "FTPClient (" + ftpId + ") path: " + path, e); |
| 358 | callback.error(e.getMessage()); |
| 359 | } catch (Exception e) { |
| 360 | Log.e("FTP", "FTPClient (" + ftpId + ") path: " + path, e); |
| 361 | callback.error(e.getMessage()); |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | ); |
| 366 | } |
| 367 | |
| 368 | public void sendNoOp(JSONArray args, CallbackContext callback) { |
| 369 | cordova |