[android-beginners] Re: Unable to Connect to FTP server

2009-07-01 Thread PJ

I have been banging my head against the very same problem until I
remembered the permission need to be set in the manifest:



That should get you past the error you are having.


On Jun 15, 4:43 pm, Andy Wolpert  wrote:
> Hello All -
>
> I am trying to upload a file from the Android (Emulator or I/O phone)
> and get a cannot connect to server error. I saw a variety of posts,
> but never a solution. The same accounts, URLs and passwords work from
> the shell.
>
> The following code is "Hello Android" extended to call my FTP code.
> (accounts, passwords changed).
> Does FTP upload work?
> Is there a sample to work from?
> Any other ideas?
> (P.S. I would gladly use HTTP instead but found that more confusing
> and got a different error. So a sample there would be great as well).
> - Andy
>
> -- the code follows -
>
> package com.example.helloandroid;
>
> import java.io.FileInputStream;
> import java.io.OutputStream;
> import java.net.URL;
> import java.net.URLConnection;
> import android.app.Activity;
> import android.os.Bundle;
> import android.util.Log;
>
> public class HelloAndroid extends Activity {
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>         try {
>         testFTP();
>         }
>
>         catch (Exception e) {
>                         Log.println(1, "FTP", e.getMessage());
>                         e.printStackTrace();
>                 }
>     }
>
>     protected void testFTP() throws Exception {
>                 final String localfile = 
> "/data/data/com.technomusicology.upload/
> test.mp3";
>                 final String targetfile = "test.mp3";
>                 final String host = "ftp.myhost_here.com";
>                 final String user = "user_here";
>                 final String password = "password_here";
>                 URL url = new URL("ftp://"+ user+ ":"+ password+ "@"+ host + 
> "/"+
> targetfile+ ";type=i");
>                 URLConnection urlc = url.openConnection();
>                 urlc.setDoOutput(true);
>                 // the following line throws "unable to connect to host {0}"
>                 OutputStream os = urlc.getOutputStream();
>                 FileInputStream is=  new FileInputStream(localfile);
>
>            byte[] buf= new byte[16384];
>            int c;
>            while (true) {
>                    c= is.read(buf);
>                    if (c<= 0)  break;
>                    os.write(buf, 0, c);
>            }
>            os.close();
>            is.close();
>            urlc = null; // close
>     }
>
> }
>
> // here is more information on the exception
> this    HelloAndroid  (id=830058643256)
> savedInstanceState      null
> e       IOException  (id=830058667280)
>         cause   IOException  (id=830058667280)
>         detailMessage   "Unable to connect to server: {0}" (id=830058746592)
>         stackState      int[]  (id=830058792560)
>         stackTrace      null

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Unable to Connect to FTP server

