[android-developers] Sending file from sdcard to FTP-server?
I have quite simple sounding task. I need to send file "test.txt" from
my sdcard to my ftp-server. And before actual file sending I create
folder "test" on the ftp-server.
I have tried several code snippets that I have found from internet,
but nothing seems to work. What I'm missing here? IS there some errors
in code or do I need to add more permission or some special project
settings to access FTP.
After getting this atom part of application working I can add more
features, like file chooser.
//up.java class
import android.app.Activity;
import android.os.Bundle;
import org.apache.commons.net.ftp.FTPClient;
import java.io.FileInputStream;
public class up extends Activity {
FileInputStream fis = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect("mydomain.com", 21);
ftpClient.login("user", "password");
ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
ftpClient.makeDirectory("test");
String filename = "/sdcard/test.txt";
fis = new FileInputStream(filename);
ftpClient.storeFile(filename, fis);
ftpClient.logout();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
finally
{
try
{
if (ftpClient.isConnected())
{
ftpClient.logout();
ftpClient.disconnect();
}
}
catch (Exception e)
{
// do nothing
}
}
}
}
//Class end
Also in AndroidManifest.xml I have set:
<uses-permission android:name="android.permission.INTERNET" />
do I need to add more permissions?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home