I am trying to connect to an FTP server in an Android application and I believe that I fall in an infinite loop, but can't understand why. The library I am using is Apache Comomns net.
I have the internet permission in manifest :
<uses-permission android:name="android.permission.INTERNET"/>
I am also connecting to the FTP in an AsyncTask.
Here is a sample code which was supposed to work :
// I have other values when I test it of course
FTPClient ftpClient = new FTPClient();
ftpClient.connect("111.111.111.111"); // It stops working here when in 4G
ftpClient.login("user", "mdp");
ftpClient.changeWorkingDirectory("directory");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
ftpClient.logout();
ftpClient.disconnect();
It works on Wifi (and my real application works too in wifi) but when I use my 4G (or 3G) it seems to loop at the line where I try to connect() forever.
I have tryed to understand what there is behind this but it's not clear for me.
How can I connect to my FTP using 4G?
Any help would be appreciated.
It sounds like your network operator may have the FTP port blocked.
To test this you can try to ftp to the same site on a browser in your mobile device - if it works then it point to an issue in your app.
If it does not work then try with a known working FTP site - Tele2 host a test site for example (there are lot of other open FTP sites if you do a quick search):
ftp://speedtest.tele2.net
If you can't access this from your mobile device over 4G then it looks very likely that your operator has FTP, and you should contact them to find out why and what you can do to remove the block.
Related
I am running Django on my raspberry-pi, and I am using avahi-daemon to access my rpi on raspberrypi.local . On my Django I have made APIs for my android application to access via HTTP protocol. For example one of my http request url is: http://raspberrypi.local/api/getUserNames/
The problem is that android is not accessing this url on my local wifi network, i have confirmed that my android device and rpi are both connected to same wifi network, but still the http://raspberrypi.local is not working on android. While it works fine on my PC & MAC.
I tried to find the solution and went through many Q&A explaining about bonjour, mDNS, jmDNS, android-multicast. But all are either too confusing to implement or doesn't work. Please help me, I'm stuck for a while.
NOTE: on my Rpi the avahi-daemon is broadcasting itself as "_workstation._tcp." service-type
--
My Solution:
http://www.dodgycoder.net/2015/02/setting-up-bonjourzeroconfmdnsnsd.html
Android NSD (Network Service Discovery) solved my problem. I used only Discovery Listener and Resolve Listener to solve my purpose.
I specifically used SERVICE_TYPE = "_workstation._tcp."; in order to search for raspberrypi.local with avahi-daemon
Android NSD (Network Service Discovery) solved my problem. I used only Discovery Listener and Resolve Listener to solve my purpose.
NOTE- You'll have to use SERVICE_TYPE = "_workstation._tcp."; in order to search for raspberrypi.local with avahi-daemon
here's link to the solution - http://www.dodgycoder.net/2015/02/setting-up-bonjourzeroconfmdnsnsd.html
i'm developing a small example about socket connection between android and ios (via wifi), after trying, the connection hasn't been established. Here is what I have done so far, I created a server on ios (used Bonjour to publish the service). I also created a client on android. However, after starting the server on ios, I also got the log:
ServerSocketConnection[3487:c07] Bonjour Service Published: domain(local.) type(_serversocket._tcp.) name(Macmini) port(54065)
Which means the server starting ok.
To the client part(android), I created the client through Socket class, some few lines of code:
Socket s = new Socket("local.", 54065);
OutputStream out = s.getOutputStream();
PrintWriter output = new PrintWriter(out);
output.println("Hello Android!");
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
String st = input.readLine();
Putting it into AsyncTask to execute. However, I got the UnknowHostException:
08-06 12:45:44.460: W/System.err(873): java.net.UnknownHostException: Unable to resolve host "local.": No address associated with hostname
I'm a newbie to this kind of problem so any ideas what the problem is? I know it's related to the "host" thing but need the way to fix it.
*Note: I run 2 apps on 2 simulators (ios and android) as the same wifi network and same MAC, maybe this is the problem? any help would be appreciated and sorry for my English, it's not my native one.
Use the actual IP address of the iPhone instead of 'local.'.
On Android you can find a phone's IP via Settings -> WiFi -> Advanced. Not sure if iPhone offers the same option.
ps. Also be sure to have the internet permission in your manifest;
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
I have the android FTPserver app running on my android mobile under Tethering mode. I connected to my mobiles network from my laptop and tried to connect to mobile via FTP to access few files. I wrote a python code that uses the ftp connection to transfer files but I am unable to perform simple connection.
I keep getting this error
in windows:
server.gaierror: [Errno 11004] getadderinfo failed
in linux:
socket.gaierror: [Errno -2] Name or service not known
I searched so many places but never found a proper solution. All I could findout was people suggesting to check the firewall. I checked the firewall settings and everything and still I get the problem.
When I use a client software (filezilla) it does get connected.
I am a newbie to python could someone possibly tell me where I am going wrong?
here is my simple connecting code:
import os
from ftplib import FTP
ftp = FTP("192.168.43.1,5002")
ftp.login("usrid","pwd")
I am unable to connect to a general ftp test site, Here is the code for that:
from ftplib import FTP
ftp = FTP('ftp.cwi.nl')
ftp.login("anonymous","anonymous#")
ftp.retrlines('LIST')
do this:
ftp = FTP()
ftp.connect("192.168.43.1", 5002)
instead of:
ftp = FTP("192.168.43.1,5002")
because you can't give non-standard port number to the constructor.
Code:
from ftplib import FTP
ftp = FTP()
ftp.connect("192.168.43.1", 5002)
ftp.login("usrid", "pwd")
ftp.dir()
ftp.close()
I am very new to Android. Our lan is working in class C IP (192.168.1.x series).
I need to establish socket connection between android emulator(Server) and java eclipse (eclipse-java-juno-SR1) which is acting like a client. As I got a information from "http://developer.android.com" website every Android emulator having 10.0.2.15 (Class A IP) by default. But our LAN is working in Class C.
"PC-1" which is using for Android Emulator is having 192.168.1.50 IP, and
the another one "PC-2" which is using for Eclipse-Java is having 192.168.1.55.
This is the setup which I have.
My work is, When I send a string command (through socket) from Android emulator(runing on PC-1) to Java program(runing on PC-2) then that Java program should send continuous jpg photo to Android emulator through socket.
I tried lot but when I try to work with sockets installed apk application is closing by this error: "Unfortunately, Activity name> is closing"
Please help me out in this...
Thanks in advance :)
Does your Application have the
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
in your Manifest - File ?
You can either insert the above line into the manifest xml,
or you can go to "permissions" add "uses permission" and then add the "Internet" one.
My Emulator has no problems opening a Webview to the internet with this permission,
and I can even access my router in my network through the browser in the emulator, which is on some 192.168... address.
Kind Regards and a Happy New Year,
karlheinz
I've an UnknownHostException when i used this method for uploading files from ddms:
try {
SimpleFTP ftp = new SimpleFTP();
// Connect to an FTP server on port 21.
ftp.connect("ftp://*******", 21, "*****", "*****");
// Set binary mode.
ftp.bin();
// Change to a new working directory on the FTP server.
ftp.cwd("web");
// Upload some files.
ftp.stor(new File("data/data/com.android/file/contacts"));
// Quit from the FTP server.
ftp.disconnect();
}
catch (IOException e) {
// Jibble.
}
What is the problem for this method? Anyone clarify me.
There are two major problems with using FTP on the android emulator:
The emulator takes hold of a specific port on the host machine (between 5554 and 5584) to access the internet.
See http://developer.android.com/guide/developing/tools/emulator.html
FTP communicates on two ports. The initial port (the one the emulator is using) and a secondary data communication port (usually defined by the FTP client and server).
See http://www.troubleshootingnetworks.com/ftpinfo.html for information on how FTP works.
This means that the initial communication with the FTP server works the way it is intended, but once you are attempting to pass data to / from the server the emulator cannot communicate with the port the FTP server requests because your computer doesn't know what to do with the traffic on that port. See the link above to get a better grasp on FTP communications.
If you want to test FTP on Android you will need to have a device with its own internet connection.
Cursory look at SimpleFTP example suggests that you need to use host name without ftp:// prefix. Also make sure that you include INTERNET permission in manifest.