1

我创建了一个端口转发到我的本地(虚拟-> 192.168.1.56)ftpserver。当我尝试使用 FileZilla 从主机(192.168.1.47)连接时,它可以工作:

在此处输入图像描述

当我使用 android 设备尝试时,出现以下错误:

05-18 11:18:00.479: E/Trace(1231): error opening trace file: No such file or directory (2)
05-18 11:18:00.840: D/dalvikvm(1231): GC_FOR_ALLOC freed 37K, 7% free 2412K/2592K, paused 80ms, total 97ms
05-18 11:18:00.900: I/dalvikvm-heap(1231): Grow heap (frag case) to 6.493MB for 4194320-byte allocation
05-18 11:18:00.960: D/dalvikvm(1231): GC_FOR_ALLOC freed 1K, 3% free 6507K/6692K, paused 58ms, total 58ms
05-18 11:18:01.049: D/dalvikvm(1231): GC_CONCURRENT freed <1K, 3% free 6507K/6692K, paused 4ms+4ms, total 89ms
05-18 11:18:02.609: E/sdcard-err2:(1231): println needs a message
05-18 11:18:02.802: V/Error(1231): java.io.IOException: Host attempting data connection 192.168.1.56 is not same as server 92.105.134.53
05-18 11:18:02.802: W/System.err(1231): java.io.IOException: Host attempting data connection 192.168.1.56 is not same as server 92.105.134.53
05-18 11:18:02.809: W/System.err(1231):     at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:525)
05-18 11:18:02.809: W/System.err(1231):     at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2296)
05-18 11:18:02.819: W/System.err(1231):     at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2269)
05-18 11:18:02.819: W/System.err(1231):     at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2046)
05-18 11:18:02.819: W/System.err(1231):     at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2093)
05-18 11:18:02.819: W/System.err(1231):     at spicysoftware.getthepicture.newestPictures.connectFTP(newestPictures.java:232)
05-18 11:18:02.819: W/System.err(1231):     at spicysoftware.getthepicture.newestPictures$2.run(newestPictures.java:116)
05-18 11:18:02.819: W/System.err(1231):     at java.lang.Thread.run(Thread.java:856)
05-18 11:18:02.909: I/Choreographer(1231): Skipped 34 frames!  The application may be doing too much work on its main thread.
05-18 11:18:02.929: D/gralloc_goldfish(1231): Emulator without GPU emulation detected.
05-18 11:18:04.192: I/Choreographer(1231): Skipped 42 frames!  The application may be doing too much work on its main thread.
05-18 11:18:15.121: I/Choreographer(1231): Skipped 43 frames!  The application may be doing too much work on its main thread.
05-18 11:22:08.110: I/Choreographer(1231): Skipped 49 frames!  The application may be doing too much work on its main thread.
05-18 11:22:10.229: I/Choreographer(1231): Skipped 230 frames!  The application may be doing too much work on its main thread.

代码:

它崩溃了

**Log.v("FTP STATUS: ",ftpClient.getStatus());**

public void connectFTP(String host, String username, String password){

    try {
        ftpClient = new FTPClient();
        while (ftpClient.isConnected()==false){
            ftpClient.connect(host, 49501);
            ftpClient.login(username, password);
            ftpClient.enterLocalPassiveMode();
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        }
        ftpClient.changeWorkingDirectory("/thumbs");

        try{
        //HERE IT IS CRASHING.....
        Log.v("FTP STATUS: ",ftpClient.getStatus());
        }catch(Exception ex){
            String err = (ex.getMessage()==null)?"SD Card failed":ex.getMessage();
            Log.e("sdcard-err2:",err); 
        }


        FTPFile[] files = ftpClient.listFiles();
        insert_arraylist = "";
        for (FTPFile file : files) {
            imageNames.add(file.getName());
        }

}
4

1 回答 1

0

您的服务器要求客户端(Filezilla 或您的 Java 代码)连接到内部 IP 地址192.168.1.56以进行数据传输。

FileZilla 猜测服务器位于防火墙/端口转发/其他(不会说德语,但我相信这就是“Vom Server gesendete Addresse ...”行所说的)。因此 FileZilla 忽略该请求并改为连接到服务器的外部 IP 地址(92.105.*请注意,您忘记在日志中混淆 IP)。

在这种情况下,您的 Java 客户端会引发错误。

检查 Apache FTPClient 的源代码,似乎它应该和 FileZilla 一样,至少从 3.1 开始。你用的是什么版本?

/**
 * @since 3.1
 */
protected void _parsePassiveModeReply(String reply)
throws MalformedServerReplyException
{
    java.util.regex.Matcher m = __PARMS_PAT.matcher(reply);
    if (!m.find()) {
        throw new MalformedServerReplyException(
                "Could not parse passive host information.\nServer Reply: " + reply);
    }

    __passiveHost = m.group(1).replace(',', '.'); // Fix up to look like IP address

    try
    {
        int oct1 = Integer.parseInt(m.group(2));
        int oct2 = Integer.parseInt(m.group(3));
        __passivePort = (oct1 << 8) | oct2;
    }
    catch (NumberFormatException e)
    {
        throw new MalformedServerReplyException(
                "Could not parse passive port information.\nServer Reply: " + reply);
    }

    try {
        InetAddress host = InetAddress.getByName(__passiveHost);
        // reply is a local address, but target is not - assume NAT box changed the PASV reply
        if (host.isSiteLocalAddress()) {
            InetAddress remote = getRemoteAddress();
            if (!remote.isSiteLocalAddress()){ 
                String hostAddress = remote.getHostAddress();
                fireReplyReceived(0,
                            "[Replacing site local address "+__passiveHost+" with "+hostAddress+"]\n");
                __passiveHost = hostAddress;                    
            }
        }
    } catch (UnknownHostException e) { // Should not happen as we are passing in an IP address
        throw new MalformedServerReplyException(
                "Could not parse passive host information.\nServer Reply: " + reply);
    }
}

或者,您可以告诉(配置)您的服务器它的外部 IP 地址是什么,以便它使用它而不是内部 IP 地址。

于 2013-05-20T09:05:32.940 回答