I'm unable to create a dump thread currently.
I did managed to reproduce it locally, and I've attached the code.
Please see it and let me know if you find any issues.
In the sample code I'm using the dbUserManager (as on my server), and trying to
login 100 simultaneous connections.
Another issue i forgot to mention is that when i start the ftp server (as a
standalone) it starts with 1 db connection but after a while it grows to 8.
Is this a normal behavior?
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import java.io.File;
import java.io.FileInputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class TestCommonsNet {
private static Connection conn;
public static void main(String args[]) {
TestCommonsNet test = new TestCommonsNet();
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/abc", "root", "");
Statement stmt = null;
try {
stmt = conn.createStatement();
ResultSet res = stmt.executeQuery("select userid from ftp_user limit 100");
List<String> users = new ArrayList<String>();
while (res.next()) {
String userId = ((Integer) res.getInt("userid")).toString();
users.add(userId);
}
while (true) {
for (String user : users) {
test.uploadFile(user);
}
Thread.sleep(10000);
System.out.println("entering another loop");
}
} catch (SQLException e) {
System.out.println(e);
}
} catch (Exception e) {
System.out.println(e);
}
}
private void uploadFile(final String username) {
new Thread(new Runnable() {
public void run() {
try {
String ftpHost = "10.0.0.8";
String ftpUserName = username;
String ftpPassword = "123";
String ftpRemoteDirectory = "/";
String fileToTransmit = "c:\\data.txt";
//Create a Jakarta Commons Net FTP Client object
FTPClient ftp = new FTPClient();
//A datatype to store responses from the FTP server
int reply;
//
//Connect to the server
//
ftp.connect(ftpHost);
//
// After connection attempt, you should check the reply code to verify
// success.
//
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
try {
ftp.disconnect();
} catch (Exception e) {
System.err.println("Unable to disconnect from FTP server " +
"after server refused connection. " + e.toString());
}
throw new Exception("FTP server refused connection.");
}
System.out.println("Connected to " + ftpHost + ". " + ftp.getReplyString());
//
//Try to login
//
if (!ftp.login(ftpUserName, ftpPassword)) {
throw new Exception("Unable to login to FTP server " +
"using username " + ftpUserName + " " +
"and password " + ftpPassword);
}
// ftp.enterRemotePassiveMode();
System.out.println(ftp.getReplyString());
System.out.println("Remote system is " + ftp.getSystemName());
//
//Set our file transfer mode to either ASCII or Binary
//
//ftp.setFileType(FTP.ASCII_FILE_TYPE);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
//
//Change the remote directory
//
if (ftpRemoteDirectory != null && ftpRemoteDirectory.trim().length() > 0) {
System.out.println("Changing to FTP remote dir: " + ftpRemoteDirectory);
ftp.changeWorkingDirectory(ftpRemoteDirectory);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
throw new Exception("Unable to change working directory " +
"to:" + ftpRemoteDirectory);
}
}
//
//Get the file that we will transfer and send it.
//
File f = new File(fileToTransmit);
System.out.println("Storing file as remote filename: " + f.getName());
boolean retValue = ftp.storeFile(f.getName(), new FileInputStream(f));
if (!retValue) {
throw new Exception("Storing of remote file failed. ftp.storeFile()" +
" returned false.");
}
//
//Get the list of files on the remote server
//
FTPFile files[] = ftp.listFiles();
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
throw new Exception("Unable to get list of files to dowload.");
}
//
//Log if we have nothing to download
//
if (files.length == 0) {
System.out.println("No files are available for download.");
}
//
//Disconnect from the FTP server
//
try {
//ftp.logout();
ftp.disconnect();
} catch (Exception exc) {
System.err.println("Unable to disconnect from FTP server. " + exc.toString());
}
}
catch (Exception e) {
System.err.println("Error: " + e.toString());
}
}
}).start();
System.out.println("Process Complete.");
}
}