I'm currently trying to do some network coding for an android (java) application and I'm facing some problems. I use the Apache library commons.net in order to establish an ftp connection to a server I'm hosting for file transfer to the android unit. this is my code:
public class Server {
public static void main(String[] args)
{
String username = "Username";
String password = "Password";
String host = "AddressString";
FTPSClient ftps;
ftps = new FTPSClient();
System.out.println("trying to connect...");
try{
System.out.println("trying to connect...");
ftps.connect(host, 21);
System.out.println("Connected");
System.out.println("logging in...");
ftps.login(username, password);
System.out.println("logged in!");
ftps.enterLocalPassiveMode();
catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if (ftps.isConnected()) {
System.out.print("LOggin out");
ftps.logout();
ftps.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
System.out.println("Terminated");
}
}
The program never gets passed the line "ftps.connect(host, 21);", with the error "Connection closed without indication", I do belive I have configured my server correctly since I can connect to it via "Putty" from another network etc. What am I missing here?
Note: I am not trying to connect through an Android device, I'm currently using eclipse for testing.
"I do belive I have configured my server correctly since I can connect to it via "Putty" from another network etc. What am I missing here?"
The "putty" utility talking to an SSH server on port 22 not to an FTP server on port 21. You can say that basic network connectivity / routing appears to be working, but that's not necessarily enough.
Possible problems you may be having include:
the FTP port being blocked by firewalling on the client, the server or somewhere in between, or
the FTP server may be configured incorrectly.
I noticed that the client is trying to use FTP/S but it it using the default port for FTP (21) not FTP/S (991). This is not necessarily wrong (see https://serverfault.com/questions/10807/what-firewall-ports-do-i-need-to-open-when-using-ftps for details) but maybe you should check that your server is configured to support explicit FTP/S.
I would advise:
look at the server and client side logs for clues
temporarily turn on "debug level" logging (client & server side)
see if you can establish a raw TCP connection on port 21; e.g. using telnet <server-host> 21
try changing the client to use FTP rather than FTP/S
if all else fails, try using a packet sniffer to capture the network traffic.
UPDATE
... it seems i confused sftp with ftps ...
Yes, they are very different. SFTP is in effect FTP tunneled over an SSH connection. It requires a client-side library that understands SSH.
So if you are trying to use FTP / FTPS client-side libraries and settings to talk an SSH (SFTP) service, you are probably failing because port 21 is blocked (which it should be if there is no FTP service) or because no FTP service is running (which should be the default for a typical out-of-the-box Linux server).
Related
On my company network we run Remedy 7.64 and want to create Incidents automatically. I setup the development environment using IntelliJ IDEA and the ARAPI-files for my server version. We have no administration access to the server to change anything over there.
The error says
ERROR (90): Can't connect to AR System-Server; Connection refused:
connect <host>.
Mysteriously i can connect to the Web-Interface using Chrome, i can ping the host, i can access it via the Driver & the official Remedy Client and the java tool can get the source code of the web-interface of it as well, so it obviously is possible to connect to the host but the difficulty is somewhere else.
This is my simple demo file
import com.bmc.arsys.api.*;
public static void main(String [ ] args)
{
ARServerUser ctx = new ARServerUser();
ctx.setServer("<server>");
ctx.setUser("<user>");
ctx.setPassword("<pass>");
try {
ctx.login();
System.out.println("works");
} catch (ARException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
This is the list of dependancies
1.8 (java version "1.8.0_65")
[Module source ]
groovy-2.4.5
log4j-1.2.14.jar
arapi7604_build002.jar
You have to provide port number in which AR server is listening on. "ERROR (90): Can't connect to AR System-Server; Connection refused: connect ." means that the server refused to connect as you haven't mentioned the port number to connect. Normally people use 37000 as the AR server port number, but you have to check with your Remedy Admin to know this.
I just came across the same error. My issue was that I tried to connect using the full url as <server> ("https://..."). Using just the name of the server worked.
I have this tiny java http server:
public class HttpServer {
public static void main(String args[]) {
int port;
ServerSocket server_socket;
try {
port = Integer.parseInt(args[0]);
} catch (Exception e) {
port = 8080;
}
try {
server_socket = new ServerSocket(port, 0, InetAddress.getByName("localhost"));
System.out.println("httpServer running on port "
+ server_socket.getLocalPort()
+ " address " + server_socket.getInetAddress()
);
} catch (IOException e) {
System.out.println(e);
}
}
}
When I connect with google chrome to localhost IDE console writes following:
httpServer running on port 8080 address localhost/127.0.0.1
New connection accepted /127.0.0.1:54839
New connection accepted /127.0.0.1:54840
Seems like google chrome connects two times to the server, but changing its port.
Why is it can be?
Since port 8080 on your client is already taken, the client's operating system will map the connection to a different unused port on the client. Your client connects from port 54839 and 54840 to port 80 on the server. To allow another client to connect to your server, the port is automatically redirected to an untaken port.
Here's a list of what happens...
Client opens up a Socket to connect to your server
Client's OS checks if the port the Socket is trying to connect to is used and if not looks for an unused port.
Client's OS assigns the socket to the unused local port it's detected in step 2.
Server receives connection request and accepts it. Server's OS redirects the connection from port 8080 to another port to allow more clients to connection.
Client and server have a chat and then disconnect.
54839 and 54840 are ports the OS assigned to the two Sockets your browser created when attempting to connect to your local website.
Edit: To correctly answer your question, the resources you send the browser causes it to connect twice. Once to retrieve the first resource and a second time to retrieve the resource the first requires.
I have a W8 machine with Oracle VirtualBox. In this, I have an ubuntu machine connected with only-host network.
VirtualBox Host-Only Ethernet Adapter
Intel PRO/1000 MT Desktop (82540EM)
Allow All
On the host machine I have a java program that acts like an RMI server.
On the virtual machine I have the the java program acting like an RMI client.
The client succeed in getting the registry without any problem, then it hangs when it looks up for the stub. Thus I have:
SEVERE: java.rmi.ConnectException: Connection refused to host: 192.bla.bla.bla; nested exception is:
java.net.ConnectException: Connection timed out
at ...
Both RMIclient and RMIserver have all the permissions, and this is the code for the RMI connection:
SERVER SIDE:
private static void startServer() {
System.setProperty("java.rmi.server.hostname", "192.bla.bla.bla");
if (System.getSecurityManager() == null) {
System.setProperty("java.security.policy", POLICY_FILE_LOC); //all permissions
System.setSecurityManager(new SecurityManager());
}
try {
String name = "RemoteController";
RemoteControllerInterface remote = new RemoteController();
RemoteControllerInterface stub =
(RemoteControllerInterface) UnicastRemoteObject.exportObject(remote, 0);
Registry registry = LocateRegistry.createRegistry(1099);
registry.rebind(name, stub);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
CLIENT SIDE:
RemoteControllerInterface remote = null;
if (System.getSecurityManager() == null) {
System.setProperty("java.security.policy", POLICY_FILE_LOC); //all permissions
System.setSecurityManager(new SecurityManager());
}
try {
String name = "RemoteController";
Registry registry = LocateRegistry.getRegistry("192.bla.bla.bla");
remote = (RemoteControllerInterface) registry.lookup(name); // stuck here
remote.connect(); // sample remote method
} catch (Exception e) {
e.printStackTrace();
}
I used the same client code running it on the host machine and all works fine, that's why I think is some problem in the configuration of VirtualBox maybe.
I don't know Windows Firewall so these are general guidelines:
You need to not only have port 1099 open on Windows for the RMI registry, you need to have another port open for your server RMI object itself - I think it opens a random port, unfortunately (see other StackOverflow questions on this). Also you may need to allow the VirtualBox host-only network to talk to localhost, as well (yes, I know that's the whole point of a host-only network, I'm just saying).
But you don't need to allow any other machines to access your Java programs (right?), so you could just allow unrestricted access from the VirtualBox host-only network, if Windows Firewall lets you configure it to do that.
I am writing a code where the android phone is the client trying to connect to the server on my pc USING WIFI. I am opening the sockets as follows:
try {
servsock = new ServerSocket(13299);
System.out.println("Listening :13299");
} catch (IOException e) {
e.printStackTrace();
}
while (true) {
Socket sock = servsock.accept();
and on client side:
Socket sock = new Socket("192.168.0.108", 13299);
Log.i("sending","sending");
However I am receiving on the logcat: "No route to host" I have searched and inserted permission to use internet in the manifest.xml and did a ping from my phone with ip 192.168.0.107 to the pc server with ip 192.168.0.108.
What Am I missing? Why isn't the tcp socket connection established ? the server is written in netbeans. Does it have to do with the ports?
EDIT: I think the problem is in the IP addresses. I set the address of the server (private address) according to the output of "ipconfig" in cmd window.
I had the same issue, i changed the internet access point and the app worked. My app was using a local IP to access the server.
It must be some sort of blockage that keeps your connection to the server out of the scope for your client. Try applying different ports, and see what happens then.
hiho,
i intend to develop just a litte network application, something like a chat. so i downloaded xampp for windows and installed it (also as service), mysql included. well, i started the apache (and mysql) as service and just wrote the short line in java:
try {
Socket sock = new Socket("127.0.0.1", 21);
System.out.println("connection established");
} catch ( UnknownHostException e ) {
System.out.println("Can't find host.");
} catch ( IOException e ) {
System.out.println("Error connecting to host. " + e.toString());
}
but directly i got the answer:
Error connecting to host. java.net.ConnectException: Connection refused: connect
the server is runnin'. the localhost is accessible on the browser.
did i forgot something? any ideas?
In your java code you're trying to connect to port 21 (ftp). Don't know what you want to do, but perhaps you should try port 80 (http).
Did you download and install the Tomcat add-on for XAMPP? It's not part of the default install.
After it's extracted into the XAMPP folder you have to run first setup_xampp.bat and then tomcat_start.bat.
Also, Tomcat in XAMPP will use the 8080 port by default.