FTP客户端类未连接 [英] FTP client class is not connecting

查看:168
本文介绍了FTP客户端类未连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


尝试{
client.connect(32.178.10.121);
client.login(XXX,XXX);

//
//创建要上传文件的InputStream
//
String filename =Touch.dat;
fis = new FileInputStream(filename);

//
//将文件存储到服务器
//
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();
}
}

我已经尝试过了,但每次都会超时的约束例外,并通过其他方式,我成功地获得连接,但nt从这里可能是什么原因。



这是堆栈跟踪:

  java.net.ConnectException:连接超时:在java.net.PlainSocketImpl.socketConnect(本地方法)上连接
在java.net.PlainSocketImpl.doConnect上的
(未知源)在java.net.PlainSocketImpl.connectToAddress上的
未知源)
在java.net.PlainSocketImpl.connect(未知源)
在java.net.SocksSocketImpl.connect(未知源)
在java.net.Socket.connect(未知源)在java.net.Socket.connect上的
(未知源)在java.net.Socket上的
。< init>(Unknown Source)在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)
  FTPClient ftp = new FTPHTTPClient(proxyHost,proxyPort,proxyUser,proxyPassword); 

然后尝试按照您的方式进行连接,并让我知道错误是否消失。


如果错误仍然存​​在,请检查FTP服务器的防火墙设置。还可以尝试从系统连接一些GUI工具,如Filezilla连接到服务器。


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. Also try to connect from the System with some GUI tool like Filezilla to connect to the server.

这篇关于FTP客户端类未连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