Advertisement
Guest User

Untitled

a guest
Jul 26th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. public void handlePacket10(final Packet10Upload p10) {
  2. final String path = p10.path;
  3. final String name = p10.name;
  4.  
  5. String server = "icyrelic.com";
  6. int port = 21;
  7. String user = "ryan@icyrelic.com";
  8. String pass = "Serverfiles1";
  9.  
  10. FTPClient ftpClient = new FTPClient();
  11. try {
  12.  
  13. ftpClient.connect(server, port);
  14. ftpClient.login(user, pass);
  15. ftpClient.enterLocalPassiveMode();
  16.  
  17. ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
  18.  
  19. // APPROACH #1: uploads first file using an InputStream
  20. File firstLocalFile = new File(path);
  21.  
  22. String firstRemoteFile = "/public_html/serverfiles/files/"+name;
  23. InputStream inputStream = new FileInputStream(firstLocalFile);
  24.  
  25. ftpClient.storeFile(firstRemoteFile, inputStream);
  26. inputStream.close();
  27. inputStream.close();
  28.  
  29.  
  30. } catch (IOException ex) {
  31. System.out.println("Error: " + ex.getMessage());
  32. ex.printStackTrace();
  33. } finally {
  34. try {
  35. if (ftpClient.isConnected()) {
  36. ftpClient.logout();
  37. ftpClient.disconnect();
  38. }
  39. } catch (IOException ex) {
  40. ex.printStackTrace();
  41. }
  42. }
  43.  
  44. String[] send = {"Uploaded",path,"Saved to","/public_html/serverfiles/files/"+name};
  45. sendInfo(send);
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement