Two Laptop Bag
The moose likes Android and the fly likes Android Eclipse Emulator and FTP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Android Eclipse Emulator and FTP" Watch "Android Eclipse Emulator and FTP" New topic

Android Eclipse Emulator and FTP

Paul Kinzelman

Joined: Aug 15, 2011
Posts: 3
I'm interested in doing just a simple FTP 'get' in my app. It works fine on the Palm Pre and WPF/C# and windows, but not the Android at least on the emulator and I can't find any examples from the searching I've done. I tried a simple:

but it gets an exception on getInputStream: Unable to connect to server: Unable to configure data port

And I know internet access works because I can do an http protocol request. I have the magical incantation in the manifest file to allow network access:
<uses-permission android:name="android.permission.INTERNET" />

Also, there must be a more intelligent way to pull the data out of the stream buffer than byte-by-byte, isn't there? I can't find that either.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
I wouldn't rely on the URL ftp: scheme to work. The Apache Commons Net library has FTP client classes built in, and it works just fine on Android.
Paul Kinzelman

Joined: Aug 15, 2011
Posts: 3
Too bad, the ftp URL scheme works fine on webOS and WPF/C#.

Could you please be a bit more specific about how to do what you suggest?
And how to make it work in the Eclipse/Emulator environment?

Would I need to refer a JAR library or something?

I tried the FTPClient library here:
but I can't get it to work either, says "NoClassDefFoundError" as though the library
is not available on the Emulator, but is available on Eclipse - the references get
resolved properly. It there some magical incantation I need in the AndroidManifest
file or something?

Paul Kinzelman

Joined: Aug 15, 2011
Posts: 3
Whew! I finally got it going.

After fixing the library access (Project | Properties | Java Build Path | Libraries | Add JARs...) I fiddled with the calls until it started working. Here's the sequence of my FTPClient calls. It wouldn't work until I set it in passive mode.

I agree. Here's the link:
subject: Android Eclipse Emulator and FTP
It's not a secret anymore!