You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-dev@incubator.apache.org by ta...@flextronicssoftware.com on 2006/07/13 05:11:35 UTC
java.net.BindException: Address already in use
Hi ,
I have integrated the FTPServer in my application. FTP server is running
fine in my application. The FTPClient
(org.apache.commons.net.ftp.FTPClient) connects to FTPServer on port
18021. I am able to retrieve a file from the FTPServer. Whenever I try
to retrieve more than one files from the FTPServer. Then I am getting
exception "BindException: Address already in use" .
Could you please tell me How I can resolve this problem? Please let me
know if you have any solutions or suggestion for this. I am looking
forward your response.
I am also sending code snippets:
FTPClient client = new FTPClient();
System.out.println("Connecting FTP Server");
client.connect("10.150.1.111",18021);
//client.connect("10.150.1.111");
System.out.println("FTP Server Connected");
int reply = client.getReplyCode();
System.out.println("[EmbeddedFtpSessionPolicy] FTP connection
reply code is "+reply);
if (FTPReply.isPositiveCompletion(reply)) {
System.out.println("[EmbeddedFtpSessionPolicy] connection
established to "+client.getRemoteAddress().getHostAddress());
boolean success = client.login("admin", "admin");
System.out.println("FTP Server success "+success);
}
File local1 = new File("TEST.log");
File local = new File("ftpd.log");
boolean status;
// if we comment any one of the given bellow it will work
properly ....
status = client.retrieveFile("/sdp/database/ftpd.properties", new
FileOutputStream(local));
status = client.retrieveFile("/sdp/database/TEST.log", new
FileOutputStream(local1));
if (client.isConnected()) {
System.out.println("FTP Server disconnected");
client.logout();
client.disconnect();
client =null;
}
System.out.println("FTP Server disconnected ");
2006-07-12 15:22:12,641 INFO [org.apache.ftpserver.RequestHandler] Open
connection - 10.150.10.133
2006-07-12 15:22:12,650 INFO [org.apache.ftpserver.command.PASS] Login
success - admin
2006-07-12 15:22:12,660 WARN [org.apache.ftpserver.FtpDataConnection]
FtpDataConnection.getDataSocket()
java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:331)
at java.net.Socket.bind(Socket.java:498)
at java.net.Socket.<init>(Socket.java:307)
at java.net.Socket.<init>(Socket.java:211)
at
org.apache.ftpserver.FtpDataConnection.getDataSocket(FtpDataConnection.java:205)
at
org.apache.ftpserver.FtpRequestImpl.getDataOutputStream(FtpRequestImpl.java:332)
at org.apache.ftpserver.command.RETR.execute(RETR.java:120)
at
org.apache.ftpserver.RequestHandler.service(RequestHandler.java:277)
at
org.apache.ftpserver.RequestHandler.run(RequestHandler.java:242)
at java.lang.Thread.run(Thread.java:534)
Thanks and regards,
Tarkeshwar Prasad
Flextronics Software Systems
tarkeshwar.prasad@flextronicssoftware.com
( Mobile: 9886562675
Office: 080-41067342(x7342)
*********************** FSS-Private ***********************
Re: java.net.BindException: Address already in use
Posted by Dave Correia <da...@jopari.com>.
We had a similar problem, it was caused by having a single specific
local-port configured for the data-connection.
fixed it by setting local-port to zero, that is let the server use a
default local port for connecting out.
in ftpd.xml
<data-connection>
<idle-time>10</idle-time>
<active>
<enable>true</enable>
<local-address>10.25.1.8</local-address>
<local-port>0</local-port>
<ip-check>false</ip-check>
</active>
<passive>
<address>10.25.1.8</address>
<ports>0</ports>
</passive>
</data-connection>
the code where you're throwing is
if(localPort == 0) {
dataSoc = new Socket(address, port);
}
else {
InetAddress localAddr =
dataConfig.getActiveLocalAddress();
dataSoc = new Socket(address, port, localAddr,
localPort);
}
by setting a single local-port, you call Socket with a localAddr and
localPort,
so it makes sense that the second call would fail with a bind failure.
hope that helps
tarkeshwar.prasad@flextronicssoftware.com wrote:
> Hi ,
> I have integrated the FTPServer in my application. FTP server is running
> fine in my application. The FTPClient
> (org.apache.commons.net.ftp.FTPClient) connects to FTPServer on port
> 18021. I am able to retrieve a file from the FTPServer. Whenever I try
> to retrieve more than one files from the FTPServer. Then I am getting
> exception "BindException: Address already in use" .
> Could you please tell me How I can resolve this problem? Please let me
> know if you have any solutions or suggestion for this. I am looking
> forward your response.
>
> I am also sending code snippets:
>
> FTPClient client = new FTPClient();
> System.out.println("Connecting FTP Server");
> client.connect("10.150.1.111",18021);
> //client.connect("10.150.1.111");
> System.out.println("FTP Server Connected");
>
> int reply = client.getReplyCode();
> System.out.println("[EmbeddedFtpSessionPolicy] FTP connection
> reply code is "+reply);
> if (FTPReply.isPositiveCompletion(reply)) {
> System.out.println("[EmbeddedFtpSessionPolicy] connection
> established to "+client.getRemoteAddress().getHostAddress());
> boolean success = client.login("admin", "admin");
> System.out.println("FTP Server success "+success);
> }
> File local1 = new File("TEST.log");
> File local = new File("ftpd.log");
> boolean status;
> // if we comment any one of the given bellow it will work
> properly ....
> status = client.retrieveFile("/sdp/database/ftpd.properties", new
> FileOutputStream(local));
> status = client.retrieveFile("/sdp/database/TEST.log", new
> FileOutputStream(local1));
>
> if (client.isConnected()) {
> System.out.println("FTP Server disconnected");
> client.logout();
> client.disconnect();
> client =null;
> }
> System.out.println("FTP Server disconnected ");
>
> 2006-07-12 15:22:12,641 INFO [org.apache.ftpserver.RequestHandler] Open
> connection - 10.150.10.133
> 2006-07-12 15:22:12,650 INFO [org.apache.ftpserver.command.PASS] Login
> success - admin
> 2006-07-12 15:22:12,660 WARN [org.apache.ftpserver.FtpDataConnection]
> FtpDataConnection.getDataSocket()
> java.net.BindException: Address already in use
> at java.net.PlainSocketImpl.socketBind(Native Method)
> at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:331)
> at java.net.Socket.bind(Socket.java:498)
> at java.net.Socket.<init>(Socket.java:307)
> at java.net.Socket.<init>(Socket.java:211)
> at
> org.apache.ftpserver.FtpDataConnection.getDataSocket(FtpDataConnection.java:205)
> at
> org.apache.ftpserver.FtpRequestImpl.getDataOutputStream(FtpRequestImpl.java:332)
> at org.apache.ftpserver.command.RETR.execute(RETR.java:120)
> at
> org.apache.ftpserver.RequestHandler.service(RequestHandler.java:277)
> at
> org.apache.ftpserver.RequestHandler.run(RequestHandler.java:242)
> at java.lang.Thread.run(Thread.java:534)
>
>
> Thanks and regards,
>
>
> Tarkeshwar Prasad
> Flextronics Software Systems
> tarkeshwar.prasad@flextronicssoftware.com
> ( Mobile: 9886562675
> Office: 080-41067342(x7342)
>
> *********************** FSS-Private ***********************
>