title: my app works fine with wifi but gives exception on 2g ,3g
body: <p>It mainly happens when i am uploading images to server.i am using ftp file uploder to upload images.i have tried it with wifi its working absolutely fine. I am new to this senario .pls help .....</p>
  
  <p>My File uploder class :</p>
  
  <pre><code> public void uploadFile(Context context, File fileName) {
          FTPClient client = new FTPClient();
  
          try {
              flag = false;
              if (!client.isConnected()) {
               client.setSecurity(FTPClient.SECURITY_FTPES);
              // client.setSecurity(FTPClient.SECURITY_FTP);
                  try {
                      client.connect(FTP_HOST, 21);
                      client.setType(FTPClient.TYPE_BINARY);
                      SSLContext sc = SSLContext.getInstance("SSL");
                      sc.init(null, trustAllCerts, new java.security.SecureRandom());
                      client.setSSLSocketFactory(sc.getSocketFactory());
                      client.login(FTP_USER, FTP_PASS);
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  client.setType(FTPClient.TYPE_BINARY);
  
                  client.changeDirectory(UPLOAD_PATH);
                  client.upload(fileName);
                  flag = true;
              }
          } catch (Exception e) {
              e.printStackTrace();
              try {
                  client.disconnect(true);
              } catch (Exception e2) {
                  e2.printStackTrace();
              }
              flag = false;
          }
      }
  </code></pre>
  
  <p>My Async task :</p>
  
  <pre><code>  private class SellAsync extends AsyncTask&lt;String, String, String&gt;
      {
          final ProgressDialog progressDialog = new ProgressDialog(Sell_Main.this);
          long totalSize = 0;
  
          @Override
  
  
           protected String doInBackground(String... urls)
          {
              String msg = "";
              try
              {
  
                      for (int i = 0; i &lt; imageList.size(); i++)
                      {
                          File f = new File(imageList.get(i));
                          new FileUploader().uploadFile(Sell_Main.this, f);
  
                          if (!FileUploader.flag)
                          {
                              throw new Exception("File uploading failed");
                          }
                      }
  
  
                  ArrayList&lt;NameValuePair&gt; arr = new ArrayList&lt;NameValuePair&gt;();
                  arr.add(new BasicNameValuePair("brand", brand));
                  arr.add(new BasicNameValuePair("model", model));
                  arr.add(new BasicNameValuePair("variant", variant));
                  arr.add(new BasicNameValuePair("fuel_type", fuelspinner));
                  arr.add(new BasicNameValuePair("kilometres", km));
                  arr.add(new BasicNameValuePair("transmission", trans));
                  arr.add(new BasicNameValuePair("make_year", makeyear));
                  arr.add(new BasicNameValuePair("Expected_price", price));
                  arr.add(new BasicNameValuePair("ownership", owner));
                  arr.add(new BasicNameValuePair("location", location));
                  arr.add(new BasicNameValuePair("cid", sPref.getString("id", "")));
  
                  String imagesList = "";
                  for (int i = 0; i &lt; imageList.size(); i++) {
                      File f = new File(imageList.get(i));
                      imagesList += f.getName() + ",";
                  }
                  arr.add(new BasicNameValuePair("images", imagesList.substring(0, imagesList.length() - 1)));
  
                  HttpParams httpParameters = new BasicHttpParams();
  // Set the timeout in milliseconds until a connection is established.
  // The default value is zero, that means the timeout is not used.
                  int timeoutConnection = 15000;
                  HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
  // Set the default socket timeout (SO_TIMEOUT)
  // in milliseconds which is the timeout for waiting for data.
                  int timeoutSocket = 30000;
                  HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
  
  
                  HttpClient client = new DefaultHttpClient(httpParameters);
  
                  HttpPost post = new HttpPost(urls[0]);
  
                  post.setEntity(new UrlEncodedFormEntity(arr));
  
                  HttpResponse response = client.execute(post);
  
                  msg = EntityUtils.toString(response.getEntity());
  
              } catch (Exception e) {
                  msg = e.getMessage();
              }
              return msg;
          }
  
  
  
          @Override
          protected void onPreExecute()
          {
              progressDialog.setMessage("Uploading...it may take some time.");
              progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
              progressDialog.show();
              progressDialog.setCancelable(false);
              progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                  @Override
                  public void onDismiss(DialogInterface dialog) {
                      cancel(true);
                  }
              });
              super.onPreExecute();
          }
  
          @Override
          protected void onPostExecute(String s)
          {
              super.onPostExecute(s);
              progressDialog.dismiss();
              if (s.equalsIgnoreCase("inserted successfully"))
              {
                  Toast.makeText(getApplicationContext(), "Details Submitted successfully,will revert you back soon..", Toast.LENGTH_LONG).show();
                  finish();
              }
              else if(s.equalsIgnoreCase("File uploading failed"))
              {
                  Toast.makeText(getApplicationContext(), "Please check your internet connection", Toast.LENGTH_LONG).show();
              }
          }
      }
  </code></pre>