Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FileTransfer {
- Settings gb = new Settings();
- RMQ rmq = new RMQ();
- Long tsLong = System.currentTimeMillis()/1000;
- private static final String TAG = null;
- /**
- * Function register untuk menyimpan gambar ke ftp dan mengirimkan data ke RMQ
- * @param srcFilePath
- * @param Imei
- * @param nama
- * @param txtTelpText
- * @param kodeProv
- * @param context
- * @return
- */
- /**
- * Function Send Report dan menyimpan file gambar di FTP dan mengirim data ke RMQ
- * @param srcFilePath
- * @param comment
- * @param context
- * @param imei
- * @return
- */
- public boolean ftpReport(String srcFilePath, Editable comment,Editable nilai2, Context context,String imei){
- try {
- String komentar = String.valueOf(comment);
- String Nilai2 = String.valueOf(nilai2);
- FTPClient ftpClient = new FTPClient();
- ftpClient.connect(gb.getHostFTP());
- Log.d("host11", "ftpReport: HOST "+gb.getHostFTP());
- Log.d("user11", "ftpReport: user "+gb.getUserFTP());
- Log.d("pw11", "ftpReport: Pw "+gb.getPwFTP());
- if(FTPReply.isPositiveCompletion(ftpClient.getReplyCode())){
- boolean status1 = ftpClient.login(gb.getUserFTP(),gb.getPwFTP());
- ftpClient.enterLocalPassiveMode();
- Log.d("Connectionsuccess", "ftpConnect: berhasil status = "+status1);
- FileInputStream srcFileStream = new FileInputStream(srcFilePath);
- BufferedInputStream bis = new BufferedInputStream(srcFileStream);
- Bitmap bmp = BitmapFactory.decodeStream(bis);
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- bmp.compress(Bitmap.CompressFormat.JPEG,10,stream);
- InputStream iss = new ByteArrayInputStream(stream.toByteArray());
- BufferedInputStream bii = new BufferedInputStream(iss);
- ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
- String ts = tsLong.toString();
- boolean status = ftpClient.storeFile("Panwaslu/gambar/"+ts+".jpg",bii);
- rmq.setupConnectionFactory();
- ArrayList<String> list = new ArrayList<String>();
- list.add("Panwaslu/gambar/"+ts+".jpg");
- JSONObject obj = new JSONObject();
- obj.put("NILAI 1",komentar);
- obj.put("NILAI 2",Nilai2);
- obj.put("PATHIMAGE",list);
- Log.d("TAGJsonData", "ftpReport: "+obj.toString());
- rmq.setupConnectionFactory();
- rmq.publish(obj.toString());
- bis.close();
- return status;
- }
- } catch (SocketException e) {
- Log.d("FTP1", "Error: could not connect to socket " + e );
- } catch (IOException e) {
- Log.d("FTP2", "Error: could not connect to host " + e);
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- } catch (URISyntaxException e) {
- e.printStackTrace();
- } catch (TimeoutException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (KeyManagementException e) {
- e.printStackTrace();
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement