title: Upload Files Using SCP/SFTP or more secure way in Android
body: <p>How to Upload Files Using SCP protocol in Android.</p>
  
  <p>I don't have any idea. Please give me sample code or clear guidance.</p>
  
  <p>I made following code using FTP. Its working fine. but Client said that FTP is a less secure protocol. They told me that use SCP instead of FTP. Any way these are the codes. Please let me know how can I do this in secure way(SCP or any relevant method please explain).</p>
  
  <pre><code>private String sendImageToServer(final String folderName, final File image) {
  class FtpAsyncTask extends AsyncTask&lt;Void, Void, String&gt;{
  
      @Override
      protected String doInBackground(Void... params) {
          try{
  
              FTPClient connection = new FTPClient();
              connection.connect("192.244.110.86");
              boolean imageUploaded = false;
  
              if (connection.login("root","1pass6")) {
  
                  connection.setFileType(FTP.BINARY_FILE_TYPE);
                  connection.enterLocalPassiveMode();
  
                  byte[] imageInBytes = new byte[(int) image.length()];
                  try {
  
                      FileInputStream fileInputStream = new FileInputStream(
                              image);
                      fileInputStream.read(imageInBytes);
  
                      ByteArrayInputStream in = new ByteArrayInputStream(
                              imageInBytes);
  
                      boolean folderCreted = connection.makeDirectory(folderName);
  
                      if (folderCreted) {
                          System.out.println("folder created ");
                      } else {
                          System.out.println("folder not created ");
  
                      }
  
                      imageUploaded = connection.storeFile(folderName+"/"+image.getName()+".jpg", in);
  
                      System.out.println("Image sent "+imageUploaded);
                      in.close();
                      connection.logout();
                      connection.disconnect();
                      if (imageUploaded) {
                          System.out.println("imageUploaded success");
                          return "success";
                      } else {
                          System.out.println("imageUploaded fail");
                          return "fail";
                      }
                  } catch (Exception e) {
                      e.printStackTrace();
                      result = "fail";
  
                  }
  
              } else {
                  System.out.println("UNABLE TO LOG IN TO THE FTP");
              }
  
  
          }catch(Exception e){
              e.printStackTrace();
              return "fail";
          }
          return "fail";
      }
  
      @Override
      protected void onPostExecute(String result) {
          super.onPostExecute(result);
  
          System.out.println("onPostExecute "+result);
          if (result.equals(UPLOAD_SUCCESS)) {
              image.delete();
  
              System.out.println("UPLOAD_SUCCESS");
          } else if (result.equals(UPLOAD_FAIL)) {
              System.out.println("UPLOAD_FAIL");                  
  
          }
      }
  
  }
  
  FtpAsyncTask ftpAsyncTask = new FtpAsyncTask();
  ftpAsyncTask.execute();
  return result;
  }
  </code></pre>