commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jthistle <jthis...@jtmconcepts.com>
Subject FTPS Connect Help
Date Tue, 14 Jul 2009 12:41:51 GMT

Hello,
I am trying to use apache commons to connect to my data server using FTPS
over SSL. The code runs fine until it tries to connect to the server
"ftpsClient.connect(server, port);" at which point the code sits there for
several minutes until a socket exception is thrown that says "Connection
Reset", presumably from timing out.  I am using a self-signed certificate if
that makes a difference.  When I connect to the server using Filezilla it
takes just a few seconds to connect using SSL from the same computer I'm
running my java program, so it shouldn't be a network problem.  I've placed
my code below, any help would be greatly appreciated.

Thank you in advance,
-Jordan

--------------------------------------------------------------------------------
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.SocketException;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTPConnectionClosedException;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPSClient;

public class FileTransferFTPS implements IFileTransfer
{
    private FTPSClient ftpsClient;
    boolean tracer = true;
    private String server;
    private String user;
    private String pass;
    private int port;
    private Log log = Main.getLog();
    private int j = 0;
    
    /**
     *  This method tries to connect & logon to the server, and
     *  returns a Boolean true upon success and false upon failure
     *
     *  @param serverName           Name of the server to connect to
     *  @param userName             Username to use
     *  @param password             password to use
     *
     *  @return boolean             true on connected, 
     *                              false if unable to connect
     */
    public boolean connect(String serverName, int connectionPort, String
userName,
            String password) 
    {
        if(tracer) System.out.println("FileTransferFTPS.connect()");
        server = serverName;
        user = userName;
        pass = password;
        port = connectionPort;
        boolean success;
        
        try {
            ftpsClient = new FTPSClient("SSL");
            ftpsClient.addProtocolCommandListener(new
PrintCommandListener(new PrintWriter(System.out)));

        }
        catch (NoSuchAlgorithmException ex) {
            return false;
        }
        
        try {
            /* Can't write to textArea if textArea doesn't exist yet
             * Occurs during a test connection */
            try{
                log.writeTextArea("Connecting...\n");
            }catch(NullPointerException ex){
        }
            
            ftpsClient.connect(server, port);            
            ftpsClient.enterLocalPassiveMode();
            success = ftpsClient.login(user, pass);
        } 
        catch (SocketException ex) {
            System.out.println(ex.getMessage());
            return false;
        } 
        catch (IOException ex) {
            return false;
        }
        
        return success;
    }
-- 
View this message in context: http://www.nabble.com/FTPS-Connect-Help-tp24478702p24478702.html
Sent from the Commons - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message