logo       

[jira] Resolved: (NET-287) Implicit SSL issue with EFT Server: msg#00343

issues-commons-apache

Subject: [jira] Resolved: (NET-287) Implicit SSL issue with EFT Server


[
https://issues.apache.org/jira/browse/NET-287?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Ryan McV resolved NET-287.
--------------------------

Resolution: Fixed

I found out that the server needed a PROT P command. All better :D

> Implicit SSL issue with EFT Server
> ----------------------------------
>
> Key: NET-287
> URL: https://issues.apache.org/jira/browse/NET-287
> Project: Commons Net
> Issue Type: Bug
> Environment: I am using Windows XP sp3, and am running the demo
> version of EFT Server. If it matters, I am using Eclipse to write and run the
> code.
> Reporter: Ryan McV
>
> I am trying to write some code that will download a file from a FTPS Server.
> When I tested the code in explicit mode using the EFT Server, it works fine.
> However, when I switch over to implicit mode, I am able to connect and login,
> but when I try to download a file, It sends back a code 150 saying that it
> was about to open a data connection, but it never does. Here is the exchange:
> {noformat}
> Attempting to connect to localhost
> 220 GlobalSCAPE EFT Server (v. 6.0) * UNREGISTERED COPY *
> Connected to localhost.
> USER test
> 331 Password required for test.
> PASS 1234
> 230-This is an * UNREGISTERED COPY * of GlobalSCAPE EFT Server.
> 230-
> 230 Login OK. Proceed.
> SYST
> 215 UNIX Type: L8
> Remote System is UNIX Type: L8
> PASV
> 227 Entering Passive Mode (127,0,0,1,18,158).
> RETR test.txt
> 150 Opening ASCII mode data connection for test.txt.{noformat}
> after that, nothing happens and eventually the server times out.
> and here is the code:
> {noformat}import javax.net.ssl.*;
> import java.security.*;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> import java.io.PrintWriter;
> import java.security.NoSuchAlgorithmException;
> import java.security.cert.CertificateException;
> import org.apache.commons.net.PrintCommandListener;
> import org.apache.commons.net.ftp.FTPConnectionClosedException;
> import org.apache.commons.net.ftp.FTPReply;
> import org.apache.commons.net.ftp.FTPSClient;
> public class FTPS_Test2 {
> /**
> * @param args
> */
> public static void main(String[] args)
> {
> String server = "localhost";
> String username = "test";
> String password = "1234";
> String remotefile = "test.txt";
> String localfile = "test.txt";
> String protocl = "SSL";
> String keypass = "jkm127012";
> boolean error = false;
>
> FTPSClient ftps = null;
>
> //Initialization
> KeyStore ks = null;
> try
> {
> ks = KeyStore.getInstance("JKS");
> }
> catch (KeyStoreException e1)
> {
> System.err.println("KeyStore Exception");
> e1.printStackTrace();
> }
>
> FileInputStream fis = null;
> try
> {
> fis = new FileInputStream(".keystore");
> ks.load(fis, keypass.toCharArray());
> fis.close();
> }
> catch (FileNotFoundException e)
> {
> System.err.println("File Not Found");
> e.printStackTrace();
> }
> catch (NoSuchAlgorithmException e)
> {
> System.err.println("No Such Algorithm");
> e.printStackTrace();
> }
> catch (CertificateException e)
> {
> System.err.println("Certificate Exception");
> e.printStackTrace();
> }
> catch (IOException e)
> {
> System.err.println("IOException");
> e.printStackTrace();
> }
>
> TrustManagerFactory tmf = null;
> try
> {
> tmf = TrustManagerFactory.getInstance("PKIX");
> tmf.init(ks);
> }
> catch (NoSuchAlgorithmException e1)
> {
> e1.printStackTrace();
> }
> catch (KeyStoreException e)
> {
> e.printStackTrace();
> }
>
> TrustManager tm[] = tmf.getTrustManagers();
>
> //FTPS Initialization
> try
> {
> ftps = new FTPSClient(protocl, true);
> ftps.addProtocolCommandListener(new
> PrintCommandListener(new PrintWriter(System.out)));
> }
> catch (NoSuchAlgorithmException e)
> {
> System.err.println("FTPS Initialization Failed");
> e.printStackTrace();
> System.exit(1);
> }
>
> try
> {
> int reply;
>
> System.out.println("Attempting to connect to " +
> server);
> ftps.setTrustManager(tm[0]);
> ftps.connect(server, 990);
> System.out.println("Connected to " + server + ".");
>
> reply = ftps.getReplyCode();
>
> if(!FTPReply.isPositiveCompletion(reply))
> {
> ftps.disconnect();
> System.err.println("FTP server connection
> failed");
> System.exit(1);
> }
>
> }
> catch (IOException e)
> {
> System.err.println("IOException");
> e.printStackTrace();
>
> if(ftps.isConnected())
> {
> try
> {
> ftps.disconnect();
> }
> catch (IOException f)
> {
> System.err.println("IOException");
> }
> }
> }
>
> //Main
> try
> {
> ftps.setBufferSize(1000);
>
> if (!ftps.login(username, password))
> {
> ftps.logout();
> error = true;
> }
>
>
> System.out.println("Remote System is " +
> ftps.getSystemName());
> ftps.enterLocalPassiveMode();
>
> OutputStream output;
> output = new FileOutputStream(localfile);
> ftps.retrieveFile(remotefile, output);
> output.close();
>
> ftps.logout();
> }
> catch (FTPConnectionClosedException e)
> {
> error = true;
> System.err.println("Server Connection closed");
> e.printStackTrace();
> }
> catch (IOException e)
> {
> error = true;
> e.printStackTrace();
> }
> finally
> {
> if(ftps.isConnected())
> {
> try
> {
> ftps.disconnect();
> }
> catch (IOException f)
> {
>
> }
> }
> }
>
> System.exit(error ? 1 : 0);
> }
> } {noformat}
> I have tested the same code on different servers,and it works fine in
> implicit and explicit modes. However the EFT Server uses a certificate and a
> key file, and all the other servers just use a cerrtificate file. Is there
> some special code I have to use in that case? Or is there some setting in the
> server that I have to set?
> Thanks in advance you for your help.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise