Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to FTP on Gingerbread

Tags:

android

ftp

I recently noticed that when trying to run my application on the Gingerbread emulation, that FTP broke. I am currently using the apache commons external library for FTP support, but for some reason it works on every other Android OS except 2.3 (Gingerbread)

Here is my FTP code

FTPClient ftp = new FTPClient();
ftp.connect(SERVER);
ftp.login("anonymous", "anonymous");
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();

InputStream is = ftp.retrieveFileStream("file.txt");
byte[] data = new byte[1024];

fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
int x = 0;
while((x=is.read(data,0,1024))>=0){
    fos.write(data,0,x);
}
fos.flush();
fos.close();
ftp.logout();
ftp.disconnect();

As I said, this is tested and works on 1.6, 2.1 and 2.2, but not 2.3. I've tried all day to figure out why and how to fix it but I can't find any solution.

I was therefore wondering if anybody have experience with FTP and Gingerbread and if you might be so nice to guide me in the right direction.

Thanks.

like image 295
ernie Avatar asked Jan 10 '11 14:01

ernie


1 Answers

I don't know what is causing the problem, but I found out that FTP on Android 2.3 does work, but not in emulation.

The moment I tried my code on my cell phone, it worked like it had on all previous versions of Android.

Thanks for all the help!

like image 167
ernie Avatar answered Sep 22 '22 10:09

ernie