Dilan1991

Untitled

Apr 13th, 2020
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. public boolean ftpReport(String srcFilePath, JSONObject object, Context context){
  2. try {
  3.  
  4.  
  5. FTPClient ftpClient = new FTPClient();
  6. ftpClient.connect(gb.getHostFTP(),gb.getPortFTP());
  7. Log.d("host11", "ftpReport: HOST "+gb.getHostFTP());
  8. Log.d("user11", "ftpReport: user "+gb.getUserFTP());
  9. Log.d("pw11", "ftpReport: Pw "+gb.getPwFTP());
  10. if(FTPReply.isPositiveCompletion(ftpClient.getReplyCode())){
  11. boolean status1 = ftpClient.login(gb.getUserFTP(),gb.getPwFTP());
  12. ftpClient.enterLocalPassiveMode();
  13. Log.d("Connectionsuccess", "ftpConnect: berhasil status = "+status1);
  14.  
  15. FileInputStream srcFileStream = new FileInputStream(srcFilePath);
  16. BufferedInputStream bis = new BufferedInputStream(srcFileStream);
  17.  
  18. Bitmap bmp = BitmapFactory.decodeStream(bis);
  19. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  20. bmp.compress(Bitmap.CompressFormat.JPEG,60,stream);
  21. InputStream iss = new ByteArrayInputStream(stream.toByteArray());
  22. BufferedInputStream bii = new BufferedInputStream(iss);
  23.  
  24. ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
  25. String ts = tsLong.toString();
  26. SharedPreferences pref = context.getSharedPreferences(String.valueOf(R.string.pref_main), MODE_PRIVATE);
  27. String guid = pref.getString(String.valueOf(R.string.guid_pref),null);
  28. Log.d("INI_Adalah String", "ftpReport: "+guid);
  29. boolean status = ftpClient.storeFile("/kehadiran/image/"+guid+ts+"-PPTIK.jpg",bii);
  30. if (status){
  31.  
  32. rmq.setupConnectionFactory();
  33. JSONObject obj = object;
  34. obj.put("MSG_TYPE",1);
  35. obj.put("CMD_TYPE",0);
  36. obj.put("TIMESTAMP",ts);
  37. obj.put("IMAGE","data/kehadiran/image/"+guid+ts+"-PPTIK.jpg");
  38. obj.put("GUID",guid);
  39. if (obj.getString("ADDRESS")==null){
  40. obj.put("ADDRESS","Unamed Address");
  41. }
  42.  
  43. Log.d("TAGJsonData", "ftpReport: "+obj.toString());
  44. rmq.publish(obj.toString());
  45.  
  46. }else{
  47.  
  48. }
  49. bis.close();
  50. ftpClient.disconnect();
  51.  
  52. return status;
  53. }
  54. } catch (SocketException e) {
  55. Log.d("FTP1", "Error: could not connect to socket " + e );
  56. } catch (IOException e) {
  57. Log.d("FTP2", "Error: could not connect to host " + e );
  58. } catch (JSONException e) {
  59. e.printStackTrace();
  60. Log.d("FTP3", "Error: could not connect to host " + e );
  61. } catch (NoSuchAlgorithmException e) {
  62. e.printStackTrace();
  63. } catch (URISyntaxException e) {
  64. e.printStackTrace();
  65. } catch (TimeoutException e) {
  66. e.printStackTrace();
  67. } catch (InterruptedException e) {
  68. e.printStackTrace();
  69. } catch (KeyManagementException e) {
  70. e.printStackTrace();
  71. }
  72. return false;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment