我正在尝试连接到 FTP 站点并上传/下载文件。我能够通过浏览器和 FileZilla 进行连接。所以我确信它有效。但是当我尝试通过我的 java 程序访问它时,我得到了这个异常。请任何帮助将不胜感激。
我的 Java 类(构造函数)
public TriFtpClient() {
tri = new FTPClient();
String host = InkAndTonerProperties.getSingleton().getProperty(
"ftpDomain");
int reply;
try {
tri.addProtocolCommandListener(new PrintCommandListener(
new PrintWriter(System.out), true));
tri.connect(host, 21);
log.debug("default port = " + tri.getDefaultPort());
reply = tri.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
tri.disconnect();
log.error("Exception in connecting to FTP Server");
}
tri.login(
InkAndTonerProperties.getSingleton().getProperty(
"ftpUserId"), InkAndTonerProperties.getSingleton()
.getProperty("ftpPassword"));
tri.enterLocalPassiveMode();
} catch (IOException e) {
if (tri.isConnected()) {
log.error("it is connected.");
try {
tri.disconnect();
} catch (IOException f) {
// do nothing
}
}
log.error("Failed to connect and login", e);
}
}
// 上传
方法 // 下载方法
堆栈跟踪
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)