Android ftp client source code

Android-ftp-client-source-code-featured.jpg

I am working in Windows 7, and I am learning to code for Android.

Android ftp client source code1 Android ftp client source code

I need to create an FTP client to upload and download the files from free FTP servers. I am using “www.drivehq.com”, which is a free ftp space. I need to know whether I can use this kind of free space as my FTP server, or if not, which FTP server can be used?

I have written the following code to login to an FTP server, as well as to upload a file. It doesnt show any errors, but I couldn’t check from the emulator (android 2.2) whether the login was successful. The file is not uploaded, I separately checked through website using my login account in that FTP server.

How should I proceed further? How can I login successfully and upload the file?

FTPClient con = new FTPClient();
try
{
con.connect(“http://www.ftpserver.com”);
if (con.login(“user name”, “password”))
{
con.enterLocalPassiveMode(); // important!
String data = “test data”;
ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());
boolean result = con.storeFile(“/sdcard/abc.jpg”, in);
in.close();
if (result) Log.v(“upload result”, “succeeded”);
//lblResult.setText(“Login successful.”);
}
}
catch (Exception e)
{
e.printStackTrace();
}

try
{
con.logout();
con.disconnect();
}
catch (IOException e)
{
e.printStackTrace();
}
lblResult.setText(“Login successful.”);
else {
lblResult.setText(“Login failed. Username and/or password doesn’t match.”);
}
}
});

i dont know, whether i am getting any exception.

FTPClient con = new FTPClient();
try
{
con.connect(“FTPserver”);
if (con.login(“username”, “password”))
{
lblResult.setText(“Login successful.”);
con.enterLocalPassiveMode();

when i run this it prints “login successful”, it means, i have logged in, isn’t it? but file is not getting uploaded.

String data = “test data”;
ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());
boolean result = con.storeFile(“/text.txt”, in);

what is this test data? “con.storefile”- inside the brackets what i need to fill? whether destination location or path of the source file need to be uploaded.

if it is the path of source file, i have my datas in the sdcard,which i have created virtually for my emulator, using DDMS perspective i loaded the files in sdcard, how can i represent the path of that file, if it is destination location, should i need to include the url of the directory?

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)