Search code examples
javaftps

Connection Reset while Transfering files over FTPS using java


I am using Java(Zehon) to transfer files over FTPS. This is my code snippet.

try {
FTPsClient ftpClient = new FTPsClient(host, port,username ,password ,false,keyStorePath,keyStorePass);
ftpClient.sendFile(absFilePath, ftpsFolder);
}catch (FileTransferException e) {e.printStackTrace();}

I have telnet the host ip and i am getting connected. I am quite sure that the credentials i am passing is correct.The exception am getting is com.zehon.exception.FileTransferException: java.net.SocketException: Connection reset Any suggestions as to what else i may need to add while connecting to the host because the javadoc for FTPsClient does not show any more methods to connect to the host.


Solution

  • The Problem was with configuring the keystore file. This is how you actually need to make it: Download OPENSSL and type this command

    openssl pkcs12 -export -in  /path/to/YourVeriSignSSLCert.crt -inkey /path/to/YourPrivateKey.key -out mycert.p12 -name tomcat -CAfile /path/to/YourIntermediateCertificate.cer -caname root
    

    YourVeriSignSSLCert.crt is your current openssl certificate

    YourPrivateKey.key is your current private key

    YourIntermediateCertificate.cer is the VeriSign Intermediate CA

    The exported keystore will be in 'mycert.p12'

    Now the keystore file is of pkcs12 format i am converting this into jks format :

    keytool -v -importkeystore -trustcacerts -srckeystore mycert.p12 -srcstoretype PKCS12 -destkeystore md_keystore.jks -deststoretype JKS
    

    Now this is the keystore file that needs to be passed to the program.