Archived Forum Post

Index of archived forum posts

Question:

CkFtp2Progress not fire callbacks on Android 6.0

Jul 20 '16 at 19:20

Currently use ftp by follow sample https://www.example-code.com/android/ftp_download_with_progress.asp. It's works fine. But on Android 6.0 CkFtp2Progress callbacks not fire. I'm confused. Help me please. Some piece of code

public void loadFile(final int position, final Config.File file, final OnDownloadFileListener listener, final OnDownloadingProgressListener progressListener) {

asyncManager.runAsync(new Runnable() {

@Override

public void run() {

if(file == null || file.file == null) { sendError("", listener); return; }

            CkFtp2 ftp = getFtpClient();
            CustomProgressWatcher progressWatcher = new CustomProgressWatcher(position, file.size
                    , progressListener);
            ftp.put_EventCallbackObject(progressWatcher);

            //  Connect and login to the FTP server.
            boolean success = ftp.ConnectOnly();
            if (!success) {
                sendError(ftp.lastErrorText(), listener);
                return;
            }

            success = ftp.LoginAfterConnectOnly();
            if (!success) {
                sendError(ftp.lastErrorText(), listener);
                ftp.Disconnect();
                return;
            }

            String localFilename = fileNameProvider.getLocalStorageFileName(file);
            String remoteFilename = fileNameProvider.getRemoteFileName(file);

            //  Change to the remote directory where the file is located.
            //  This step is only necessary if the file is not in the root directory
            //  for the FTP account.
            success = ftp.ChangeRemoteDir("remoteDirName");
            if (!success) {
                L.e(ftp.lastErrorText());
                ftp.Disconnect();
                return;
            }

            //  Download the file.
            success = ftp.GetFile(remoteFilename,localFilename);
            if (!success) {
                sendError(ftp.lastErrorText(), listener);
                ftp.Disconnect();
                return;
            } else {
                L.e("File Downloaded = " + file.file);
            }

            DownloadResult result = new DownloadResult();
            result.result = file;
            sendResult(result, listener);

            ftp.put_EventCallbackObject(null);
            ftp.Disconnect();
        }
    });
}

private CkFtp2 getFtpClient() {
    CkFtp2 ftp = new CkFtp2();
    ftp.put_Hostname(CommonConfig.BASE_URL);
    ftp.put_Username(CommonConfig.USER_NAME);
    ftp.put_Password(CommonConfig.USER_PASSWORD);

    ftp.put_HeartbeatMs(300);

    ftp.put_CrlfMode(2);
    ftp.put_PreferIpv6(true);
    ftp.put_AuthTls(true);
    ftp.put_Passive(true);

    return ftp;
}

public class CustomProgressWatcher extends CkFtp2Progress {

private FTPDownloadManagerImpl.OnDownloadingProgressListener listener;
private int position;
private long onePercent;
private long lastByteCount = 0l;

public CustomProgressWatcher(int position, long fileSize,
                             FTPDownloadManagerImpl.OnDownloadingProgressListener listener) {
    this.position = position;
    this.listener = listener;
    onePercent = fileSize / 100;
}

@Override
public void DownloadRate(final long byteCount, long bytesPerSec) {
    super.DownloadRate(byteCount, bytesPerSec);
    final long completion = byteCount / onePercent;
    final long byteTransfered = byteCount - lastByteCount;
    lastByteCount = byteCount;

    L.e("byteCount = " + byteCount);
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            if (listener != null) {
                listener.onProgress(completion, position);
                listener.onByteCount(byteTransfered);
            }
        }
    });
}

}


Answer

I'll have a look as soon as possible..


Answer

Please give this new build a try: http://www.chilkatsoft.com/download/preRelease/chilkat-9.5.0-android.zip

I tested it, and everything seems to be working. Also.. to be sure events are working and it's not just a problem with DownloadRate (or the code within your DownloadRate handler), add a method for ProgressInfo to see if you get those events. For example:

public class CustomProgressWatcher extends CkFtp2Progress {
...
  public void ProgressInfo(String name, String value)
    {
    ...
    return;
    }
};