user874747
user874747

Reputation:

Problem when connecting to FTP server through android?

I've an UnknownHostException when i used this method for uploading files from ddms:

try {
SimpleFTP ftp = new SimpleFTP();

// Connect to an FTP server on port 21.
ftp.connect("ftp://*******", 21, "*****", "*****");

// Set binary mode.
ftp.bin();

// Change to a new working directory on the FTP server.
ftp.cwd("web");

// Upload some files.
ftp.stor(new File("data/data/com.android/file/contacts"));


// Quit from the FTP server.
ftp.disconnect();
}
catch (IOException e) {
// Jibble.
}

What is the problem for this method? Anyone clarify me.

Upvotes: 2

Views: 4293

Answers (2)

Kyle Diedrick
Kyle Diedrick

Reputation: 11

There are two major problems with using FTP on the android emulator:

  1. The emulator takes hold of a specific port on the host machine (between 5554 and 5584) to access the internet.

    See http://developer.android.com/guide/developing/tools/emulator.html

  2. FTP communicates on two ports. The initial port (the one the emulator is using) and a secondary data communication port (usually defined by the FTP client and server).

    See http://www.troubleshootingnetworks.com/ftpinfo.html for information on how FTP works.

This means that the initial communication with the FTP server works the way it is intended, but once you are attempting to pass data to / from the server the emulator cannot communicate with the port the FTP server requests because your computer doesn't know what to do with the traffic on that port. See the link above to get a better grasp on FTP communications.

If you want to test FTP on Android you will need to have a device with its own internet connection.

Upvotes: 1

Alex Gitelman
Alex Gitelman

Reputation: 24722

Cursory look at SimpleFTP example suggests that you need to use host name without ftp:// prefix. Also make sure that you include INTERNET permission in manifest.

Upvotes: 0

Related Questions