gpt4 book ai didi

java.net.UnknownHostException 无法连接到 ftp

转载 作者:行者123 更新时间:2023-12-03 01:38:16 25 4
gpt4 key购买 nike

我的 ftp 端口为:ftp://173.201.0.1/

我尝试通过以下方式连接它:

String Ftp_Path = "ftp://173.201.0.1/";


public List<String> GetFileList()

{
String ftpServerIP = Ftp_Path;
String ftpUserID = Ftp_UserName;
String ftpPassword = Ftp_Password;

FTPFile[] downloadFiles = null;

StringBuilder result = new StringBuilder();
FTPClient ftp = new FTPClient();
List<String> xlsFiles = null;

try {
ftp.connect(Ftp_Path);
ftp.login(ftpUserID, ftpPassword);

downloadFiles=ftp.listFiles();

xlsFiles = new ArrayList<String>();
for(FTPFile i : downloadFiles) {
if(i.toString().endsWith(".xls")) {
xlsFiles.add(i.toString());
}
}


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return xlsFiles;

}

但是我在网上遇到错误:

ftp.connect(Ftp_Path);

以下是错误。

java.net.UnknownHostException: ftp://173.201.0.1/
at java.net.AbstractPlainSocketImpl.connect(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:92)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:201)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:289)
at com.amazonaws.mws.samples.ImportRulesPropertyClass.GetFileList(ImportRulesPropertyClass.java:33)
at com.amazonaws.mws.samples.ManageReportScheduleSample.main(ManageReportScheduleSample.java:74)

请帮助我。

我是java新手。

最佳答案

你只需要指定IP即可。FTPClient发出ftp请求。它与http请求不同。只需更改

String Ftp_Path = "ftp://173.201.0.1/";

to

String Ftp_Path = "173.201.0.1";

同时检查 ftp 端口是否已启动并可通过 telnet 访问

关于java.net.UnknownHostException 无法连接到 ftp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21985467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com