Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.System;
- import java.io.IOException;
- import java.io.*;
- import java.net.*;
- //
- // This is an implementation of a simplified version of a command
- // line ftp client. The program always takes two arguments
- //
- public class CSftp {
- public static void main(String [] args) {
- // Get command line arguments and connected to FTP
- // If the arguments are invalid or there aren't enough of them
- // then exit.
- if (!(args.length == 2 || args.length == 1)) {
- System.out.print("Usage: cmd ServerAddress ServerPort\n");
- return;
- }
- int portNumber = 21;
- String hostName = args[0];
- if (args.length == 2){
- portNumber = Integer.parseInt(args[1]);
- }
- try
- // (Socket ftpSocket = new Socket(hostName, portNumber);
- // PrintWriter out = new PrintWriter(ftpSocket.getOutputStream(), true);
- // BufferedReader in = new BufferedReader(
- // new InputStreamReader(ftpSocket.getInputStream())); )
- {
- BufferedReader stdIn =
- new BufferedReader(new InputStreamReader(System.in));
- String fromServer;
- String fromUser;
- System.out.println("Welcome! Please state user:");
- while (true) {
- System.out.print("csftp> ");
- // Start processing the command here.
- fromUser = stdIn.readLine();
- if (fromUser!= null) {
- String[] splited = fromUser.split("\\s+");
- switch (splited[0]) {
- case "user":
- //out.println("USER user");
- break;
- case "pw":
- System.out.print("U WOT\n");
- break;
- case "quit":
- System.out.print("M8\n");
- break;
- case "get":
- System.out.print("dat\n");
- break;
- case "features":
- System.out.print("aint\n");
- break;
- case "cd":
- System.out.print("falco\n");
- break;
- case "dir":
- System.out.print("WHERE U AT\n");
- break;
- default:
- System.out.println("900 Invalid command.");
- }
- }
- }
- } catch (UnknownHostException e){
- System.err.println("Don't know about host " + hostName);
- System.exit(1);
- } catch (IOException exception) {
- System.err.println("998 Input error while reading commands, terminating.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement