Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class ServerP
  5. {
  6. public static void main(String args[]) throws Exception
  7. {
  8. ServerSocket soc=new ServerSocket(6661, 1);
  9. System.out.println("Server started (6661)");
  10.  
  11. {
  12. System.out.println("Waiting...");
  13. soc.accept();
  14. System.out.println("Connection accepted");
  15. }
  16. }
  17. }
  18.  
  19. import java.io.BufferedOutputStream;
  20. import java.io.File;
  21. import java.io.FileInputStream;
  22. import java.io.FileOutputStream;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.io.OutputStream;
  26. import org.apache.commons.net.ftp.FTP;
  27. import org.apache.commons.net.ftp.FTPClient;
  28.  
  29. public class RapsodiaClient {
  30.  
  31. public static void main(String[] args) {
  32. String server = "127.0.0.1";
  33. int port = 6667;
  34. String user = "user";
  35. String pass = "pass";
  36.  
  37. FTPClient ftpClient = new FTPClient();
  38. try {
  39. System.out.println("Checkpoint 1");
  40. ftpClient.connect(server, 6661);
  41. System.out.println("Checkpoint 2");
  42. ftpClient.login(user, pass);
  43. ftpClient.enterLocalPassiveMode();
  44. ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
  45. System.out.println("Checkpoint 3");
  46. // APPROACH #1: using retrieveFile(String, OutputStream)
  47. String remoteFile1 = "C://Users//C92//Desktop//VV.wav";
  48. File downloadFile1 = new File("C://Users//C92//Desktop//output.wav");
  49. OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
  50. System.out.println("Checkpoint 4");
  51. boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
  52. System.out.println("Checkpoint 5");
  53. outputStream1.close();
  54. System.out.println("Checkpoint 6");
  55. if (success) {
  56. System.out.println("File #1 has been downloaded successfully.");
  57. }
  58.  
  59. } catch (IOException ex) {
  60. System.out.println("Error: " + ex.getMessage());
  61. ex.printStackTrace();
  62. } finally {
  63. try {
  64. if (ftpClient.isConnected()) {
  65. ftpClient.logout();
  66. ftpClient.disconnect();
  67. }
  68. } catch (IOException ex) {
  69. ex.printStackTrace();
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement