Question

I have created a portforwarding to my local (virtual-> 192.168.1.56) ftpserver. When I try to connect from host (192.168.1.47) with FileZilla it works:

enter image description here

And when I try it with an android device I have following error:

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.

Code:

It's crashing at

**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());
        }

}
Was it helpful?

Solution

Your server asks the client (Filezilla or your Java code) to connect to internal IP address 192.168.1.56 for data transfer.

FileZilla guesses that the server is behind firewall/port forwarding/whatever (not speaking German, but I believe this is what the "Vom Server gesendete Addresse..." line says). So FileZilla disregards the request and connects to the server's external IP address instead (92.105.*, note that you forgot to obfuscate the IP in the log).

While your Java client throws an error in this situation.

Checking the source code of Apache FTPClient, it seems that it should be doing the same as FileZilla, at least since 3.1. What version are you using?

/**
 * @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);
    }
}

Alternatively, you may be able to tell (configure) your server what is its external IP address, so that it uses that instead of the internal IP address.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top