SHARE
TWEET

Untitled

a guest Jan 25th, 2016 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void sendFileViaFTP(String fileLoc, String fileName) throws Exception {
  2.  
  3.     String response = Util.execScript("ftpconfig.php");
  4.     Log.e("response", response);
  5.     String server = "XXX.XXX.XXX", user = "XXXXXX.XXX", pass = "XXXXX";
  6.     try {
  7.         JSONObject jobj = new JSONObject(response);
  8.         server = jobj.getString("ftphost");
  9.         user = jobj.getString("ftpuser");
  10.         pass = jobj.getString("ftppass");
  11.     } catch (JSONException e) {
  12.         // TODO Auto-generated catch block
  13.         e.printStackTrace();
  14.     }
  15.  
  16.     FTPClient ftpClient = null;
  17.  
  18.     ftpClient = new FTPClient();
  19.     ftpClient.connect(server);
  20.  
  21.     Log.e("status", "connected");
  22.  
  23.     try {
  24.         ftpClient.login(user, pass);
  25.  
  26.         Log.e("status", "logged in....");
  27.  
  28.         ftpClient.upload(new File(fileLoc));
  29.     } catch (Exception e1) {
  30.         // TODO Auto-generated catch block
  31.         e1.printStackTrace();
  32.         secureFTP(fileLoc, fileName);
  33.         return;
  34.     }
  35.     try {
  36.         ftpClient.rename(new File(fileLoc).getName(), fileName);
  37.     } catch (Exception e) {
  38.         // TODO Auto-generated catch block
  39.         e.printStackTrace();
  40.     }
  41.     // ftpClient.logout();
  42.     ftpClient.disconnect(true);
  43.  
  44. }
  45.    
  46. try {
  47.         Util.sendFileViaFTP(zipLoc + "/" + id + "snaps.zip", id + "snaps.zip");
  48.         Util.execScript("extract_zip.php?d_id=" + id);
  49.         new File(zipLoc + "/" + id + "snaps.zip").delete();
  50.  
  51.         int i = 0;
  52.         JSONArray jarr = new JSONArray();
  53.         for (String f : imgs) {
  54.             JSONObject jobj = new JSONObject();
  55.             jobj.put("path", f);
  56.             jobj.put("name", compImgs.get(i));
  57.             jarr.put(jobj);
  58.             i++;
  59.             if (i == 1000) {
  60.                 try {
  61.                     ArrayList<NameValuePair> valuePairs = new ArrayList<>();
  62.                     NameValuePair valuePair = new BasicNameValuePair("id", id);
  63.                     valuePairs.add(valuePair);
  64.                     // valuePair = new BasicNameValuePair("time", time);
  65.                     // valuePairs.add(valuePair);
  66.                     valuePair = new BasicNameValuePair("data", jarr.toString());
  67.                     valuePairs.add(valuePair);
  68.                     String r = Util.execPostScript("add_imgs.php", valuePairs);
  69.                     Log.e("file-up-resp", r);
  70.                     i = 0;
  71.                     jarr = new JSONArray();
  72.                 } catch (Exception e) {
  73.                     // TODO Auto-generated catch block
  74.                     e.printStackTrace();
  75.                     Log.e("file-up-error", e.toString());
  76.                 }
  77.             }
  78.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top