简体   繁体   English

FTP客户端类未连接

[英]FTP client class is not connecting

FTPClient client = new FTPClient();
FileInputStream fis = null;


try {
    client.connect("32.178.10.121");
    client.login("XXX", "XXX");

    //
    // Create an InputStream of the file to be uploaded
    //
    String filename = "Touch.dat";
    fis = new FileInputStream(filename);

    //
    // Store file to server
    //
    client.storeFile(filename, fis);
    client.logout();
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        if (fis != null) {
            fis.close();
        }
        client.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

I have tried this but each time it gives time out of bound exception and by other means of i am successfully getting connected but nt from here what could be reason. 我已经尝试了这个,但每次它给出时间超出约束的异常,并通过其他方式我成功连接但是从这里可能是理由。

this is the stacktrace: 这是堆栈跟踪:

java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.apache.commons.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:53)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:162)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:250)
    at forTesting.FileUploadDemo.main(FileUploadDemo.java:15)

First try to set the proxy details like below 首先尝试设置代理详细信息,如下所示

FTPClient ftp = new FTPHTTPClient(proxyHost, proxyPort, proxyUser, proxyPassword);

Then try to connect as you are doing and let me know if the error is gone. 然后尝试连接,如果错误消失,请告诉我。
If the error persists then check the firewall setting for the FTP server. 如果错误仍然存​​在,请检查FTP服务器的防火墙设置。 Also try to connect from the System with some GUI tool like Filezilla to connect to the server. 还尝试使用某些GUI工具(如Filezilla)连接系统以连接到服务器。

You might want to try using PASV mode, if you're behind a firewall or proxy. 如果您位于防火墙或代理之后,您可能想尝试使用PASV模式。 Have a look here : 看看这里

In situations where the client is behind a firewall and unable to accept incoming TCP connections, passive mode may be used. 在客户端位于防火墙后面并且无法接受传入TCP连接的情况下,可以使用被动模式。 In this mode, the client uses the control connection to send a PASV command to the server and then receives a server IP address and server port number from the server, which the client then uses to open a data connection from an arbitrary client port to the server IP address and server port number received. 在此模式下,客户端使用控制连接向服务器发送PASV命令,然后从服务器接收服务器IP地址和服务器端口号,然后客户端使用该端口号打开从任意客户端端口到服务器的数据连接。收到的服务器IP地址和服务器端口号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM