Advertisement
Guest User

Untitled

a guest
May 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public static boolean upload(String url, String username, String password, File file) {
  2. FTPClient client = new FTPClient();
  3. FileInputStream fis = null;
  4.  
  5. try {
  6. client.connect(url);
  7. client.login(username, password);
  8.  
  9. fis = new FileInputStream(file);
  10.  
  11. // Store file on server and logout
  12. boolean uploaded = client.storeFile(file.getName(), fis);
  13.  
  14. client.logout();
  15.  
  16. return uploaded;
  17. } catch (IOException e) {
  18. e.printStackTrace();
  19. } finally {
  20. try {
  21. if (fis != null) {
  22. fis.close();
  23. }
  24. client.disconnect();
  25. } catch (IOException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29.  
  30. return false;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement