String directory = args[4];
String mode = args[5];
String connMode = args[6];
// connect and test supplying port no.
FTPClient ftp = new FTPClient();
ftp.setControlEncoding("UTF-8");
ftp.setRemoteHost(host);
ftp.setRemotePort(21);
ftp.connect();
ftp.login(user, password);
ftp.quote("LANG da-DK", new String[] { "200" });
// ftp.dirDetails(".");
ftp.chdir("test");
ftp.quit();
if (true)
return;
// connect again
ftp = new FTPClient();
ftp.setRemoteHost(host);
ftp.login(user, password);
ftp.dir(".", false);
// binary transfer
if (mode.equalsIgnoreCase("BINARY")) {
ftp.setType(FTPTransferType.BINARY);
}
else if (mode.equalsIgnoreCase("ASCII")) {
ftp.setType(FTPTransferType.ASCII);
}
else {
System.out.println("Unknown transfer type: " + args[5]);
System.exit(-1);
}
// PASV or active?
if (connMode.equalsIgnoreCase("PASV")) {
ftp.setConnectMode(FTPConnectMode.PASV);
}
else if (connMode.equalsIgnoreCase("ACTIVE")) {
ftp.setConnectMode(FTPConnectMode.ACTIVE);
}
else {
System.out.println("Unknown connect mode: " + args[6]);
System.exit(-1);
}
// change dir
ftp.chdir(directory);
// put a local file to remote host
ftp.put(filename, filename);
// get bytes
byte[] buf = ftp.get(filename);
System.out.println("Got " + buf.length + " bytes");
// append local file
try {
ftp.put(filename, filename, true);
}
catch (FTPException ex) {
System.out.println("Append failed: " + ex.getMessage());
}
// get bytes again - should be 2 x
buf = ftp.get(filename);
System.out.println("Got " + buf.length + " bytes");
// rename
ftp.rename(filename, filename + ".new");
// get a remote file - the renamed one
ftp.get(filename + ".tst", filename + ".new");
// ASCII transfer
ftp.setType(FTPTransferType.ASCII);
// test that list() works
String[] listing = ftp.dir(".");
for (int i=0; i<listing.length; i++)
System.out.println(listing[i]);
// test that dir() works in full mode
String[] listings = ftp.dir(".", true);
for (int i = 0; i < listings.length; i++)
System.out.println(listings[i]);
// try system()
System.out.println(ftp.system());
// try pwd()
System.out.println(ftp.pwd());
ftp.quit();
}
catch (Exception ex) {
System.out.println("Caught exception: " + ex.getMessage());
}
}