Reputation: 3061
I am trying to read data from a file from ftp server. This piece of code works perfectly in java when i run from my desktop computer. I copied over the same code to android and i am getting an exception. The Exception is:
java.io.IOException: Unable to connect to server: Unable to retrieve file: 550
I have no idea why it is occurring when the same code is working perfecty in java. The java code is:
String s = "ftp://username:[email protected]:21/sg1996text.txt;type=i";
URL u;
String f="";
try {
u = new URL(s);
URLConnection uc=u.openConnection();
BufferedInputStream bis=new BufferedInputStream(uc.getInputStream()); //This is where exception i raised.
System.out.println("IS opened");
int i;
while((i=bis.read())!=-1)
f=f+(char)i;
System.out.println("File Read");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 0
Views: 3154
Reputation: 57388
Error 550 usually means "permission error", so the most likely cause is username/password mismatch (but see case #3).
Yet, if the same code works on your desktop, username and password ought to be correct. The possibilities I see are:
ftp.mysite.x10.mx
but to somewhere else, e.g. a development installation on localhost (I did this once; took me some time to figure it out). Try changing the server name to its IP address.Upvotes: 0
Reputation: 336
Remove:
;type=i
from your URL:
String s = "ftp://username:[email protected]:21/sg1996text.txt;type=i";
It works in my application.
Upvotes: 1