0

自上周以来,我一直在与 Apache Commons FTP 库打交道,这真是一种折磨。我无法连接到任何在线 FTP,但这可能是我无法访问的路由器设置故障。无论如何,我使用 IIS 来在我的硬盘上创建本地 FTP。最后我设法连接到这个 FTP。

凉爽的。此 FTP 也适用于 Internet Explorer。

ftpGetCurrentWorkingDirectory() 函数也可以正常工作,返回字符串“/”

但是 listFiles 函数有一个迷恋(第二种方法在调用第一种方法的单独线程中):

    public static void ftpPrintFilesList(String dir_path) {
    try {
        Log.e(TAG, "1");
        FTPFile[] ftpFiles = mFTPClient.listFiles(dir_path);
        int length = ftpFiles.length;
        Log.e(TAG, "2, length: " + length);
        for (int i = 0; i < length; i++) {
            String name = ftpFiles[i].getName();
            boolean isFile = ftpFiles[i].isFile();
            Log.e(TAG, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+ name);
            if (isFile) {
                Log.i(TAG, "File : " + name);
            } else {
                Log.i(TAG, "Directory : " + name);
            }
            Log.e(TAG, "3 ????"+ name);

        }
    } catch (Exception e) {
         Log.e(TAG, "4 ####");
        e.printStackTrace();
    }

}



public void run(){
     if(FTP.ftpConnect(host, user, password, 21))
        {
            DotNetWSActivity.rslt="connected";
        }
        else
        {
            DotNetWSActivity.rslt="disconnected";
        } 
        //DotNetWSActivity.rslt2 = "cookie monster";
        FTP.ftpPrintFilesList(FTP.ftpGetCurrentWorkingDirectory());
        Boolean status1 = FTP.ftpDownload("test.txt", "/storage/sdcard");       
}

日志显示 listFiles 生成了一个被捕获的异常。我试图通过“/”而不是 FTP.ftpGetCurrentWorkingDirectory() 但没有区别。尝试 .toString() 仍然没有。我的本地 ftp 不是空的,有几个文件,它们可以从资源管理器中看到。'FTP' 是一个正确的对象,因为我可以成功连接到我的 FTP。

你知道我对这个库的方法/使用有什么问题吗? 如果我的问题没有答案,
我会考虑使用这个:
http ://www.enterprisedt.com/products/edtftpj/overview.html。




/////////////////////////////////////////
_ ////////////////////////////////////////////////////////////////////////////////////////
_
_ //////
////////////////////////////

10-17 09:51:05.312: I/Choreographer(967): Skipped 45 frames!  The application may be doing too much work on its main thread.

10-17 09:51:33.881: D/gralloc_goldfish(1015): Emulator without GPU emulation detected.

10-17 09:52:00.761: I/Choreographer(1015): Skipped 36 frames!  The application may be doing too much work on its main thread.

**10-17 09:52:52.111: E/(1015): 1**

**10-17 09:52:52.654: E/(1015): 4 ####**

10-17 09:52:52.661: W/System.err(1015): java.net.ConnectException: failed to connect to /127.0.0.1 (port 49867): connect failed: ECONNREFUSED (Connection refused)

10-17 09:52:52.692: W/System.err(1015):     at libcore.io.IoBridge.connect(IoBridge.java:114)

10-17 09:52:52.692: W/System.err(1015):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)

10-17 09:52:52.701: W/System.err(1015):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)

10-17 09:52:52.701: W/System.err(1015):     at java.net.Socket.startupSocket(Socket.java:566)

10-17 09:52:52.711: W/System.err(1015):     at java.net.Socket.tryAllAddresses(Socket.java:127)

10-17 09:52:52.711: W/System.err(1015):     at java.net.Socket.<init>(Socket.java:177)

10-17 09:52:52.711: W/System.err(1015):     at java.net.Socket.<init>(Socket.java:149)

10-17 09:52:52.711: W/System.err(1015):     at javax.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:40)

10-17 09:52:52.721: W/System.err(1015):     at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:502)

10-17 09:52:52.721: W/System.err(1015):     at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2296)

10-17 09:52:52.731: W/System.err(1015):     at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2269)

10-17 09:52:52.731: W/System.err(1015):     at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2046)

10-17 09:52:52.731: W/System.err(1015):     at com.prgguru.android.FTP.ftpPrintFilesList(FTP.java:81)

10-17 09:52:52.741: W/System.err(1015):     at com.prgguru.android.Caller5.run(Caller5.java:25)

10-17 09:52:52.751: W/System.err(1015): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)

10-17 09:52:52.801: W/System.err(1015):     at libcore.io.Posix.connect(Native Method)

10-17 09:52:52.801: W/System.err(1015):     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)

10-17 09:52:52.811: W/System.err(1015):     at libcore.io.IoBridge.connectErrno(IoBridge.java:127)

10-17 09:52:52.831: W/System.err(1015):     at libcore.io.IoBridge.connect(IoBridge.java:112)

10-17 09:52:52.863: W/System.err(1015):     ... 13 more

10-17 09:52:52.891: D/(1015): download failed


当我连接到 FTP 时,已经有一行 mFTPClient.enterLocalPassiveMode();

public static boolean ftpConnect(String host, String username,
        String password, int port) {
    try {
        mFTPClient = new FTPClient();

        mFTPClient.connect(host, port);
        if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
            boolean status = mFTPClient.login(username, password);
            mFTPClient.enterLocalPassiveMode();
            mFTPClient.setFileTransferMode(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);

            return status;
        }
    } catch (Exception e) {
        Log.d(TAG, "Error: could not connect to host " + host);
    }

    return false;
}
4

0 回答 0