How can I upload images using FTP on Android?
Asked
Active
Viewed 1.5k times
12
-
possible duplicate of [How do you upload images to an FTP server within an Android app?](http://stackoverflow.com/questions/6464456/how-do-you-upload-images-to-an-ftp-server-within-an-android-app) – Brad Larson Nov 23 '11 at 18:00
-
While the linked duplicate is newer, it has an answer where this question didn't. – Brad Larson Nov 23 '11 at 18:00
-
1Are you asking how would you implement an FTP client in android? Or are you just looking to connect to an FTP server. There seem to be several FTP apps on the market, though if any work or not I have no idea. – Falmarri Jul 07 '10 at 05:09
-
I Want to upload the Images into the server through FTP but I have no code using Android SDK how to upload it. – Amit Jul 07 '10 at 07:16
2 Answers
7
Use SimpleFTP, simply add simpleftp.jar to your classpath and import the package in whichever classes will use it: Download here
import org.jibble.simpleftp.*;
Make sure you use binary mode when uploading images and suchlike, or they may become corrupted.
try
{
SimpleFTP ftp = new SimpleFTP();
// Connect to an FTP server on port 21.
ftp.connect("ftp.somewhere.net", 21, "username", "password");
// 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("webcam.jpg"));
ftp.stor(new File("comicbot-latest.png"));
// You can also upload from an InputStream, e.g.
ftp.stor(new FileInputStream(new File("test.png")), "test.png");
ftp.stor(someSocket.getInputStream(), "blah.dat");
// Quit from the FTP server.
ftp.disconnect();
}
catch (IOException e)
{
e.printStackTrace();
}
This was all the functionality, so it does not let you download files!

RTB
- 5,773
- 7
- 33
- 50
-
@Amit if my anwser helped, please accept it. If not how can we help you furhter? – RTB Jul 19 '12 at 11:22
-
Upvoted, It helped to know there is some lib...Can u please let me know what other API's are available with this Jar/lib\ – AAnkit Jul 31 '12 at 16:30
-
SimpleFTP is licensed under GNU GPL. They provide also a commercial license. – Yar Feb 28 '14 at 07:50
3
Download the FTP Jar Library from Here
public void sendFileViaFTP() {
FTPClient ftpClient = null;
try {
ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName("ftp.myserver.com"));
if (ftpClient.login("myftpusername", "myftppass")) {
ftpClient.enterLocalPassiveMode(); // important!
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
String Location = Environment.getExternalStorageDirectory()
.toString();
String data = Location + File.separator + "FileToSend.txt";
FileInputStream in = new FileInputStream(new File(data));
boolean result = ftpClient.storeFile("FileToSend.txt", in);
in.close();
if (result)
Log.v("upload result", "succeeded");
ftpClient.logout();
ftpClient.disconnect();
}
} catch (Exception e) {
Log.v("count", "error");
e.printStackTrace();
}
}
This will work for sure. I've done this many times.

ARMAGEDDON
- 939
- 3
- 11
- 23
-
This might be a bit late but using this method to upload always returns error code 550(access denied). any suggestions??? – shreyas Jun 13 '14 at 06:20