Guest User

Untitled

a guest
Jan 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. private class FTPUploader extends AsyncTask<URL, Integer, Long> {
  2.  
  3.  
  4. protected Long doInBackground(URL... urls) {
  5. String data = "/pathimage/filename.jpg";
  6. File sourceFile = new File(data);
  7. FTPClient con = new FTPClient();
  8. try {
  9.  
  10. con.connect("ftp.ftpServer.it", 21);
  11.  
  12. if (con.login("user", "password")) {
  13. con.setFileType(FTP.BINARY_FILE_TYPE);
  14. con.enterLocalPassiveMode();
  15.  
  16.  
  17. if (sourceFile.exists()) {
  18. InputStream input = new FileInputStream(sourceFile);
  19.  
  20.  
  21. boolean result = con.storeFile("/folder/newfilename.jpg", input);
  22. input.close();
  23. if (result) {
  24. System.out.println(result);
  25. }
  26. }
  27. }
  28. } catch (Exception e) {
  29. e.printStackTrace();
  30. }
  31.  
  32. try {
  33. if (sourceFile.exists()) {
  34. con.logout();
  35. con.disconnect();
  36. }
  37. } catch (IOException e) {
  38. e.printStackTrace();
  39. }
  40.  
  41. return null;
  42. }
  43. }
Add Comment
Please, Sign In to add comment