1
votes

I trie to connect to a remote server with the FTP from Apache commons library. But i can't connect to this server..i got the exception:

java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at org.apache.commons.net.SocketClient.connect(SocketClient.java:188) at org.apache.commons.net.SocketClient.connect(SocketClient.java:209) at de.download.Info4c.start(Info4c.java:95) at de.download.Info4c.main(Info4c.java:67)

This is my code:

FTPSClient client = new FTPSClient(false);
    client.connect("<IP>",990);     
    int reply =  client.getReplyCode();
    if (FTPReply.isPositiveCompletion(reply)) {
        if(client.login(user, pass)){
            // Set protection buffer size
            client.execPBSZ(0);
            // Set data channel protection to private
            client.execPROT("P");
            // Enter local passive mode
            client.enterLocalPassiveMode();
        }
    }
1
<IP> is supposed to be replaced with the address of the server that you're trying to connect to. Did you mask it out yourself for the sake of posting the question or is it actually "<IP>" that you're using in your program?Neil
@Neil the <IP> tag contains my remote server IP. I don't have any name, just the IP, so on the server i want to connect to there is running windows server 2012, it is just a remote server.user3515460
Always a good idea to try to do ping <IP> to test if the server exists. If it responds, check the port as @duffymo suggests. Otherwise your issue is that from your PC, you cannot see that server. That doesn't necessarily mean that the server is off! It could be firewall or other factors.Neil
try to add run property -Djava.net.preferIPv4Stack=trueCroWell
@user3515460: check with an existing ftps client application you can reach the ftps server. Perhaps it is blocked by a firewall or it is not running on the server.rve

1 Answers

1
votes

If the remote server is behind a firewall, maybe you should use the proper proxy to access it. Have you got a system proxy in your internet options? Then, configure the JVM to use it through the standard Java networking properties.