diff --git a/src/main/java/org/waarp/ftp/client/Version.java b/src/main/java/org/waarp/ftp/client/Version.java
index 6546967..5d36164 100644
--- a/src/main/java/org/waarp/ftp/client/Version.java
+++ b/src/main/java/org/waarp/ftp/client/Version.java
@@ -3,7 +3,7 @@
/** Provides the version information of Waarp OpenR66. */
public final class Version {
/** The version identifier. */
- public static final String ID = "3.0.7";
+ public static final String ID = "3.1.0";
/** Prints out the version identifier to stdout. */
public static void main(String[] args) { System.out.println(ID); }
private Version() { super(); }
diff --git a/src/main/java/org/waarp/ftp/client/WaarpFtp4jClient.java b/src/main/java/org/waarp/ftp/client/WaarpFtp4jClient.java
index d13a5a0..0d77324 100644
--- a/src/main/java/org/waarp/ftp/client/WaarpFtp4jClient.java
+++ b/src/main/java/org/waarp/ftp/client/WaarpFtp4jClient.java
@@ -545,6 +545,35 @@ public boolean featureEnabled(String feature) {
}
}
+ /**
+ * @param remote
+ *
+ * @return True if deleted
+ */
+ public boolean deleteFile(String remote) {
+ try {
+ logger.debug("DELE {}", remote);
+ ftpClient.deleteFile(remote);
+ return true;
+ } catch (IOException e) {
+ result = "Cannot execute operation Site";
+ logger.error(result, e);
+ return false;
+ } catch (IllegalStateException e) {
+ result = "Cannot execute operation Site";
+ logger.error(result, e);
+ return false;
+ } catch (FTPIllegalReplyException e) {
+ result = "Cannot execute operation Site";
+ logger.error(result, e);
+ return false;
+ } catch (FTPException e) {
+ result = "Cannot execute operation Site";
+ logger.error(result, e);
+ return false;
+ }
+ }
+
/**
*
* @param params
diff --git a/src/main/java/org/waarp/ftp/client/WaarpFtpClient.java b/src/main/java/org/waarp/ftp/client/WaarpFtpClient.java
index f39bdd0..b0cb144 100644
--- a/src/main/java/org/waarp/ftp/client/WaarpFtpClient.java
+++ b/src/main/java/org/waarp/ftp/client/WaarpFtpClient.java
@@ -311,11 +311,6 @@ public boolean transferFile(String local, String remote, int getStoreOrAppend) {
logger.error(result);
return false;
}
- if (!this.ftpClient.completePendingCommand()) {
- result = "Cannot finalize store like operation";
- logger.error(result);
- return false;
- }
return true;
} else {
output = new FileOutputStream(new File(local, remote));
@@ -328,11 +323,6 @@ public boolean transferFile(String local, String remote, int getStoreOrAppend) {
logger.error(result);
return false;
}
- if (!this.ftpClient.completePendingCommand()) {
- result = "Cannot finalize retrieve like operation";
- logger.error(result);
- return false;
- }
return true;
}
} catch (IOException e) {
diff --git a/src/test/java/.gitkeep b/src/test/java/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/src/test/java/org/waarp/ftp/FtpServer.java b/src/test/java/org/waarp/ftp/FtpServer.java
new file mode 100644
index 0000000..2006e60
--- /dev/null
+++ b/src/test/java/org/waarp/ftp/FtpServer.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * This file is part of Waarp Project (named also Waarp or GG).
+ *
+ * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
+ * tags. See the COPYRIGHT.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * All Waarp Project is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * Waarp . If not, see .
+ ******************************************************************************/
+
+package org.waarp.ftp;
+
+import org.waarp.common.file.FileUtils;
+import org.waarp.common.file.filesystembased.FilesystemBasedFileParameterImpl;
+import org.waarp.common.logging.WaarpLogger;
+import org.waarp.common.logging.WaarpLoggerFactory;
+import org.waarp.common.logging.WaarpSlf4JLoggerFactory;
+import org.waarp.ftp.core.exception.FtpNoConnectionException;
+import org.waarp.ftp.simpleimpl.SimpleGatewayFtpServer;
+import org.waarp.ftp.simpleimpl.config.FileBasedConfiguration;
+import org.waarp.ftp.simpleimpl.control.SimpleBusinessHandler;
+import org.waarp.ftp.simpleimpl.data.FileSystemBasedDataBusinessHandler;
+
+import java.io.File;
+
+public class FtpServer {
+ /**
+ * Internal Logger
+ */
+ protected static WaarpLogger logger;
+ protected static File dir;
+ protected static FileBasedConfiguration configuration;
+
+ public static void startFtpServer(String config) {
+ WaarpLoggerFactory.setDefaultFactory(new WaarpSlf4JLoggerFactory(null));
+ if (logger == null) {
+ logger = WaarpLoggerFactory.getLogger(FtpServer.class);
+ }
+ ClassLoader classLoader = FtpServer.class.getClassLoader();
+ File file = new File(classLoader.getResource(config).getFile());
+ if (file.exists()) {
+ dir = file.getParentFile();
+ File base = new File("/tmp/GGFTP");
+ base.mkdir();
+ FileUtils.forceDeleteRecursiveDir(base);
+ configuration = new FileBasedConfiguration(
+ SimpleGatewayFtpServer.class, SimpleBusinessHandler.class,
+ FileSystemBasedDataBusinessHandler.class,
+ new FilesystemBasedFileParameterImpl());
+ if (!configuration.setConfigurationFromXml(file.getAbsolutePath())) {
+ logger.error("Bad configuration");
+ return;
+ }
+ configuration.setTIMEOUTCON(1000);
+ // Start server.
+ try {
+ configuration.serverStartup();
+ } catch (FtpNoConnectionException e) {
+ logger.error("FTP not started", e);
+ }
+ logger.info("FTP started");
+ }
+ }
+
+ public static void stopFtpServer() {
+ configuration.setShutdown(true);
+ configuration.getFtpInternalConfiguration().releaseResources();
+ }
+}
diff --git a/src/test/java/org/waarp/ftp/client/FTPClientExample.java b/src/test/java/org/waarp/ftp/client/FTPClientExampleTest.java
similarity index 59%
rename from src/test/java/org/waarp/ftp/client/FTPClientExample.java
rename to src/test/java/org/waarp/ftp/client/FTPClientExampleTest.java
index fcc59a4..53645dc 100644
--- a/src/test/java/org/waarp/ftp/client/FTPClientExample.java
+++ b/src/test/java/org/waarp/ftp/client/FTPClientExampleTest.java
@@ -1,99 +1,106 @@
-/**
- * This file is part of Waarp Project.
- *
- * Copyright 2009, Frederic Bregier, and individual contributors by the @author tags. See the
- * COPYRIGHT.txt in the distribution for a full listing of individual contributors.
- *
- * All Waarp Project is free software: you can redistribute it and/or modify it under the terms of
- * the GNU General Public License as published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- * Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with Waarp . If not, see
- * .
- */
+/*******************************************************************************
+ * This file is part of Waarp Project (named also Waarp or GG).
+ *
+ * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
+ * tags. See the COPYRIGHT.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * All Waarp Project is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * Waarp . If not, see .
+ ******************************************************************************/
package org.waarp.ftp.client;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPHTTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPConnectionClosedException;
import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPHTTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
import org.apache.commons.net.io.CopyStreamEvent;
import org.apache.commons.net.io.CopyStreamListener;
import org.apache.commons.net.util.TrustManagerUtils;
+import org.waarp.common.logging.WaarpLogger;
+import org.waarp.common.logging.WaarpLoggerFactory;
+import org.waarp.common.utility.DetectionUtils;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
/**
* This is the FTPClient example from Apache Commons-Net
- *
- * This is an example program demonstrating how to use the FTPClient class. This program connects to
- * an FTP server and retrieves the specified file. If the -s flag is used, it stores the local file
- * at the FTP server. Just so you can see what's happening, all reply strings are printed. If the -b
- * flag is used, a binary transfer is assumed (default is ASCII). See below for further options.
+ *
+ * This is an example program demonstrating how to use the FTPClient class. This
+ * program connects to an FTP
+ * server and retrieves the specified file. If the -s flag is used, it stores
+ * the local file at the FTP
+ * server. Just so you can see what's happening, all reply strings are printed.
+ * If the -b flag is used, a
+ * binary transfer is assumed (default is ASCII). See below for further
+ * options.
*/
-public final class FTPClientExample
-{
-
+public final class FTPClientExampleTest {
public static final String USAGE =
"Usage: ftp [options] [ []]\n"
- +
- "\nDefault behavior is to download a file and use ASCII transfer mode.\n"
- +
- "\t-a - use local active mode (default is local passive)\n"
- +
- "\t-b - use binary transfer mode\n"
- +
- "\t-c cmd - issue arbitrary command (remote is used as a parameter if provided) \n"
- +
- "\t-d - list directory details using MLSD (remote is used as the pathname if provided)\n"
- +
- "\t-e - use EPSV with IPv4 (default false)\n"
- +
- "\t-f - issue FEAT command (remote and local files are ignored)\n"
- +
- "\t-h - list hidden files (applies to -l and -n only)\n"
- +
- "\t-k secs - use keep-alive timer (setControlKeepAliveTimeout)\n"
- +
- "\t-l - list files using LIST (remote is used as the pathname if provided)\n"
- +
- "\t-L - use lenient future dates (server dates may be up to 1 day into future)\n"
- +
- "\t-n - list file names using NLST (remote is used as the pathname if provided)\n"
- +
- "\t-p true|false|protocol[,true|false] - use FTPSClient with the specified protocol and/or isImplicit setting\n"
- +
- "\t-s - store file on server (upload)\n"
- +
- "\t-t - list file details using MLST (remote is used as the pathname if provided)\n"
- +
- "\t-w msec - wait time for keep-alive reply (setControlKeepAliveReplyTimeout)\n"
- +
- "\t-T all|valid|none - use one of the built-in TrustManager implementations (none = JVM default)\n"
- +
- "\t-PrH server[:port] - HTTP Proxy host and optional port[80] \n" +
- "\t-PrU user - HTTP Proxy server username\n" +
- "\t-PrP password - HTTP Proxy server password\n" +
- "\t-# - add hash display during transfers\n";
-
- public static final void main(String[] args)
- {
- boolean storeFile = false, binaryTransfer = false, error = false, listFiles = false, listNames = false, hidden = false;
- boolean localActive = false, useEpsvWithIPv4 = false, feat = false, printHash = false;
+ +
+ "\nDefault behavior is to download a file and use ASCII transfer mode.\n"
+ + "\t-a - use local active mode (default is local passive)\n" +
+ "\t-b - use binary transfer mode\n"
+ +
+ "\t-c cmd - issue arbitrary command (remote is used as a parameter if provided) \n"
+ +
+ "\t-d - list directory details using MLSD (remote is used as the pathname if provided)\n"
+ + "\t-e - use EPSV with IPv4 (default false)\n"
+ + "\t-f - issue FEAT command (remote and local files are ignored)\n"
+ + "\t-h - list hidden files (applies to -l and -n only)\n"
+ + "\t-k secs - use keep-alive timer (setControlKeepAliveTimeout)\n"
+ +
+ "\t-l - list files using LIST (remote is used as the pathname if provided)\n"
+ +
+ "\t-L - use lenient future dates (server dates may be up to 1 day into future)\n"
+ +
+ "\t-n - list file names using NLST (remote is used as the pathname if provided)\n"
+ +
+ "\t-p true|false|protocol[,true|false] - use FTPSClient with the specified protocol and/or isImplicit setting\n"
+ + "\t-s - store file on server (upload)\n"
+ +
+ "\t-t - list file details using MLST (remote is used as the pathname if provided)\n"
+ +
+ "\t-w msec - wait time for keep-alive reply (setControlKeepAliveReplyTimeout)\n"
+ +
+ "\t-T all|valid|none - use one of the built-in TrustManager implementations (none = JVM default)\n"
+ + "\t-PrH server[:port] - HTTP Proxy host and optional port[80] \n"
+ + "\t-PrU user - HTTP Proxy server username\n" +
+ "\t-PrP password - HTTP Proxy server password\n"
+ + "\t-# - add hash display during transfers\n";
+ /**
+ * Internal Logger
+ */
+ private static final WaarpLogger
+ logger = WaarpLoggerFactory.getLogger(FTPClientExampleTest.class);
+ private static boolean stop = false;
+
+ public static final void main(String[] args) {
+ boolean storeFile = false, binaryTransfer = false, error = false,
+ listFiles = false, listNames = false,
+ hidden = false;
+ boolean localActive = false, useEpsvWithIPv4 = false, feat = false,
+ printHash = false;
boolean mlst = false, mlsd = false;
boolean lenient = false;
long keepAliveTimeout = -1;
@@ -108,80 +115,59 @@ public static final void main(String[] args)
String proxyPassword = null;
int base = 0;
- for (base = 0; base < args.length; base++)
- {
+ for (base = 0; base < args.length; base++) {
if (args[base].equals("-s")) {
storeFile = true;
- }
- else if (args[base].equals("-a")) {
+ } else if (args[base].equals("-a")) {
localActive = true;
- }
- else if (args[base].equals("-b")) {
+ } else if (args[base].equals("-b")) {
binaryTransfer = true;
- }
- else if (args[base].equals("-c")) {
+ } else if (args[base].equals("-c")) {
doCommand = args[++base];
minParams = 3;
- }
- else if (args[base].equals("-d")) {
+ } else if (args[base].equals("-d")) {
mlsd = true;
minParams = 3;
- }
- else if (args[base].equals("-e")) {
+ } else if (args[base].equals("-e")) {
useEpsvWithIPv4 = true;
- }
- else if (args[base].equals("-f")) {
+ } else if (args[base].equals("-f")) {
feat = true;
minParams = 3;
- }
- else if (args[base].equals("-h")) {
+ } else if (args[base].equals("-h")) {
hidden = true;
- }
- else if (args[base].equals("-k")) {
+ } else if (args[base].equals("-k")) {
keepAliveTimeout = Long.parseLong(args[++base]);
- }
- else if (args[base].equals("-l")) {
+ } else if (args[base].equals("-l")) {
listFiles = true;
minParams = 3;
- }
- else if (args[base].equals("-L")) {
+ } else if (args[base].equals("-L")) {
lenient = true;
- }
- else if (args[base].equals("-n")) {
+ } else if (args[base].equals("-n")) {
listNames = true;
minParams = 3;
- }
- else if (args[base].equals("-p")) {
+ } else if (args[base].equals("-p")) {
protocol = args[++base];
- }
- else if (args[base].equals("-t")) {
+ } else if (args[base].equals("-t")) {
mlst = true;
minParams = 3;
- }
- else if (args[base].equals("-w")) {
+ } else if (args[base].equals("-w")) {
controlKeepAliveReplyTimeout = Integer.parseInt(args[++base]);
- }
- else if (args[base].equals("-T")) {
+ } else if (args[base].equals("-T")) {
trustmgr = args[++base];
- }
- else if (args[base].equals("-PrH")) {
+ } else if (args[base].equals("-PrH")) {
proxyHost = args[++base];
String parts[] = proxyHost.split(":");
if (parts.length == 2) {
proxyHost = parts[0];
proxyPort = Integer.parseInt(parts[1]);
}
- }
- else if (args[base].equals("-PrU")) {
+ } else if (args[base].equals("-PrU")) {
proxyUser = args[++base];
- }
- else if (args[base].equals("-PrP")) {
+ } else if (args[base].equals("-PrP")) {
proxyPassword = args[++base];
- }
- else if (args[base].equals("-#")) {
+ } else if (args[base].equals("-#")) {
printHash = true;
- }
- else {
+ } else {
break;
}
}
@@ -190,7 +176,8 @@ else if (args[base].equals("-#")) {
if (remain < minParams) // server, user, pass, remote, local [protocol]
{
System.err.println(USAGE);
- System.exit(1);
+ DetectionUtils.SystemExit(1);
+ return;
}
String server = args[base++];
@@ -219,9 +206,9 @@ else if (args[base].equals("-#")) {
if (protocol == null) {
if (proxyHost != null) {
System.out.println("Using HTTP proxy server: " + proxyHost);
- ftp = new FTPHTTPClient(proxyHost, proxyPort, proxyUser, proxyPassword);
- }
- else {
+ ftp = new FTPHTTPClient(proxyHost, proxyPort, proxyUser,
+ proxyPassword);
+ } else {
ftp = new FTPClient();
}
} else {
@@ -247,10 +234,13 @@ else if (args[base].equals("-#")) {
ftp = ftps;
if ("all".equals(trustmgr)) {
System.out.println("Accept all");
- ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
+ ftps.setTrustManager(
+ TrustManagerUtils.getAcceptAllTrustManager());
} else if ("valid".equals(trustmgr)) {
System.out.println("Accept after valid");
- ftps.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
+ ftps.setTrustManager(
+ TrustManagerUtils
+ .getValidateServerCertificateTrustManager());
} else if ("none".equals(trustmgr)) {
System.out.println("Accept none");
ftps.setTrustManager(null);
@@ -269,58 +259,54 @@ else if (args[base].equals("-#")) {
ftp.setListHiddenFiles(hidden);
// suppress login details
- ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
+ ftp.addProtocolCommandListener(
+ new PrintCommandListener(new PrintWriter(System.out), true));
- try
- {
+ try {
int reply;
if (port > 0) {
ftp.connect(server, port);
} else {
ftp.connect(server);
}
- System.out.println("Connected to " + server + " on "
- + (port > 0 ? port : ftp.getDefaultPort()));
+ System.out.println("Connected to " + server + " on " +
+ (port > 0? port : ftp.getDefaultPort()));
// After connection attempt, you should check the reply code to verify
// success.
reply = ftp.getReplyCode();
- if (!FTPReply.isPositiveCompletion(reply))
- {
+ if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
- System.exit(1);
+ DetectionUtils.SystemExit(1);
+ return;
}
- } catch (IOException e)
- {
- if (ftp.getDataConnectionMode() == FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE)
- {
- try
- {
+ } catch (IOException e) {
+ if (ftp.getDataConnectionMode() ==
+ FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE) {
+ try {
ftp.disconnect();
- } catch (IOException f)
- {
+ } catch (IOException f) {
// do nothing
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
- System.exit(1);
+ DetectionUtils.SystemExit(1);
+ return;
}
- __main: try
- {
+ __main:
+ try {
if (account == null) {
- if (!ftp.login(username, password))
- {
+ if (!ftp.login(username, password)) {
ftp.logout();
error = true;
break __main;
}
} else {
- if (!ftp.login(username, password, account))
- {
+ if (!ftp.login(username, password, account)) {
ftp.logout();
error = true;
break __main;
@@ -347,8 +333,7 @@ else if (args[base].equals("-#")) {
((FTPSClient) ftp).execPROT("P");
}
- if (storeFile)
- {
+ if (storeFile) {
InputStream input;
input = new FileInputStream(local);
@@ -356,9 +341,7 @@ else if (args[base].equals("-#")) {
ftp.storeFile(remote, input);
input.close();
- }
- else if (listFiles)
- {
+ } else if (listFiles) {
if (lenient) {
FTPClientConfig config = new FTPClientConfig();
config.setLenientFutureDates(true);
@@ -369,38 +352,32 @@ else if (listFiles)
System.out.println(f.getRawListing());
System.out.println(f.toFormattedString());
}
- }
- else if (mlsd)
- {
+ } else if (mlsd) {
for (FTPFile f : ftp.mlistDir(remote)) {
System.out.println(f.getRawListing());
System.out.println(f.toFormattedString());
}
- }
- else if (mlst)
- {
+ } else if (mlst) {
FTPFile f = ftp.mlistFile(remote);
if (f != null) {
System.out.println(f.toFormattedString());
}
- }
- else if (listNames)
- {
+ } else if (listNames) {
for (String s : ftp.listNames(remote)) {
System.out.println(s);
}
- }
- else if (feat)
- {
+ } else if (feat) {
// boolean feature check
if (remote != null) { // See if the command is present
if (ftp.hasFeature(remote)) {
System.out.println("Has feature: " + remote);
} else {
if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
- System.out.println("FEAT " + remote + " was not detected");
+ System.out.println(
+ "FEAT " + remote + " was not detected");
} else {
- System.out.println("Command failed: " + ftp.getReplyString());
+ System.out.println(
+ "Command failed: " + ftp.getReplyString());
}
}
@@ -408,13 +385,16 @@ else if (feat)
String[] features = ftp.featureValues(remote);
if (features != null) {
for (String f : features) {
- System.out.println("FEAT " + remote + "=" + f + ".");
+ System.out
+ .println("FEAT " + remote + "=" + f + ".");
}
} else {
if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
- System.out.println("FEAT " + remote + " is not present");
+ System.out.println(
+ "FEAT " + remote + " is not present");
} else {
- System.out.println("Command failed: " + ftp.getReplyString());
+ System.out.println(
+ "Command failed: " + ftp.getReplyString());
}
}
} else {
@@ -424,9 +404,7 @@ else if (feat)
System.out.println("Failed: " + ftp.getReplyString());
}
}
- }
- else if (doCommand != null)
- {
+ } else if (doCommand != null) {
if (ftp.doCommand(doCommand, remote)) {
// Command listener has already printed the output
// for(String s : ftp.getReplyStrings()) {
@@ -435,9 +413,7 @@ else if (doCommand != null)
} else {
System.out.println("Failed: " + ftp.getReplyString());
}
- }
- else
- {
+ } else {
OutputStream output;
output = new FileOutputStream(local);
@@ -450,30 +426,25 @@ else if (doCommand != null)
ftp.noop(); // check that control connection is working OK
ftp.logout();
- } catch (FTPConnectionClosedException e)
- {
+ } catch (FTPConnectionClosedException e) {
error = true;
System.err.println("Server closed connection.");
e.printStackTrace();
- } catch (IOException e)
- {
+ } catch (IOException e) {
error = true;
e.printStackTrace();
- } finally
- {
- if (ftp.getDataConnectionMode() == FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE)
- {
- try
- {
+ } finally {
+ if (ftp.getDataConnectionMode() ==
+ FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE) {
+ try {
ftp.disconnect();
- } catch (IOException f)
- {
+ } catch (IOException f) {
// do nothing
}
}
}
- System.exit(error ? 1 : 0);
+ DetectionUtils.SystemExit(error? 1 : 0);
} // end main
private static CopyStreamListener createListener() {
@@ -481,12 +452,14 @@ private static CopyStreamListener createListener() {
private long megsTotal = 0;
public void bytesTransferred(CopyStreamEvent event) {
- bytesTransferred(event.getTotalBytesTransferred(), event.getBytesTransferred(),
- event.getStreamSize());
+ bytesTransferred(event.getTotalBytesTransferred(),
+ event.getBytesTransferred(),
+ event.getStreamSize());
}
public void bytesTransferred(long totalBytesTransferred,
- int bytesTransferred, long streamSize) {
+ int bytesTransferred,
+ long streamSize) {
long megs = totalBytesTransferred / 1000000;
for (long l = megsTotal; l < megs; l++) {
System.err.print("#");
diff --git a/src/test/java/org/waarp/ftp/client/FtpClient2Test.java b/src/test/java/org/waarp/ftp/client/FtpClient2Test.java
new file mode 100644
index 0000000..1c01e7b
--- /dev/null
+++ b/src/test/java/org/waarp/ftp/client/FtpClient2Test.java
@@ -0,0 +1,562 @@
+package org.waarp.ftp.client;
+
+import org.apache.commons.net.PrintCommandListener;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPClientConfig;
+import org.apache.commons.net.ftp.FTPConnectionClosedException;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPReply;
+import org.apache.commons.net.ftp.FTPSClient;
+import org.apache.commons.net.io.CopyStreamEvent;
+import org.apache.commons.net.io.CopyStreamListener;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.waarp.common.file.FileUtils;
+import org.waarp.common.logging.WaarpLogLevel;
+import org.waarp.common.logging.WaarpLogger;
+import org.waarp.common.logging.WaarpLoggerFactory;
+import org.waarp.common.logging.WaarpSlf4JLoggerFactory;
+import org.waarp.common.utility.DetectionUtils;
+import org.waarp.ftp.FtpServer;
+import org.waarp.ftp.client.transaction.Ftp4JClientTransactionTest;
+import org.waarp.ftp.client.transaction.FtpApacheClientTransactionTest;
+import org.waarp.ftp.client.transaction.FtpClientThread;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static junit.framework.TestCase.*;
+import static org.junit.Assert.assertFalse;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class FtpClient2Test {
+ public static AtomicLong numberOK = new AtomicLong(0);
+ public static AtomicLong numberKO = new AtomicLong(0);
+ /**
+ * Internal Logger
+ */
+ protected static WaarpLogger logger =
+ WaarpLoggerFactory.getLogger(FtpClient2Test.class);
+ private static final int port = 2021;
+
+ @BeforeClass
+ public static void startServer() throws IOException {
+ WaarpLoggerFactory
+ .setDefaultFactory(new WaarpSlf4JLoggerFactory(WaarpLogLevel.WARN));
+ DetectionUtils.setJunit(true);
+ File file = new File("/tmp/GGFTP/fred/a");
+ file.mkdirs();
+ FtpServer.startFtpServer("config.xml");
+ File localFilename = new File("/tmp/ftpfile.bin");
+ FileWriter fileWriterBig = new FileWriter(localFilename);
+ for (int i = 0; i < 100; i++) {
+ fileWriterBig.write("0123456789");
+ }
+ fileWriterBig.flush();
+ fileWriterBig.close();
+ logger.warn("Will start server");
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ logger.warn("Will shutdown from client");
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+ Ftp4JClientTransactionTest client =
+ new Ftp4JClientTransactionTest("127.0.0.1", port, "fredo", "fred1", "a",
+ 0);
+ if (!client.connect()) {
+ logger.warn("Cant connect");
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ }
+ try {
+ String[] results = client.executeSiteCommand("internalshutdown abcdef");
+ System.err.print("SHUTDOWN: ");
+ for (String string : results) {
+ System.err.println(string);
+ }
+ } finally {
+ client.disconnect();
+ }
+ logger.warn("Will stop server");
+ FtpServer.stopFtpServer();
+ File file = new File("/tmp/GGFTP");
+ FileUtils.forceDeleteRecursiveDir(file);
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ @Before
+ public void clean() {
+ File file = new File("/tmp/GGFTP");
+ FileUtils.forceDeleteRecursiveDir(file);
+ file = new File("/tmp/GGFTP/fredo/a");
+ file.mkdirs();
+ }
+
+
+
+
+ @Test
+ public void test1_Ftp4JSimple() throws IOException {
+ numberKO.set(0);
+ numberOK.set(0);
+ File localFilename = new File("/tmp/ftpfile.bin");
+ testFtp4J("127.0.0.1", port, "fred", "fred2", "a", 0,
+ localFilename.getAbsolutePath(), 0, 50, true, 1, 1);
+ }
+
+ public void testFtp4J(String server, int port, String username, String passwd,
+ String account, int isSSL,
+ String localFilename, int type, int delay,
+ boolean shutdown, int numberThread,
+ int numberIteration) {
+ // initiate Directories
+ Ftp4JClientTransactionTest client =
+ new Ftp4JClientTransactionTest(server, port, username, passwd, account,
+ isSSL);
+
+ logger.warn("First connexion");
+ if (!client.connect()) {
+ logger.error("Can't connect");
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ }
+ try {
+ logger.warn("Create Dirs");
+ for (int i = 0; i < numberThread; i++) {
+ client.makeDir("T" + i);
+ }
+ logger.warn("Feature commands");
+ System.err.println("SITE: " + client.featureEnabled("SITE"));
+ System.err.println("SITE CRC: " + client.featureEnabled("SITE XCRC"));
+ System.err.println("CRC: " + client.featureEnabled("XCRC"));
+ System.err.println("MD5: " + client.featureEnabled("XMD5"));
+ System.err.println("SHA1: " + client.featureEnabled("XSHA1"));
+ } finally {
+ logger.warn("Logout");
+ client.logout();
+ }
+ if (isSSL > 0) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ }
+ ExecutorService executorService = Executors.newCachedThreadPool();
+ logger.warn("Will start {} Threads", numberThread);
+ long date1 = System.currentTimeMillis();
+ for (int i = 0; i < numberThread; i++) {
+ executorService.execute(
+ new FtpClientThread("T" + i, server, port, username, passwd, account,
+ localFilename,
+ numberIteration, type, delay, isSSL));
+ if (delay > 0) {
+ try {
+ long newdel = ((delay / 3) / 10) * 10;
+ if (newdel == 0) {
+ Thread.yield();
+ } else {
+ Thread.sleep(newdel);
+ }
+ } catch (InterruptedException e) {
+ }
+ } else {
+ Thread.yield();
+ }
+ }
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ executorService.shutdownNow();
+ // Thread.currentThread().interrupt();
+ }
+ executorService.shutdown();
+ long date2 = 0;
+ try {
+ if (!executorService.awaitTermination(12000, TimeUnit.SECONDS)) {
+ date2 = System.currentTimeMillis() - 120000 * 60;
+ executorService.shutdownNow();
+ if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
+ System.err.println("Really not shutdown normally");
+ }
+ } else {
+ date2 = System.currentTimeMillis();
+ }
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ executorService.shutdownNow();
+ date2 = System.currentTimeMillis();
+ // Thread.currentThread().interrupt();
+ }
+
+ logger.warn(
+ localFilename + " " + numberThread + " " + numberIteration + " " +
+ type + " Real: "
+ + (date2 - date1) + " OK: " + numberOK.get() + " KO: " +
+ numberKO.get() + " Trf/s: "
+ + (numberOK.get() * 1000 / (date2 - date1)));
+ assertTrue("No KO", numberKO.get() == 0);
+ }
+
+ @Test
+ public void test2_FtpSimple() throws IOException {
+ numberKO.set(0);
+ numberOK.set(0);
+ File localFilename = new File("/tmp/ftpfile.bin");
+
+ int delay = 50;
+
+ FtpApacheClientTransactionTest
+ client =
+ new FtpApacheClientTransactionTest("127.0.0.1", port, "fred", "fred2",
+ "a", 0);
+ if (!client.connect()) {
+ logger.error("Can't connect");
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ }
+ try {
+ logger.warn("Create Dirs");
+ client.makeDir("T" + 0);
+ logger.warn("Feature commands");
+ System.err.println("SITE: " + client.featureEnabled("SITE"));
+ System.err.println("SITE CRC: " + client.featureEnabled("SITE XCRC"));
+ System.err.println("CRC: " + client.featureEnabled("XCRC"));
+ System.err.println("MD5: " + client.featureEnabled("XMD5"));
+ System.err.println("SHA1: " + client.featureEnabled("XSHA1"));
+ client.changeDir("T0");
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ client.changeFileType(true);
+ client.changeMode(true);
+ internalApacheClient(client, localFilename, delay, true);
+ client.changeMode(false);
+ internalApacheClient(client, localFilename, delay, false);
+ } finally {
+ logger.warn("Logout");
+ client.logout();
+ client.disconnect();
+ }
+ assertTrue("No KO", numberKO.get() == 0);
+ }
+
+
+ private void internalApacheClient(FtpApacheClientTransactionTest client,
+ File localFilename, int delay,
+ boolean mode) {
+ String smode = mode? "passive" : "active";
+ logger.info(" transfer {} store ", smode);
+ if (!client.transferFile(localFilename.getAbsolutePath(),
+ localFilename.getName(), true)) {
+ logger.warn("Cant store file {} mode ", smode);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ if (!client.deleteFile(localFilename.getName())) {
+ logger.warn(" Cant delete file {} mode ", smode);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ if (!client.transferFile(localFilename.getAbsolutePath(),
+ localFilename.getName(), true)) {
+ logger.warn("Cant store file {} mode ", smode);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ Thread.yield();
+ logger.info(" transfer {} retr ", smode);
+ if (!client.transferFile(null,
+ localFilename.getName(), false)) {
+ logger.warn("Cant retrieve file {} mode ", smode);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
+ @Test
+ public void test0_FtpApacheClientActive() throws IOException {
+ File localFilename = new File("/tmp/ftpfile.bin");
+ FileWriter fileWriterBig = new FileWriter(localFilename);
+ for (int i = 0; i < 100; i++) {
+ fileWriterBig.write("0123456789");
+ }
+ fileWriterBig.flush();
+ fileWriterBig.close();
+ logger.warn("Active");
+ launchFtpClient("127.0.0.1", port, "fredo", "fred1", "a", true,
+ localFilename.getAbsolutePath(), localFilename.getName());
+ logger.warn("End Active");
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+
+ @Test
+ public void test0_FtpApacheClientPassive() throws IOException {
+ File localFilename = new File("/tmp/ftpfile.bin");
+ FileWriter fileWriterBig = new FileWriter(localFilename);
+ for (int i = 0; i < 100; i++) {
+ fileWriterBig.write("0123456789");
+ }
+ fileWriterBig.flush();
+ fileWriterBig.close();
+ logger.warn("Passive");
+ launchFtpClient("127.0.0.1", port, "fredo", "fred1", "a", false,
+ localFilename.getAbsolutePath(), localFilename.getName());
+ logger.warn("End Passive");
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+
+ public static void launchFtpClient(String server, int port, String username,
+ String password, String account,
+ boolean localActive, String local,
+ String remote) {
+ boolean mustCallProtP = false;
+ boolean binaryTransfer = true, error = false;
+ boolean useEpsvWithIPv4 = false;
+ boolean lenient = false;
+ final FTPClient ftp;
+ ftp = new FTPClient();
+
+ ftp.setCopyStreamListener(createListener());
+ ftp.setControlKeepAliveTimeout(30000);
+ ftp.setControlKeepAliveReplyTimeout(30000);
+ ftp.setListHiddenFiles(true);
+ // suppress login details
+ ftp.addProtocolCommandListener(
+ new PrintCommandListener(new PrintWriter(System.out), true));
+
+ try {
+ int reply;
+ if (port > 0) {
+ ftp.connect(server, port);
+ } else {
+ ftp.connect(server);
+ }
+ System.out.println("Connected to " + server + " on " +
+ (port > 0? port : ftp.getDefaultPort()));
+
+ // After connection attempt, you should check the reply code to verify
+ // success.
+ reply = ftp.getReplyCode();
+
+ if (!FTPReply.isPositiveCompletion(reply)) {
+ ftp.disconnect();
+ System.err.println("FTP server refused connection.");
+ assertFalse("Can't connect", true);
+ return;
+ }
+ } catch (IOException e) {
+ if (ftp.getDataConnectionMode() ==
+ FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE) {
+ try {
+ ftp.disconnect();
+ } catch (IOException f) {
+ // do nothing
+ }
+ }
+ System.err.println("Could not connect to server.");
+ e.printStackTrace();
+ assertFalse("Can't connect", true);
+ return;
+ }
+
+ __main:
+ try {
+ if (account == null) {
+ if (!ftp.login(username, password)) {
+ ftp.logout();
+ error = true;
+ break __main;
+ }
+ } else {
+ if (!ftp.login(username, password, account)) {
+ ftp.logout();
+ error = true;
+ break __main;
+ }
+ }
+ System.out.println("Remote system is " + ftp.getSystemType());
+
+ if (binaryTransfer) {
+ ftp.setFileType(FTP.BINARY_FILE_TYPE);
+ }
+
+ // Use passive mode as default because most of us are
+ // behind firewalls these days.
+ if (localActive) {
+ ftp.enterLocalActiveMode();
+ } else {
+ ftp.enterLocalPassiveMode();
+ }
+
+ ftp.setUseEPSVwithIPv4(useEpsvWithIPv4);
+
+ if (mustCallProtP) {
+ ((FTPSClient) ftp).execPBSZ(0);
+ ((FTPSClient) ftp).execPROT("P");
+ }
+
+ InputStream input;
+
+ input = new FileInputStream(local);
+
+ if (!ftp.storeFile(remote, input)) {
+ error = true;
+ input.close();
+ return;
+ }
+ input.close();
+
+ OutputStream output;
+
+ output = new FileOutputStream(local);
+
+ if (!ftp.retrieveFile(remote, output)) {
+ error = true;
+ output.close();
+ return;
+ }
+ output.close();
+ if (lenient) {
+ FTPClientConfig config = new FTPClientConfig();
+ config.setLenientFutureDates(true);
+ ftp.configure(config);
+ }
+
+ for (FTPFile f : ftp.listFiles(remote)) {
+ System.out.println(f.getRawListing());
+ System.out.println(f.toFormattedString());
+ }
+ for (FTPFile f : ftp.mlistDir(remote)) {
+ System.out.println(f.getRawListing());
+ System.out.println(f.toFormattedString());
+ }
+ FTPFile f = ftp.mlistFile(remote);
+ if (f != null) {
+ System.out.println(f.toFormattedString());
+ }
+ String[] results = ftp.listNames(remote);
+ if (results != null) {
+ for (String s : ftp.listNames(remote)) {
+ System.out.println(s);
+ }
+ }
+ if (!ftp.deleteFile(remote)) {
+ error = true;
+ System.out.println("Failed delete");
+ }
+ // boolean feature check
+ if (ftp.features()) {
+ // Command listener has already printed the output
+ } else {
+ System.out.println("Failed: " + ftp.getReplyString());
+ error = true;
+ }
+
+ ftp.noop(); // check that control connection is working OK
+ } catch (FTPConnectionClosedException e) {
+ error = true;
+ System.err.println("Server closed connection.");
+ e.printStackTrace();
+ } catch (IOException e) {
+ error = true;
+ e.printStackTrace();
+ } finally {
+ if (ftp.getDataConnectionMode() ==
+ FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE) {
+ try {
+ ftp.disconnect();
+ } catch (IOException f) {
+ // do nothing
+ }
+ }
+ assertFalse("Error occurs", error);
+ }
+ }
+
+
+ private static CopyStreamListener createListener() {
+ return new CopyStreamListener() {
+ private long megsTotal = 0;
+
+ public void bytesTransferred(CopyStreamEvent event) {
+ bytesTransferred(event.getTotalBytesTransferred(),
+ event.getBytesTransferred(), event.getStreamSize());
+ }
+
+ public void bytesTransferred(long totalBytesTransferred,
+ int bytesTransferred, long streamSize) {
+ long megs = totalBytesTransferred / 1000000;
+ for (long l = megsTotal; l < megs; l++) {
+ System.err.print("#");
+ }
+ megsTotal = megs;
+ }
+ };
+ }
+}
diff --git a/src/test/java/org/waarp/ftp/client/FtpClient.java b/src/test/java/org/waarp/ftp/client/FtpClientTest.java
similarity index 52%
rename from src/test/java/org/waarp/ftp/client/FtpClient.java
rename to src/test/java/org/waarp/ftp/client/FtpClientTest.java
index 6fa6731..dce919a 100644
--- a/src/test/java/org/waarp/ftp/client/FtpClient.java
+++ b/src/test/java/org/waarp/ftp/client/FtpClientTest.java
@@ -1,28 +1,57 @@
+/**
+ * This file is part of Waarp Project (named also Waarp or GG).
+ *
+ * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
+ * tags. See the COPYRIGHT.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * All Waarp Project is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * Waarp . If not, see .
+ */
+
/**
*
*/
package org.waarp.ftp.client;
+import org.waarp.common.logging.WaarpLogger;
+import org.waarp.common.logging.WaarpLoggerFactory;
+import org.waarp.common.logging.WaarpSlf4JLoggerFactory;
+import org.waarp.common.utility.DetectionUtils;
+import org.waarp.ftp.client.transaction.Ftp4JClientTransactionTest;
+import org.waarp.ftp.client.transaction.FtpClientThread;
+
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
-import org.waarp.common.logging.WaarpLoggerFactory;
-import org.waarp.common.logging.WaarpSlf4JLoggerFactory;
-import org.waarp.ftp.client.transaction.FtpClientThread;
-import org.waarp.ftp.client.transaction.Ftp4JClientTransactionTest;
+import static junit.framework.TestCase.*;
/**
- * Simple test example using predefined scenario (Note: this uses the configuration example for user shutdown command)
- *
+ * Simple test example using predefined scenario (Note: this uses the configuration example for user shutdown
+ * command)
+ *
* @author frederic
- *
+ *
*/
-public class FtpClient {
+public class FtpClientTest {
public static AtomicLong numberOK = new AtomicLong(0);
-
public static AtomicLong numberKO = new AtomicLong(0);
+ /**
+ * Internal Logger
+ */
+ protected static WaarpLogger logger =
+ WaarpLoggerFactory.getLogger(FtpClientTest.class);
/**
* @param args
@@ -40,9 +69,11 @@ public static void main(String[] args) {
int numberThread = 1;
int numberIteration = 1;
if (args.length < 8) {
- System.err.println("Usage: " + FtpClient.class.getSimpleName() +
- " server port user pwd acct localfilename nbThread nbIter");
- System.exit(1);
+ System.err.println("Usage: " + FtpClientTest.class.getSimpleName()
+ +
+ " server port user pwd acct localfilename nbThread nbIter");
+ DetectionUtils.SystemExit(1);
+ return;
}
server = args[0];
port = Integer.parseInt(args[1]);
@@ -70,24 +101,44 @@ public static void main(String[] args) {
if (args.length > 11) {
shutdown = Integer.parseInt(args[11]) > 0;
}
+ FtpClientTest ftpClient = new FtpClientTest();
+ ftpClient.testFtp4J(server, port, username, passwd, account, isSSL,
+ localFilename, type, delay, shutdown,
+ numberThread, numberIteration);
+ }
+
+ public void testFtp4J(String server, int port, String username,
+ String passwd,
+ String account, int isSSL,
+ String localFilename, int type, int delay,
+ boolean shutdown, int numberThread,
+ int numberIteration) {
// initiate Directories
- Ftp4JClientTransactionTest client = new Ftp4JClientTransactionTest(server,
- port, username, passwd, account, isSSL);
+ Ftp4JClientTransactionTest client =
+ new Ftp4JClientTransactionTest(server, port, username, passwd,
+ account,
+ isSSL);
+
+ logger.warn("First connexion");
if (!client.connect()) {
- System.err.println("Cant connect");
- FtpClient.numberKO.incrementAndGet();
+ logger.error("Can't connect");
+ FtpClientTest.numberKO.incrementAndGet();
return;
}
try {
+ logger.warn("Create Dirs");
for (int i = 0; i < numberThread; i++) {
client.makeDir("T" + i);
}
+ logger.warn("Feature commands");
System.err.println("SITE: " + client.featureEnabled("SITE"));
- System.err.println("SITE CRC: " + client.featureEnabled("SITE XCRC"));
+ System.err
+ .println("SITE CRC: " + client.featureEnabled("SITE XCRC"));
System.err.println("CRC: " + client.featureEnabled("XCRC"));
System.err.println("MD5: " + client.featureEnabled("XMD5"));
System.err.println("SHA1: " + client.featureEnabled("XSHA1"));
} finally {
+ logger.warn("Logout");
client.logout();
}
if (isSSL > 0) {
@@ -97,18 +148,22 @@ public static void main(String[] args) {
}
}
ExecutorService executorService = Executors.newCachedThreadPool();
+ logger.warn("Will start {} Threads", numberThread);
long date1 = System.currentTimeMillis();
for (int i = 0; i < numberThread; i++) {
- executorService.execute(new FtpClientThread("T" + i, server, port,
- username, passwd, account, localFilename, numberIteration,
- type, delay, isSSL));
+ executorService.execute(
+ new FtpClientThread("T" + i, server, port, username, passwd,
+ account,
+ localFilename,
+ numberIteration, type, delay, isSSL));
if (delay > 0) {
try {
long newdel = ((delay / 3) / 10) * 10;
- if (newdel == 0)
+ if (newdel == 0) {
Thread.yield();
- else
+ } else {
Thread.sleep(newdel);
+ }
} catch (InterruptedException e) {
}
} else {
@@ -118,10 +173,9 @@ public static void main(String[] args) {
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
- // TODO Auto-generated catch block
e1.printStackTrace();
executorService.shutdownNow();
- Thread.currentThread().interrupt();
+ // Thread.currentThread().interrupt();
}
executorService.shutdown();
long date2 = 0;
@@ -140,35 +194,17 @@ public static void main(String[] args) {
e.printStackTrace();
executorService.shutdownNow();
date2 = System.currentTimeMillis();
- Thread.currentThread().interrupt();
+ // Thread.currentThread().interrupt();
}
- System.out.println(localFilename + " " + numberThread + " " + numberIteration + " " + type +
- " Real: " + (date2 - date1) + " OK: " +
- numberOK.get() + " KO: " + numberKO.get() + " Trf/s: " +
- (numberOK.get() * 1000 / (date2 - date1)));
- if (shutdown) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- }
- client = new Ftp4JClientTransactionTest(server,
- port, "fredo", "fred1", "a", isSSL);
- if (!client.connect()) {
- System.err.println("Cant connect");
- FtpClient.numberKO.incrementAndGet();
- return;
- }
- try {
- String[] results = client.executeSiteCommand("internalshutdown abcdef");
- System.err.print("SHUTDOWN: ");
- for (String string : results) {
- System.err.println(string);
- }
- } finally {
- client.disconnect();
- }
- }
+ logger.warn(
+ localFilename + " " + numberThread + " " + numberIteration +
+ " " +
+ type + " Real: "
+ + (date2 - date1) + " OK: " + numberOK.get() + " KO: " +
+ numberKO.get() + " Trf/s: "
+ + (numberOK.get() * 1000 / (date2 - date1)));
+ assertTrue("No KO", numberKO.get() == 0);
}
}
diff --git a/src/test/java/org/waarp/ftp/client/transaction/Ftp4JClientTransactionTest.java b/src/test/java/org/waarp/ftp/client/transaction/Ftp4JClientTransactionTest.java
index ca684f8..521f226 100644
--- a/src/test/java/org/waarp/ftp/client/transaction/Ftp4JClientTransactionTest.java
+++ b/src/test/java/org/waarp/ftp/client/transaction/Ftp4JClientTransactionTest.java
@@ -1,45 +1,76 @@
+/*******************************************************************************
+ * This file is part of Waarp Project (named also Waarp or GG).
+ *
+ * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
+ * tags. See the COPYRIGHT.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * All Waarp Project is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * Waarp . If not, see .
+ ******************************************************************************/
+
package org.waarp.ftp.client.transaction;
+import org.waarp.common.logging.WaarpLogger;
+import org.waarp.common.logging.WaarpLoggerFactory;
import org.waarp.ftp.client.WaarpFtp4jClient;
+import java.io.File;
+
/**
* FTP Client using FTP4J with the test scenario
- *
+ *
* @author frederic
- *
*/
public class Ftp4JClientTransactionTest extends WaarpFtp4jClient {
- /**
- *
- * @param server
- * @param port
- * @param username
- * @param passwd
- * @param account
- */
- public Ftp4JClientTransactionTest(String server, int port, String username,
- String passwd, String account, int isSsl) {
- super(server, port, username, passwd, account, false, isSsl, 0, 10000);
- }
+ /**
+ * Internal Logger
+ */
+ protected static WaarpLogger
+ logger = WaarpLoggerFactory.getLogger(Ftp4JClientTransactionTest.class);
+
+ /**
+ * @param server
+ * @param port
+ * @param username
+ * @param passwd
+ * @param account
+ */
+ public Ftp4JClientTransactionTest(String server, int port, String username,
+ String passwd, String account, int isSsl) {
+ super(server, port, username, passwd, account, false, isSsl, 0, 10000);
+ File dir = new File("/tmp/GGFTP/" + username + "/" + account);
+ dir.mkdirs();
+ }
+
+ /**
+ * Ask to transfer a file
+ *
+ * @param local
+ * @param remote
+ * @param store
+ *
+ * @return True if the file is correctly transfered
+ */
+ public boolean transferFile(String local, String remote, boolean store) {
+ boolean status = super.transferFile(local, remote, store? 1 : 0);
+ logger.info("Transfer {} to {} using {} is {}", local, remote,
+ store? "STOR" : "RETR", status);
+ return status;
+ }
- /**
- * Ask to transfer a file
- *
- * @param local
- * @param remote
- * @param store
- * @return True if the file is correctly transfered
- */
- public boolean transferFile(String local, String remote, boolean store) {
- boolean status = super.transferFile(local, remote, store ? 1 : 0);
- /*
- * if (status) { String [] results = this.executeSiteCommand("XCRC "+remote); for (String
- * string : results) { System.err.println("XCRC: "+string); } results =
- * this.executeSiteCommand("XMD5 "+remote); for (String string : results) {
- * System.err.println("XMD5: "+string); } results =
- * this.executeSiteCommand("XSHA1 "+remote); for (String string : results) {
- * System.err.println("XSHA1: "+string); } }
- */
- return status;
- }
+ public boolean deleteFile(String remote) {
+ boolean status = super.deleteFile(remote);
+ logger.info("Delete {} is {}", remote, status);
+ return status;
+ }
}
diff --git a/src/test/java/org/waarp/ftp/client/transaction/FtpApacheClientTransactionTest.java b/src/test/java/org/waarp/ftp/client/transaction/FtpApacheClientTransactionTest.java
index b040125..9d71a44 100644
--- a/src/test/java/org/waarp/ftp/client/transaction/FtpApacheClientTransactionTest.java
+++ b/src/test/java/org/waarp/ftp/client/transaction/FtpApacheClientTransactionTest.java
@@ -1,96 +1,128 @@
+/*******************************************************************************
+ * This file is part of Waarp Project (named also Waarp or GG).
+ *
+ * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
+ * tags. See the COPYRIGHT.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * All Waarp Project is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * Waarp . If not, see .
+ ******************************************************************************/
+
package org.waarp.ftp.client.transaction;
+import org.waarp.ftp.client.NullOutputStream;
+import org.waarp.ftp.client.WaarpFtpClient;
+
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
-import org.waarp.ftp.client.NullOutputStream;
-import org.waarp.ftp.client.WaarpFtpClient;
-
/**
* FTP Apache Commons-Net client transaction test
- *
+ *
* @author frederic
- *
*/
public class FtpApacheClientTransactionTest extends WaarpFtpClient {
- /**
- *
- * @param server
- * @param port
- * @param username
- * @param passwd
- * @param account
- */
- public FtpApacheClientTransactionTest(String server, int port, String username,
- String passwd, String account, int isSsl) {
- super(server, port, username, passwd, account, false, isSsl, 0, 10000);
- }
+ /**
+ * @param server
+ * @param port
+ * @param username
+ * @param passwd
+ * @param account
+ */
+ public FtpApacheClientTransactionTest(String server, int port,
+ String username,
+ String passwd, String account,
+ int isSsl) {
+ super(server, port, username, passwd, account, false, isSsl, 0, 10000);
+ File dir = new File("/tmp/GGFTP/" + username + "/" + account);
+ dir.mkdirs();
+ }
- /**
- * Ask to transfer a file
- *
- * @param local
- * @param remote
- * @param store
- * @return True if the file is correctly transfered
- */
- public boolean transferFile(String local, String remote, boolean store) {
- boolean status = false;
- OutputStream output = null;
- FileInputStream fileInputStream = null;
+ /**
+ * Ask to transfer a file
+ *
+ * @param local
+ * @param remote
+ * @param store
+ *
+ * @return True if the file is correctly transfered
+ */
+ public boolean transferFile(String local, String remote, boolean store) {
+ boolean status = false;
+ OutputStream output = null;
+ FileInputStream fileInputStream = null;
+ try {
+ if (store) {
+ status = super.transferFile(local, remote, 1);
+ if (!status) {
+ System.err.println("Cannot finalize store like operation");
+ return false;
+ }
+ /*
+ * if (!this.ftpClient.completePendingCommand()) {
+ * System.err.println("Cannot finalize store like operation"); return false; }
+ */
+ String[] results = this.executeSiteCommand("XCRC " + remote);
+ for (String string : results) {
+ System.err.println("XCRC: " + string);
+ }
+ results = this.executeSiteCommand("XMD5 " + remote);
+ for (String string : results) {
+ System.err.println("XMD5: " + string);
+ }
+ results = this.executeSiteCommand("XSHA1 " + remote);
+ for (String string : results) {
+ System.err.println("XSHA1: " + string);
+ }
+ results = this.listFiles();
+ for (String string : results) {
+ System.err.println("LIST: " + string);
+ }
+ return true;
+ } else {
+ output = new NullOutputStream();
+ status = this.ftpClient.retrieveFile(remote,
+ output);
+ output.flush();
+ output.close();
+ return status;
+ }
+ } catch (IOException e) {
+ if (output != null) {
try {
- if (store) {
- fileInputStream = new FileInputStream(local);
- status = this.ftpClient.storeFile(remote, fileInputStream);
- fileInputStream.close();
- fileInputStream = null;
- if (!status) {
- System.err.println("Cannot finalize store like operation");
- return false;
- }
- if (!this.ftpClient.completePendingCommand()) {
- System.err.println("Cannot finalize store like operation");
- return false;
- }
- String[] results = this.executeSiteCommand("XCRC " + remote);
- for (String string : results) {
- System.err.println("XCRC: " + string);
- }
- results = this.executeSiteCommand("XMD5 " + remote);
- for (String string : results) {
- System.err.println("XMD5: " + string);
- }
- results = this.executeSiteCommand("XSHA1 " + remote);
- for (String string : results) {
- System.err.println("XSHA1: " + string);
- }
- return true;
- } else {
- output = new NullOutputStream();
- status = this.ftpClient.retrieveFile(remote,
- output);
- output.flush();
- output.close();
- if (!this.ftpClient.completePendingCommand()) {
- System.err.println("Cannot finalize store like operation");
- return false;
- }
- return status;
- }
- } catch (IOException e) {
- if (output != null)
- try {
- output.close();
- } catch (IOException e1) {
- }
- if (fileInputStream != null)
- try {
- fileInputStream.close();
- } catch (IOException e1) {
- }
- e.printStackTrace();
- return false;
+ output.close();
+ } catch (IOException e1) {
}
+ }
+ if (fileInputStream != null) {
+ try {
+ fileInputStream.close();
+ } catch (IOException e1) {
+ }
+ }
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ public boolean deleteFile(String remote) {
+ try {
+ return this.ftpClient.deleteFile(remote);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
}
+ }
}
diff --git a/src/test/java/org/waarp/ftp/client/transaction/FtpClientThread.java b/src/test/java/org/waarp/ftp/client/transaction/FtpClientThread.java
index 876cc9c..6984e1a 100644
--- a/src/test/java/org/waarp/ftp/client/transaction/FtpClientThread.java
+++ b/src/test/java/org/waarp/ftp/client/transaction/FtpClientThread.java
@@ -1,201 +1,338 @@
+/*******************************************************************************
+ * This file is part of Waarp Project (named also Waarp or GG).
+ *
+ * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
+ * tags. See the COPYRIGHT.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * All Waarp Project is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * Waarp . If not, see .
+ ******************************************************************************/
+
/**
*
*/
package org.waarp.ftp.client.transaction;
-import java.io.File;
-import java.util.Date;
+import org.waarp.common.logging.WaarpLogger;
+import org.waarp.common.logging.WaarpLoggerFactory;
+import org.waarp.ftp.client.FtpClientTest;
-import org.waarp.ftp.client.FtpClient;
+import java.io.File;
/**
* FTP Thread used to check multiple FTP clients in parallel with the test scenario
- *
+ *
* @author frederic
- *
+ *
*/
public class FtpClientThread implements Runnable {
- private String id = null;
-
- private String server = null;
-
- private int port = 21;
-
- private String username = null;
-
- private String passwd = null;
-
- private String account = null;
-
- private String localFilename = null;
-
- private String remoteFilename = null;
-
- private int numberIteration = 1;
-
- private int type = 0;
-
- private int delay = 0;
-
- private int isSsl = 0;
-
- /**
- * @param id
- * @param server
- * @param port
- * @param username
- * @param passwd
- * @param account
- * @param localFilename
- * @param nb
- * @param type
- * @param delay
- */
- public FtpClientThread(String id, String server, int port, String username,
- String passwd, String account, String localFilename, int nb,
- int type, int delay, int isSsl) {
- this.id = id;
- this.server = server;
- this.port = port;
- this.username = username;
- this.passwd = passwd;
- this.account = account;
- this.localFilename = localFilename;
- File local = new File(this.localFilename);
- this.remoteFilename = local.getName();
- this.numberIteration = nb;
- this.type = type;
- this.delay = (delay / 10) * 10;
- this.isSsl = isSsl;
+ /**
+ * Internal Logger
+ */
+ protected static WaarpLogger
+ logger = WaarpLoggerFactory.getLogger(FtpClientThread.class);
+
+ private String id = null;
+
+ private String server = null;
+
+ private int port = 21;
+
+ private String username = null;
+
+ private String passwd = null;
+
+ private String account = null;
+
+ private String localFilename = null;
+
+ private String remoteFilename = null;
+
+ private int numberIteration = 1;
+
+ private int type = 0;
+
+ private int delay = 0;
+
+ private int isSsl = 0;
+
+ /**
+ * @param id
+ * @param server
+ * @param port
+ * @param username
+ * @param passwd
+ * @param account
+ * @param localFilename
+ * @param nb
+ * @param type
+ * @param delay
+ */
+ public FtpClientThread(String id, String server, int port, String username,
+ String passwd, String account, String localFilename,
+ int nb,
+ int type, int delay, int isSsl) {
+ this.id = id;
+ this.server = server;
+ this.port = port;
+ this.username = username;
+ this.passwd = passwd;
+ this.account = account;
+ this.localFilename = localFilename;
+ File local = new File(this.localFilename);
+ this.remoteFilename = local.getName();
+ this.numberIteration = nb;
+ this.type = type;
+ this.delay = (delay / 10) * 10;
+ this.isSsl = isSsl;
+ File dir = new File("/tmp/GGFTP/T" + id + "/" + account);
+ dir.mkdirs();
+ }
+
+ public void run() {
+ Ftp4JClientTransactionTest client =
+ new Ftp4JClientTransactionTest(this.server,
+ this.port, this.username, this.passwd,
+ this.account, this.isSsl);
+ // Thread.yield();
+ // System.err.println(id+" connect");
+ if (!client.connect()) {
+ logger.error(id + " Cant connect");
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
}
+ try {
+ if (this.numberIteration <= 0) {
+ FtpClientTest.numberOK.incrementAndGet();
+ return;// Only connect
+ }
+ // client.makeDir(this.id);
+ logger.info(id + " change dir");
+ client.changeDir(this.id);
+ if (delay >= 10) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ } else {
+ Thread.yield();
+ }
- public void run() {
- Ftp4JClientTransactionTest client = new Ftp4JClientTransactionTest(this.server,
- this.port, this.username, this.passwd, this.account, this.isSsl);
- // Thread.yield();
- // System.err.println(id+" connect");
- if (!client.connect()) {
- System.err.println(id + " Cant connect");
- FtpClient.numberKO.incrementAndGet();
+ logger.info(id + " change type");
+ client.changeFileType(true);
+ if (type <= 0) {
+ logger.warn(id + " change mode passive");
+ client.changeMode(true);
+ if (type <= -10) {
+ for (int i = 0; i < this.numberIteration; i++) {
+ logger.info(id + " transfer passive store " + i);
+ if (!client.transferFile(this.localFilename,
+ this.remoteFilename, true)) {
+ logger.warn("Cant store file passive mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ // System.err.println(id+" end transfer store "+i);
+ }
+ Thread.yield();
+ } else {
+ for (int i = 0; i < this.numberIteration; i++) {
+ logger.info(id + " transfer passive store " + i);
+ if (!client.transferFile(this.localFilename,
+ this.remoteFilename, true)) {
+ logger.warn("Cant store file passive mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ if (!client.deleteFile(remoteFilename)) {
+ logger.warn(" Cant delete file passive mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ // System.err.println(id+" end transfer retr "+i);
+ }
+ if (!client.transferFile(this.localFilename,
+ this.remoteFilename, true)) {
+ logger.warn("Cant store file passive mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
return;
- }
- try {
- if (this.numberIteration <= 0) {
- FtpClient.numberOK.incrementAndGet();
- return;// Only connect
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
}
- // client.makeDir(this.id);
- // System.err.println(id+" change dir");
- client.changeDir(this.id);
- if (delay >= 10) {
+ }
+ Thread.yield();
+ for (int i = 0; i < this.numberIteration; i++) {
+ logger.info(id + " transfer passive retr " + i);
+ if (!client.transferFile(null,
+ this.remoteFilename, false)) {
+ logger.warn("Cant retrieve file passive mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
try {
- Thread.sleep(delay);
+ Thread.sleep(delay);
} catch (InterruptedException e) {
}
+ }
+ }
+ // System.err.println(id+" end transfer retr "+i);
+ }
+ Thread.yield();
+ }
+ }
+ if (type >= 0) {
+ logger.warn(id + " change mode active");
+ client.changeMode(false);
+ if (type >= 10) {
+ for (int i = 0; i < this.numberIteration; i++) {
+ logger.info(id + " transfer active store " + i);
+ if (!client.transferFile(this.localFilename,
+ this.remoteFilename, true)) {
+ logger.warn("Cant store file active mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
} else {
- Thread.yield();
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
}
-
- // System.err.println(id+" change type");
- client.changeFileType(true);
- if (type <= 0) {
- // System.err.println(id+" change mode passive");
- client.changeMode(true);
- if (type <= -10) {
- for (int i = 0; i < this.numberIteration; i++) {
- // System.err.println(id+" transfer store "+i);
- if (!client.transferFile(this.localFilename,
- this.remoteFilename, true)) {
- System.err.println((new Date()) +
- " Cant store file passive mode " + this.id);
- FtpClient.numberKO.incrementAndGet();
- return;
- } else {
- FtpClient.numberOK.incrementAndGet();
- if (delay > 0) {
- try {
- Thread.sleep(delay);
- } catch (InterruptedException e) {
- }
- }
- }
- // System.err.println(id+" end transfer store "+i);
- }
- Thread.yield();
- } else {
- for (int i = 0; i < this.numberIteration; i++) {
- // System.err.println(id+" transfer retr "+i);
- if (!client.transferFile(null,
- this.remoteFilename, false)) {
- System.err.println((new Date()) +
- " Cant retrieve file passive mode " + this.id);
- FtpClient.numberKO.incrementAndGet();
- return;
- } else {
- FtpClient.numberOK.incrementAndGet();
- if (delay > 0) {
- try {
- Thread.sleep(delay);
- } catch (InterruptedException e) {
- }
- }
- }
- // System.err.println(id+" end transfer retr "+i);
- }
- Thread.yield();
+ // System.err.println(id+" transfer store end "+i);
+ }
+ Thread.yield();
+ } else {
+ for (int i = 0; i < this.numberIteration; i++) {
+ logger.info(id + " transfer active store " + i);
+ if (!client.transferFile(this.localFilename,
+ this.remoteFilename, true)) {
+ logger.warn("Cant store file active mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
}
+ }
}
- if (type >= 0) {
- // System.err.println(id+" change mode active");
- client.changeMode(false);
- if (type >= 10) {
- for (int i = 0; i < this.numberIteration; i++) {
- // System.err.println(id+" transfer store "+i);
- if (!client.transferFile(this.localFilename,
- this.remoteFilename, true)) {
- System.err.println((new Date()) +
- " Cant store file active mode " + this.id);
- FtpClient.numberKO.incrementAndGet();
- return;
- } else {
- FtpClient.numberOK.incrementAndGet();
- if (delay > 0) {
- try {
- Thread.sleep(delay);
- } catch (InterruptedException e) {
- }
- }
- }
- // System.err.println(id+" transfer store end "+i);
- }
- Thread.yield();
- } else {
- for (int i = 0; i < this.numberIteration; i++) {
- // System.err.println(id+" transfer retr "+i);
- if (!client.transferFile(null,
- this.remoteFilename, false)) {
- System.err.println((new Date()) +
- " Cant retrieve file active mode " + this.id);
- FtpClient.numberKO.incrementAndGet();
- return;
- } else {
- FtpClient.numberOK.incrementAndGet();
- if (delay > 0) {
- try {
- Thread.sleep(delay);
- } catch (InterruptedException e) {
- }
- }
- }
- // System.err.println(id+" end transfer retr "+i);
- }
+ if (!client.deleteFile(remoteFilename)) {
+ logger.warn("Cant delete file active mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ // System.err.println(id+" end transfer retr "+i);
+ }
+ if (!client.transferFile(this.localFilename,
+ this.remoteFilename, true)) {
+ logger.warn("Cant store file active mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ Thread.yield();
+ for (int i = 0; i < this.numberIteration; i++) {
+ logger.info(id + " transfer active retr " + i);
+ if (!client.transferFile(null,
+ this.remoteFilename, false)) {
+ logger.warn("Cant retrieve file active mode " + this.id);
+ FtpClientTest.numberKO.incrementAndGet();
+ return;
+ } else {
+ FtpClientTest.numberOK.incrementAndGet();
+ if (delay > 0) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
}
+ }
}
- } finally {
- // System.err.println(id+" disconnect");
- client.logout();
- // System.err.println(id+" end disconnect");
+ // System.err.println(id+" end transfer retr "+i);
+ }
}
+ }
+ String[] results = client.executeSiteCommand("XCRC " + remoteFilename);
+ for (String string : results) {
+ logger.warn("XCRC: {}", string);
+ }
+ results = client.executeSiteCommand("XMD5 " + remoteFilename);
+ for (String string : results) {
+ logger.warn("XCRC: {}", string);
+ }
+ results = client.executeSiteCommand("XSHA1 " + remoteFilename);
+ for (String string : results) {
+ logger.warn("XCRC: {}", string);
+ }
+ results = client.listFiles();
+ for (String string : results) {
+ logger.warn("LIST: {}", string);
+ }
+ } finally {
+ logger.warn(id + " disconnect {}:{}", FtpClientTest.numberOK.get(),
+ FtpClientTest.numberKO.get());
+ client.logout();
+ logger.info(id + " end disconnect");
}
+ }
}
diff --git a/src/test/resources/authent.xml b/src/test/resources/authent.xml
new file mode 100644
index 0000000..9297c00
--- /dev/null
+++ b/src/test/resources/authent.xml
@@ -0,0 +1,23 @@
+
+
+ fredo
+ fred1
+ a
+ b
+ c
+ d
+ 1
+
+
+ fred
+ fred2
+ a
+ b
+ c
+ d
+
+
+ test
+ test
+
+
\ No newline at end of file
diff --git a/src/test/resources/config.xml b/src/test/resources/config.xml
new file mode 100644
index 0000000..adcce94
--- /dev/null
+++ b/src/test/resources/config.xml
@@ -0,0 +1,21 @@
+
+ Example of config file: change its as your need.
+ abcdef
+ 2021
+ /tmp/GGFTP
+ 10
+ 102400
+ 1024000
+ 0
+ 0
+ 10000
+ 0
+ 0
+ 0
+ 65536
+
+ 3001
+ 32000
+
+ src/test/resources/authent.xml
+
\ No newline at end of file
diff --git a/src/test/resources/config2.xml b/src/test/resources/config2.xml
new file mode 100644
index 0000000..f959729
--- /dev/null
+++ b/src/test/resources/config2.xml
@@ -0,0 +1,21 @@
+
+ Example of config file: change its as your need.
+ abcdef
+ 2022
+ /tmp/GGFTP
+ 10
+ 102400
+ 1024000
+ 0
+ 0
+ 10000
+ 0
+ 0
+ 0
+ 65536
+
+ 3001
+ 32000
+
+ src/test/resources/authent.xml
+
\ No newline at end of file
diff --git a/src/test/resources/sslconfig.xml b/src/test/resources/sslconfig.xml
new file mode 100644
index 0000000..3832277
--- /dev/null
+++ b/src/test/resources/sslconfig.xml
@@ -0,0 +1,10 @@
+
+
+ /opt/R66/GGFTP/certs/testsslnocert.jks
+ testsslnocert
+ testalias
+ /opt/R66/GGFTP/certs/testcert.jks
+ testcert
+ False
+
+
\ No newline at end of file