【发布时间】:2016-01-30 22:09:49
【问题描述】:
我目前正在尝试为 android (java) 应用程序进行一些网络编码,但遇到了一些问题。我使用 Apache 库 commons.net 来建立与我托管的服务器的 ftp 连接,以便将文件传输到 android 单元。这是我的代码:
public class Server {
public static void main(String[] args)
{
String username = "Username";
String password = "Password";
String host = "AddressString";
FTPSClient ftps;
ftps = new FTPSClient();
System.out.println("trying to connect...");
try{
System.out.println("trying to connect...");
ftps.connect(host, 21);
System.out.println("Connected");
System.out.println("logging in...");
ftps.login(username, password);
System.out.println("logged in!");
ftps.enterLocalPassiveMode();
catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if (ftps.isConnected()) {
System.out.print("LOggin out");
ftps.logout();
ftps.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
System.out.println("Terminated");
}
}
程序永远不会通过“ftps.connect(host, 21);”这一行,出现错误“连接关闭且没有指示”,我相信我已经正确配置了我的服务器,因为我可以通过“Putty”连接到它" 来自另一个网络等。我在这里缺少什么?
注意:我没有尝试通过 Android 设备进行连接,我目前正在使用 eclipse 进行测试。
【问题讨论】:
-
我显然有点不耐烦,我想我找到了问题所在。我是整个网络的新手,似乎我将 sftp 与 ftps 混淆了,我认为这个库不支持 sftp,所以我将尝试使用 JSch。
标签: java ftp apache-commons-net