Well the first issue is that you are making a network request on the main UI thread. This will block the thread until the network operation completes and might make your program close.
I suggest you start by reading this: http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html You also haven't told us what kind of error you are getting and what behavior you are seeing on the ftp server itself. On Sat, Mar 12, 2011 at 5:16 AM, dappa <dappa...@gmail.com> wrote: > 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+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- ~ Jeremiah:9:23-24 Android 2D MMORPG: http://solrpg.com/ http://www.youtube.com/user/revoltingx -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en