gpt4 book ai didi

Android FTP 连接失败

转载 作者:太空宇宙 更新时间:2023-11-03 12:36:49 25 4
gpt4 key购买 nike

我正在尝试使用 FTP 连接服务器并下载文件

但是在 Android 上连接失败,但是当我尝试使用 FileZilla 或 Windows 文件资源管理器连接 FTP 时,它可以工作。背后的原因是什么?

下面是我的代码

class FTPDownload extends AsyncTask<URL , String , Void>{

boolean running = true;

Date today = Calendar.getInstance().getTime();
Format formatter = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
String reportDate = formatter.format(today);


String file = reportDate + "_" + "giant.mp4";

@Override
protected Void doInBackground(URL... params) {
// TODO Auto-generated method stub
Log.d("******", "Background thread starting......");

FTPClient client = new FTPClient();

try {
Log.d("tag" , "arrived");
client.connect("ftp://newrising.win5.siteonlinetest.com");
boolean successLogin = client.login("newrising", "newrising2014cap!");

if(successLogin){
Log.d("tag" , "success");

// Get the files stored on FTP Server and store them into an array of FTPFiles
FTPFile[] files = client.listFiles();
for (FTPFile ftpFile : files) {
// Check the file type and print result
if (ftpFile.getType() == FTPFile.FILE_TYPE) {
System.out.println("File: " + ftpFile.getName() +
"size-> " + FileUtils.byteCountToDisplaySize(
ftpFile.getSize()));
}
}
}else{
Log.d("tag" , "sosad");
}

} catch (IOException e) {
e.printStackTrace();
} finally {
try {
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}

下面是我的 Logcat 报告

06-19 16:22:19.252: W/System.err(15270): java.net.UnknownHostException: Unable to resolve host "ftp://newrising.win5.siteonlinetest.com": Non-recoverable failure in name resolution
06-19 16:22:19.252: W/System.err(15270): at java.net.InetAddress.lookupHostByName(InetAddress.java:426)
06-19`` 16:22:19.252: W/System.err(15270): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
06-19 16:22:19.252: W/System.err(15270): at java.net.InetAddress.getByName(InetAddress.java:295)
06-19 16:22:19.252: W/System.err(15270): at org.apache.commons.net.SocketClient.connect(SocketClient.java:203)
06-19 16:22:19.252: W/System.err(15270): at org.apache.commons.net.SocketClient.connect(SocketClient.java:296)
06-19 16:22:19.252: W/System.err(15270): at com.example.recordandmovie.Main$FTPDownload.doInBackground(Main.java:105)
06-19 16:22:19.252: W/System.err(15270): at com.example.recordandmovie.Main$FTPDownload.doInBackground(Main.java:1)
06-19 16:22:19.252: W/System.err(15270): at android.os.AsyncTask$2.call(AsyncTask.java:264)
06-19 16:22:19.252: W/System.err(15270): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-19 16:22:19.252: W/System.err(15270): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-19 16:22:19.252: W/System.err(15270): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-19 16:22:19.252: W/System.err(15270): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-19 16:22:19.252: W/System.err(15270): at java.lang.Thread.run(Thread.java:856)
06-19 16:22:19.252: W/System.err(15270): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_FAIL (Non-recoverable failure in name resolution)
06-19 16:22:19.262: W/System.err(15270): at libcore.io.Posix.getaddrinfo(Native Method)
06-19 16:22:19.262: W/System.err(15270): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
06-19 16:22:19.262: W/System.err(15270): at java.net.InetAddress.lookupHostByName(InetAddress.java:411)
06-19 16:22:19.262: W/System.err(15270): ... 12 more

最佳答案

试试这个:

client.connect("newrising.win5.siteonlinetest.com"); // Remove `ftp://`

关于Android FTP 连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17186363/

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