• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps FTP client working on 2.3 - doesn;t work on 4.1

avip

Lurker
Sep 25, 2013
2
0
It works great on Android ver 2.3 but fail on Android 4.1
It is stuck right after the first attempt to connect: client.connect(FTP_HOST,21);

What is the problem????


package com.androidexample.ftpdemo;

import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.FTPDataTransferListener;
import java.io.File;

import com.kpbird.ftpdemo.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;


public class FtpUpload extends Activity {

int flag=0;

/********* work only for Dedicated IP ***********/
static final String FTP_HOST= "66.220.9.50";

/********* FTP USERNAME ***********/
static final String FTP_USER = "gcampob";

/********* FTP PASSWORD ***********/
static final String FTP_PASS ="a12b34avi";

//Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// btn = (Button) findViewById(R.id.button1);
// btn.setOnClickListener(this);
File f = new File("/mnt/sdcard/DCIM/dropbox/pic.jpg");

// Upload sdcard file
uploadFile(f);

}



public void uploadFile(File fileName){


FTPClient client = new FTPClient();

try {
Toast.makeText(getBaseContext(), " Start", Toast.LENGTH_SHORT).show();
Toast.makeText(getBaseContext(), " Start...", Toast.LENGTH_SHORT).show();
client.connect(FTP_HOST,21);
Toast.makeText(getBaseContext(), " Start 1", Toast.LENGTH_SHORT).show();
client.login(FTP_USER, FTP_PASS);
Toast.makeText(getBaseContext(), " Start 2", Toast.LENGTH_SHORT).show();
client.setType(FTPClient.TYPE_BINARY);
Toast.makeText(getBaseContext(), " Start 3", Toast.LENGTH_SHORT).show();
client.changeDirectory("/Pictures/");
Toast.makeText(getBaseContext(), " Connect", Toast.LENGTH_SHORT).show();
client.upload(fileName, new MyTransferListener());
Toast.makeText(getBaseContext(), " Connecting...", Toast.LENGTH_SHORT).show();

} catch (Exception e) {
e.printStackTrace();
try {
client.disconnect(true);
} catch (Exception e2) {
e2.printStackTrace();
}
}



}

/******* Used to file upload and show progress **********/

public class MyTransferListener implements FTPDataTransferListener {

public void started() {
Toast.makeText(getBaseContext(), " first step ...", Toast.LENGTH_SHORT).show();
// btn.setVisibility(View.GONE);
// // Transfer started
Toast.makeText(getBaseContext(), " Upload Started ...", Toast.LENGTH_SHORT).show();
//System.out.println(" Upload Started ...");
flag =1;
}

public void transferred(int length) {

// Yet other length bytes has been transferred since the last time this
// method was called
Toast.makeText(getBaseContext(), " transferred ..." + length, Toast.LENGTH_SHORT).show();
//System.out.println(" transferred ..." + length);
flag =2;
}

public void completed() {

// btn.setVisibility(View.VISIBLE);
// Transfer completed

Toast.makeText(getBaseContext(), " completed ...", Toast.LENGTH_SHORT).show();
//System.out.println(" completed ..." );
flag =3;
finish();
System.exit(0);
}

public void aborted() {

// btn.setVisibility(View.VISIBLE);
// Transfer aborted
Toast.makeText(getBaseContext()," transfer aborted , please try again...", Toast.LENGTH_SHORT).show();
//System.out.println(" aborted ..." );
flag =4;
finish();
System.exit(0);
}

public void failed() {

// btn.setVisibility(View.VISIBLE);
// Transfer failed
// System.out.println(" failed ..." );
flag =5;
finish();
System.exit(0);
}


}


}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones