Advertisement
Guest User

take this

a guest
Jan 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. import java.lang.System;
  2. import java.io.IOException;
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. //
  7. // This is an implementation of a simplified version of a command
  8. // line ftp client. The program always takes two arguments
  9. //
  10.  
  11.  
  12. public class CSftp {
  13.  
  14. public static void main(String [] args) {
  15.  
  16. // Get command line arguments and connected to FTP
  17. // If the arguments are invalid or there aren't enough of them
  18. // then exit.
  19.  
  20. if (!(args.length == 2 || args.length == 1)) {
  21. System.out.print("Usage: cmd ServerAddress ServerPort\n");
  22. return;
  23. }
  24.  
  25. int portNumber = 21;
  26. String hostName = args[0];
  27.  
  28. if (args.length == 2){
  29. portNumber = Integer.parseInt(args[1]);
  30. }
  31.  
  32. try
  33. // (Socket ftpSocket = new Socket(hostName, portNumber);
  34. // PrintWriter out = new PrintWriter(ftpSocket.getOutputStream(), true);
  35. // BufferedReader in = new BufferedReader(
  36. // new InputStreamReader(ftpSocket.getInputStream())); )
  37. {
  38. BufferedReader stdIn =
  39. new BufferedReader(new InputStreamReader(System.in));
  40. String fromServer;
  41. String fromUser;
  42.  
  43. System.out.println("Welcome! Please state user:");
  44.  
  45. while (true) {
  46. System.out.print("csftp> ");
  47. // Start processing the command here.
  48. fromUser = stdIn.readLine();
  49. if (fromUser!= null) {
  50. String[] splited = fromUser.split("\\s+");
  51. switch (splited[0]) {
  52. case "user":
  53. //out.println("USER user");
  54. break;
  55. case "pw":
  56. System.out.print("U WOT\n");
  57. break;
  58. case "quit":
  59. System.out.print("M8\n");
  60. break;
  61. case "get":
  62. System.out.print("dat\n");
  63. break;
  64. case "features":
  65. System.out.print("aint\n");
  66. break;
  67. case "cd":
  68. System.out.print("falco\n");
  69. break;
  70. case "dir":
  71. System.out.print("WHERE U AT\n");
  72. break;
  73. default:
  74. System.out.println("900 Invalid command.");
  75. }
  76.  
  77. }
  78. }
  79.  
  80. } catch (UnknownHostException e){
  81. System.err.println("Don't know about host " + hostName);
  82. System.exit(1);
  83. } catch (IOException exception) {
  84. System.err.println("998 Input error while reading commands, terminating.");
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement