androidandroid-intentftpdebug-mode

Intent is thrown, but action only done in Debug mode


I am working on an app, that uploads data to an FTP Server, once a Wireless connection is available. The Problem is, that the data is only uploaded if I am in Debug Mode.

            if (sharedpreferences.getBoolean("autoupload",false)){
                // Do your work.
                String directory = context.getFilesDir().getAbsolutePath() + File.separator + "Messdaten";
                File f = new File(directory);
                File[] files = f.listFiles();
                if (files.length != 0 ){
                    for (int i = 0; i < files.length; i++) {
                        String filepath = files[i].toString();
                        FTPupload FTPu = new FTPupload(filepath);
                        FTPu.execute();
                        Toast.makeText(context, "BikeLog Daten werden hochgeladen", Toast.LENGTH_SHORT).show();
                    }
                } 
            }

The Toast Message is shown so I am sure, that everything else should be reached as well. But when I check the data via Device explorer, it is still there although it should be removed after the upload.

class FTPupload extends AsyncTask<Void, Void, String> {
    String path;
    ProgressDialog uploading;

    public FTPupload(String filepath) {
        path = filepath;
    }

    @Override
    protected String doInBackground(Void... params) {
        FTPSClient con = null;

        try {
            con = new FTPSClient();
            con.connect("XXXXXXXX");

            if (con.login("XXXXXXXXXX", "XXXXXXXXXXX")) {
                con.enterLocalPassiveMode(); // important!
                con.setFileType(FTP.BINARY_FILE_TYPE);
                FileInputStream in = new FileInputStream(new File(path));
                String filename = path.substring(path.lastIndexOf("/") + 1);
                boolean result = con.storeFile(filename, in);

                in.close();
                if (result) {
                    Log.v("upload result", "succeeded");
                    File file = new File(path);
                    boolean deleted = file.delete();
                }
                con.logout();
                con.disconnect();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return path;
    }
}

The crazy thing is, that once I plug it into my computer and put a breakpoint into the FTP connection everything works as it was planned and the data is send to the Server.

Can you help me figuring out what is wrong ? Any hint is great!

Edit: This is what Logcat says:

2019-02-13 15:43:01.347 1537-1906/? D/ConnectivityService: Switching to new default network: NetworkAgentInfo{ ni{[type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "ReineLernWG", failover: false, available: true, roaming: false, metered: false]}  network{123}  nethandle{528297413342}  lp{{InterfaceName: wlan0 LinkAddresses: [fe80::f2d7:aaff:fe3c:6a11/64,192.168.178.57/24,]  Routes: [fe80::/64 -> :: wlan0,192.168.178.0/24 -> 0.0.0.0 wlan0,0.0.0.0/0 -> 192.168.178.1 wlan0,] DnsAddresses: [192.168.178.1,] Domains: fritz.box MTU: 0 TcpBufferSizes: 131072,262144,3145728,4096,221184,3145728}}  nc{[ Transports: WIFI Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN LinkUpBandwidth>=1048576Kbps LinkDnBandwidth>=1048576Kbps SignalStrength: -56]}  Score{20}  everValidated{false}  lastValidated{false}  created{true} lingering{false} explicitlySelected{false} acceptUnvalidated{false} everCaptivePortalDetected{false} lastCaptivePortalDetected{false} }
2019-02-13 15:43:01.355 18331-18450/online.simpledesign.bikelog W/System.err: java.net.UnknownHostException: webhosting31.1blu.de
2019-02-13 15:43:01.355 18331-18450/online.simpledesign.bikelog W/System.err:     at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:183)
2019-02-13 15:43:01.355 18331-18450/online.simpledesign.bikelog W/System.err:     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
2019-02-13 15:43:01.355 18331-18450/online.simpledesign.bikelog W/System.err:     at java.net.Socket.connect(Socket.java:586)
2019-02-13 15:43:01.355 18331-18450/online.simpledesign.bikelog W/System.err:     at org.apache.commons.net.SocketClient.connect(SocketClient.java:176)
2019-02-13 15:43:01.356 18331-18450/online.simpledesign.bikelog W/System.err:     at org.apache.commons.net.SocketClient.connect(SocketClient.java:268)
2019-02-13 15:43:01.356 18331-18450/online.simpledesign.bikelog W/System.err:     at online.simpledesign.bikelog.FTPupload.doInBackground(WifiUploader.java:67)
2019-02-13 15:43:01.356 18331-18450/online.simpledesign.bikelog W/System.err:     at online.simpledesign.bikelog.FTPupload.doInBackground(WifiUploader.java:53)
2019-02-13 15:43:01.356 18331-18450/online.simpledesign.bikelog W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:304)
2019-02-13 15:43:01.356 18331-18450/online.simpledesign.bikelog W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
2019-02-13 15:43:01.356 18331-18450/online.simpledesign.bikelog W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
2019-02-13 15:43:01.356 18331-18450/online.simpledesign.bikelog W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
2019-02-13 15:43:01.357 18331-18450/online.simpledesign.bikelog W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
2019-02-13 15:43:01.357 18331-18450/online.simpledesign.bikelog W/System.err:     at java.lang.Thread.run(Thread.java:761)
2019-02-13 15:43:01.357 18331-18450/online.simpledesign.bikelog D/exception: java.net.UnknownHostException: webhosting31.1blu.de
2019-02-13 15:43:01.359 18331-18454/online.simpledesign.bikelog W/System.err: java.net.UnknownHostException: webhosting31.1blu.de
2019-02-13 15:43:01.359 18331-18454/online.simpledesign.bikelog W/System.err:     at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:183)
2019-02-13 15:43:01.359 18331-18454/online.simpledesign.bikelog W/System.err:     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
2019-02-13 15:43:01.360 18331-18454/online.simpledesign.bikelog W/System.err:     at java.net.Socket.connect(Socket.java:586)
2019-02-13 15:43:01.360 18331-18454/online.simpledesign.bikelog W/System.err:     at org.apache.commons.net.SocketClient.connect(SocketClient.java:176)
2019-02-13 15:43:01.360 18331-18454/online.simpledesign.bikelog W/System.err:     at org.apache.commons.net.SocketClient.connect(SocketClient.java:268)
2019-02-13 15:43:01.360 18331-18454/online.simpledesign.bikelog W/System.err:     at online.simpledesign.bikelog.FTPupload.doInBackground(WifiUploader.java:67)
2019-02-13 15:43:01.360 18331-18454/online.simpledesign.bikelog W/System.err:     at online.simpledesign.bikelog.FTPupload.doInBackground(WifiUploader.java:53)
2019-02-13 15:43:01.360 18331-18454/online.simpledesign.bikelog W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:304)
2019-02-13 15:43:01.360 18331-18454/online.simpledesign.bikelog W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
2019-02-13 15:43:01.360 18331-18454/online.simpledesign.bikelog W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
2019-02-13 15:43:01.361 18331-18454/online.simpledesign.bikelog W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
2019-02-13 15:43:01.361 18331-18454/online.simpledesign.bikelog W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
2019-02-13 15:43:01.361 18331-18454/online.simpledesign.bikelog W/System.err:     at java.lang.Thread.run(Thread.java:761)
2019-02-13 15:43:01.361 18331-18454/online.simpledesign.bikelog D/exception: java.net.UnknownHostException: webhosting31.1blu.de

Solution

  • This could be a timing problem. In debug mode, everything runs slower, and if you have a breakpoint, execution stops at the breakpoint. This may give time to other threads to do other things and this hides the problem. It seems clear from the logcat that your server is not reachable by the device. The error "UnknownHostException" indicates that the DNS resolution for "webhosting31.1blu.de" is not returning an IP address. This means that you aren't connected to the Internet, or that the DNS configuration is broken.

    If you think this is some kind of timing problem, you could add some delay before you try to upload the data, or you could add some retry functionality that waits a while and tries again if the upload fails.