0

I'm developing a game in Android. The game has many levels and a Level Editor. So when a user make a level, the data are saving as Xml file. So I want to upload this Xml file to internet to share the other users. I searhed and tried these below codes. But It didn't work. The whole code like this:

                String FTP_HOST= "185.27.134.11";
                String FTP_USER = "fees0_14042425";
                String FTP_PASS  ="kadi1sd22";

                File f = new File(Environment.getExternalStorageDirectory()+"/kadirGameLevels1/a.png");


                    FTPClient client = new FTPClient();

            try {

                client.connect(FTP_HOST,21);
                client.login(FTP_USER, FTP_PASS);
                client.setType(FTPClient.TYPE_BINARY);
                client.changeDirectory("/levels/");

                client.upload(f, new MyTransferListener());

            } catch (Exception e) {
                e.printStackTrace();
                try {
                    client.disconnect(true);    
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }

But even if I only use this single line, it still stop running. Did I something wrong with is integration or anything else?

       FTPClient client = new FTPClient();
user1391058
  • 265
  • 4
  • 19

1 Answers1

0

Make sure you have the INTERNET permission in your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

This makes sure your app has the right permission to access the internet.

Also don't put any networking code in the main UI thread or you will likely get a NetworkOnMainThreadException.

Instead put all your FTP-connecting/accessing code into an AsyncTask: https://stackoverflow.com/a/6343299/833647

Community
  • 1
  • 1
Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • And the second part of my answer? Is your code in an `AsyncTask`? Are you getting a `NetworkOnMainThreadException`? Maybe if you post the logcat error people will be able to help better...so far I am just guessing :) – Ken Wolf Nov 27 '13 at 06:40