2009-07-01 Thread Andrew Burgess
I don't think you want URLConnection. I believe you'd actually want to set
up a Socket (http://developer.android.com/reference/java/net/Socket.html)
instead.

I implemented a simple one in C# a while back, and used the code from
http://www.codeproject.com/KB/IP/ftplib.aspx as a guide.

On Mon, Jun 15, 2009 at 4:43 PM, Andy Wolpert wrote:

>
> Hello All -
>
> I am trying to upload a file from the Android (Emulator or I/O phone)
> and get a cannot connect to server error. I saw a variety of posts,
> but never a solution. The same accounts, URLs and passwords work from
> the shell.
>
> The following code is "Hello Android" extended to call my FTP code.
> (accounts, passwords changed).
> Does FTP upload work?
> Is there a sample to work from?
> Any other ideas?
> (P.S. I would gladly use HTTP instead but found that more confusing
> and got a different error. So a sample there would be great as well).
> - Andy
>
> -- the code follows -
>
> package com.example.helloandroid;
>
> import java.io.FileInputStream;
> import java.io.OutputStream;
> import java.net.URL;
> import java.net.URLConnection;
> import android.app.Activity;
> import android.os.Bundle;
> import android.util.Log;
>
> public class HelloAndroid extends Activity {
>/** Called when the activity is first created. */
>@Override
>public void onCreate(Bundle savedInstanceState) {
>super.onCreate(savedInstanceState);
>setContentView(R.layout.main);
>
>try {
>testFTP();
>}
>
>catch (Exception e) {
>Log.println(1, "FTP", e.getMessage());
>e.printStackTrace();
>}
>}
>
>protected void testFTP() throws Exception {
>final String localfile =
> "/data/data/com.technomusicology.upload/
> test.mp3";
>final String targetfile = "test.mp3";
>final String host = "ftp.myhost_here.com";
>final String user = "user_here";
>final String password = "password_here";
>URL url = new URL("ftp://"+ user+ ":"+ password+ "@"+ host
> + "/"+
> targetfile+ ";type=i");
>URLConnection urlc = url.openConnection();
>urlc.setDoOutput(true);
>// the following line throws "unable to connect to host {0}"
>OutputStream os = urlc.getOutputStream();
>FileInputStream is=  new FileInputStream(localfile);
>
>   byte[] buf= new byte[16384];
>   int c;
>   while (true) {
>   c= is.read(buf);
>   if (c<= 0)  break;
>   os.write(buf, 0, c);
>   }
>   os.close();
>   is.close();
>   urlc = null; // close
>}
> }
>
> // here is more information on the exception
> thisHelloAndroid  (id=830058643256)
> savedInstanceState  null
> e   IOException  (id=830058667280)
>cause   IOException  (id=830058667280)
>detailMessage   "Unable to connect to server: {0}" (id=830058746592)
>stackState  int[]  (id=830058792560)
>stackTrace  null
>
> >
>


-- 
Andrew Burgess

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Unable to Connect to FTP server

2009-08-25 Thread engin

I have olsa this error.Did you find solution??

On 1 Temmuz, 18:36, Andrew Burgess  wrote:
> I don't think you want URLConnection. I believe you'd actually want to set
> up a Socket (http://developer.android.com/reference/java/net/Socket.html)
> instead.
>
> I implemented a simple one in C# a while back, and used the code 
> fromhttp://www.codeproject.com/KB/IP/ftplib.aspxas a guide.
>
> On Mon, Jun 15, 2009 at 4:43 PM, Andy Wolpert 
> wrote:
>
>
>
>
>
>
>
> > Hello All -
>
> > I am trying to upload a file from the Android (Emulator or I/O phone)
> > and get a cannot connect to server error. I saw a variety of posts,
> > but never a solution. The same accounts, URLs and passwords work from
> > the shell.
>
> > The following code is "Hello Android" extended to call my FTP code.
> > (accounts, passwords changed).
> > Does FTP upload work?
> > Is there a sample to work from?
> > Any other ideas?
> > (P.S. I would gladly use HTTP instead but found that more confusing
> > and got a different error. So a sample there would be great as well).
> > - Andy
>
> > -- the code follows -
>
> > package com.example.helloandroid;
>
> > import java.io.FileInputStream;
> > import java.io.OutputStream;
> > import java.net.URL;
> > import java.net.URLConnection;
> > import android.app.Activity;
> > import android.os.Bundle;
> > import android.util.Log;
>
> > public class HelloAndroid extends Activity {
> >    /** Called when the activity is first created. */
> >   �...@override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
>
> >        try {
> >        testFTP();
> >        }
>
> >        catch (Exception e) {
> >                        Log.println(1, "FTP", e.getMessage());
> >                        e.printStackTrace();
> >                }
> >    }
>
> >    protected void testFTP() throws Exception {
> >                final String localfile =
> > "/data/data/com.technomusicology.upload/
> > test.mp3";
> >                final String targetfile = "test.mp3";
> >                final String host = "ftp.myhost_here.com";
> >                final String user = "user_here";
> >                final String password = "password_here";
> >                URL url = new URL("ftp://"+ user+ ":"+ password+ "@"+ host
> > + "/"+
> > targetfile+ ";type=i");
> >                URLConnection urlc = url.openConnection();
> >                urlc.setDoOutput(true);
> >                // the following line throws "unable to connect to host {0}"
> >                OutputStream os = urlc.getOutputStream();
> >                FileInputStream is=  new FileInputStream(localfile);
>
> >           byte[] buf= new byte[16384];
> >           int c;
> >           while (true) {
> >                   c= is.read(buf);
> >                   if (c<= 0)  break;
> >                   os.write(buf, 0, c);
> >           }
> >           os.close();
> >           is.close();
> >           urlc = null; // close
> >    }
> > }
>
> > // here is more information on the exception
> > this    HelloAndroid  (id=830058643256)
> > savedInstanceState      null
> > e       IOException  (id=830058667280)
> >        cause   IOException  (id=830058667280)
> >        detailMessage   "Unable to connect to server: {0}" (id=830058746592)
> >        stackState      int[]  (id=830058792560)
> >        stackTrace      null
>
> --
> Andrew Burgess- Alıntıyı gizle -
>
> - Alıntıyı göster -

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---