2016-10-22 18:52:14 +02:00
|
|
|
package de.mas.wupclient;
|
|
|
|
import java.io.IOException;
|
2016-11-10 23:39:18 +01:00
|
|
|
import java.util.Scanner;
|
2016-10-23 15:34:57 +02:00
|
|
|
|
|
|
|
import de.mas.wupclient.client.WUPClient;
|
2016-10-24 00:49:25 +02:00
|
|
|
import de.mas.wupclient.client.operations.DownloadUploadOperations;
|
2016-11-10 23:39:18 +01:00
|
|
|
import de.mas.wupclient.client.operations.SpecialOperations;
|
2016-10-23 15:34:57 +02:00
|
|
|
import de.mas.wupclient.client.operations.UtilOperations;
|
2016-10-22 18:52:14 +02:00
|
|
|
|
|
|
|
public class Starter {
|
2016-10-23 23:09:51 +02:00
|
|
|
public static void main(String args[]){
|
|
|
|
String ip = "192.168.0.35";
|
|
|
|
if(args.length > 0){
|
|
|
|
ip = args[0];
|
|
|
|
}
|
|
|
|
WUPClient w = new WUPClient(ip);
|
2016-11-10 23:39:18 +01:00
|
|
|
try {
|
|
|
|
boolean exit = false;
|
|
|
|
|
|
|
|
System.out.println("JWUPClient. Please enter a command. Enter \"exit\" to exit.");
|
|
|
|
System.out.println();
|
|
|
|
System.out.print(w.getCwd() + " > ");
|
|
|
|
Scanner reader = new Scanner(System.in); // Reading from System.in
|
|
|
|
while(!exit){
|
|
|
|
|
|
|
|
String input = reader.nextLine();
|
|
|
|
if(input.equals("exit")){
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
processCommand(input,w);
|
|
|
|
System.out.println();
|
|
|
|
System.out.print(w.getCwd() + " > ");
|
|
|
|
}
|
|
|
|
reader.close();
|
2016-10-22 18:52:14 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2016-10-23 23:09:51 +02:00
|
|
|
}finally {
|
|
|
|
try {
|
|
|
|
w.FSA_Close(w.get_fsa_handle());
|
2016-11-10 23:39:18 +01:00
|
|
|
} catch (IOException e) {
|
2016-10-23 15:34:57 +02:00
|
|
|
}
|
2016-10-23 23:09:51 +02:00
|
|
|
w.closeSocket();
|
2016-10-23 15:34:57 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-10 23:39:18 +01:00
|
|
|
|
|
|
|
private static void processCommand(String input,WUPClient w) throws IOException {
|
|
|
|
if(input == null || input.isEmpty()){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UtilOperations util = UtilOperations.UtilOperationsFactory(w);
|
|
|
|
SpecialOperations special = SpecialOperations.SpecialOperationsFactory(w);
|
|
|
|
DownloadUploadOperations dlul = DownloadUploadOperations.DownloadUploadOperationsFactory(w);
|
|
|
|
String[] inputs = input.split(" ");
|
|
|
|
switch(inputs[0]){
|
|
|
|
case "ls":
|
|
|
|
if(inputs.length > 1){
|
|
|
|
util.ls(inputs[1]);
|
|
|
|
}else{
|
|
|
|
util.ls();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "lsr":
|
|
|
|
util.lsRecursive();
|
|
|
|
break;
|
|
|
|
case "sysdump":
|
|
|
|
util.dump_syslog();
|
|
|
|
break;
|
|
|
|
case "cd":
|
|
|
|
if(inputs.length > 1){
|
|
|
|
util.cd(inputs[1]);
|
|
|
|
}else{
|
|
|
|
util.cd();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "dldir":
|
|
|
|
String destination = null;
|
|
|
|
String source = w.getCwd();
|
|
|
|
boolean fullpath = false;
|
|
|
|
if(inputs.length > 1){
|
|
|
|
for(int i = 1;i < inputs.length;i++){
|
|
|
|
if(inputs[i].equals("-dst")){
|
|
|
|
if(inputs.length >= i+1){
|
|
|
|
destination = inputs[i+1];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}else if(inputs[i].equals("-src")){
|
|
|
|
if(inputs.length >= i+1){
|
|
|
|
source = inputs[i+1];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}else if(inputs[i].equals("-fullpath")){
|
|
|
|
fullpath = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dlul.downloadFolder(source,destination,fullpath);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "dl":
|
|
|
|
if(inputs.length == 2){
|
|
|
|
dlul.downloadFile("", inputs[1]);
|
|
|
|
}else if(inputs.length == 3){
|
|
|
|
dlul.downloadFile("", inputs[1], inputs[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "dlfp": //download to full path
|
|
|
|
if(inputs.length == 2){
|
|
|
|
dlul.downloadFile("", inputs[1],w.getCwd());
|
|
|
|
}else if(inputs.length == 3){
|
|
|
|
dlul.downloadFile("", inputs[1],inputs[2] + "/" + w.getCwd());
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "nandtickets": //download to full path
|
|
|
|
special.parseAndDownloadTickets();
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
System.out.println("Command not found!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-10-22 18:52:14 +02:00
|
|
|
}
|