private void doConnectToServer() { String strDataType = "ftp"; try { objConnectOptions = objOptions.getConnectionOptions().Source(); VFSFactory.setConnectionOptions(objConnectOptions); objVFS4Handler = VFSFactory.getHandler(strDataType); objDataClient = (ISOSVfsFileTransfer) objVFS4Handler; } catch (Exception e) { e.printStackTrace(); } }
@Override public void run() { logger.setLevel(Level.DEBUG); objConnectOptions = objOptions.getConnectionOptions().Source(); Vector<String> objA = new Vector<String>(); BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in)); try { while (true) { System.out.println("give command:\n"); String strCommand; strCommand = bufferRead.readLine(); if (strCommand == null || strCommand.length() <= 0) { break; } String[] strCmdParams = strCommand.split(" "); switch (strCmdParams[0]) { case "open": /* * Connects to the specified FTP server. Syntax: open computer [port] Parameter(s): computer - Specifies the remote computer to connect to. Computer can be specified by IP address or computer name (a DNS or HOSTS file must be available). If auto-login is on (default), FTP also attempts to automatically log the user in to the FTP server (see Ftp command-line options to disable auto-login). port - Specifies a port number to use to contact an FTP server. */ String strHost = strCmdParams[1]; objConnectOptions.protocol.Value(enuTransferTypes.ftp); objConnectOptions.host.Value(strHost); logger.debug("try to connect to host " + strHost); doConnectToServer(); logger.info("connected"); break; case "user": doAuthenticate(); break; case "quit": case "close": case "bye": closeConnection(); System.out.println("bye, bye ..."); break; case "recv": case "get": /* * Copies a remote file to the local computer using the current file transfer type. See also mget, which can copy multiple files. Syntax: get remote-file [local-file] Parameter(s): remote-file Specifies the remote file to copy. local-file Specifies the name to use on the local computer. If not specified, the file is given the remote-file name. */ break; case "send": case "put": /* * Copies a local file to the remote computer using the current file transfer type. See also mput, which can copy multiple files. Syntax: put local-file [remote-file] Parameter(s): local-file - Specifies the local file to copy. remote-file - Specifies the name to use on the remote computer. If not specified, the file is given the local-file name. */ break; case "chdir": break; case "pwd": /* * Displays the current directory on the remote computer. Syntax: pwd */ break; default: break; } objA.add(strCommand); } } catch (IOException e) { e.printStackTrace(); } }