I am trying to connect to the ftps client server through my Java code. For this, I use the apache commons library. However, I cannot do this. Can anyone help me with this.
The client server uses the FTPS / Implicit SSL connection and uses passive mode for data connections.
My code is as follows:
public static void connectServer(String host, int port, String userName, String password) throws Exception { FTPSClient client = new FTPSClient("SSL", true); String remote = "Contact.xml"; File inFile = new File("C:/Documents/Applications/Contact.xml"); File outFile = new File("C:/Documents/Applications/Sample.xml"); InputStream input = new FileInputStream(inFile); InputStream out = new FileInputStream(outFile); try { if(client.isConnected()){ client.disconnect(); } client.connect(host,990); client.enterLocalPassiveMode(); client.enterRemotePassiveMode(); client.login(userName, password); client.setBufferSize((int)inFile.length()+100); client.completePendingCommand(); System.out.println(client.printWorkingDirectory()); System.out.println(inFile.getAbsolutePath()); client.storeFile(remote, input); out = client.retrieveFileStream("/folder/inputfeed.xml"); client.completePendingCommand(); client.logout(); } catch (Exception e) { e.printStackTrace(); System.err.println(client.getReplyString()); } finally { out.close(); input.close(); client.disconnect(); } }
This code does not cause any exceptions, but I do not see that the file is being copied to the server, nor any data is being copied to my InputStream. Also, the sysout statement to get the working directory returns me the correct directory. I can also connect to the server through Filezilla and WinSCP.
Please help, I'm stuck with this.
thanks
Vivek source share