aquasw
asked on
connection reset exception while using ftp clinet of apache commons-net-1.3
Hi Experts
I am using commons-net-1.3 of apache, to retrive files from ftp.
this is my function
ftp = new FTPClient();
int reply;
ftp.connect(ftpServer);
System.out.println("Connec ted to " + ftpServer + ".");
// After connection attempt, you should check the reply code to
// verify success.
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompl etion(repl y)) {
ftp.disconnect();
throw new Exception("FTP server refused connection.");
}
ftp.login(ftpUsername, ftpPassword);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
// Use passive mode as default because most of us are
// behind firewalls these days.
ftp.enterLocalPassiveMode();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ftp.retrieveFile(remote, baos);
byte[] ret = baos.toByteArray();
try {
tmpp = ftp.logout();
} catch (Exception e) {
// here I get the exception
system.out.println("DEBUG - ftp logout problem\r\n"+StringUtils
.getStackTrace(e));
}
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException f) {
}
}
and I am get exception almost every time when invoking ftp.logout
this is the exception
java.net.SocketException: Connection reset
at java.net.SocketInputStream .read(Sock etInputStr eam.java:1 68)
at java.io.BufferedInputStrea m.read1(Bu fferedInpu tStream.ja va:256)
at java.io.BufferedInputStrea m.read(Buf feredInput Stream.jav a:317)
at java.io.BufferedInputStrea m.fill(Buf feredInput Stream.jav a:218)
at java.io.BufferedInputStrea m.read(Buf feredInput Stream.jav a:237)
at org.apache.commons.net.tel net.Telnet InputStrea m.__read(T elnetInput Stream.jav a:114)
at org.apache.commons.net.tel net.Telnet InputStrea m.run(Teln etInputStr eam.java:5 35)
at java.lang.Thread.run(Threa d.java:619 )
do you know what is the problem and how can i solve it ?
thanks
I am using commons-net-1.3 of apache, to retrive files from ftp.
this is my function
ftp = new FTPClient();
int reply;
ftp.connect(ftpServer);
System.out.println("Connec
// After connection attempt, you should check the reply code to
// verify success.
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompl
ftp.disconnect();
throw new Exception("FTP server refused connection.");
}
ftp.login(ftpUsername, ftpPassword);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
// Use passive mode as default because most of us are
// behind firewalls these days.
ftp.enterLocalPassiveMode();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ftp.retrieveFile(remote, baos);
byte[] ret = baos.toByteArray();
try {
tmpp = ftp.logout();
} catch (Exception e) {
// here I get the exception
system.out.println("DEBUG - ftp logout problem\r\n"+StringUtils
.getStackTrace(e));
}
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException f) {
}
}
and I am get exception almost every time when invoking ftp.logout
this is the exception
java.net.SocketException: Connection reset
at java.net.SocketInputStream
at java.io.BufferedInputStrea
at java.io.BufferedInputStrea
at java.io.BufferedInputStrea
at java.io.BufferedInputStrea
at org.apache.commons.net.tel
at org.apache.commons.net.tel
at java.lang.Thread.run(Threa
do you know what is the problem and how can i solve it ?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
ellandrd, how can I ensure that I recived full response ? I tried to put sleep after the transfer,it still didn't solve the problem. I think that it's another problem
CEHJ, you suggest to ignore it.
why it is happening at all ?
I sniffed the packets with ethereal, and it seems that all the ftp packets gets and received very well, including the the quit packet (receive and response) so it seems that it's not problem of networking.
any suggestions ?
ellandrd, how can I ensure that I recived full response ? I tried to put sleep after the transfer,it still didn't solve the problem. I think that it's another problem
CEHJ, you suggest to ignore it.
why it is happening at all ?
I sniffed the packets with ethereal, and it seems that all the ftp packets gets and received very well, including the the quit packet (receive and response) so it seems that it's not problem of networking.
any suggestions ?
>>how can I ensure that I recived full response?
You're already doing that. If you get a positive, you can safely ignore the exception. That sort of thing can happen due to the order of 'hanging up' the conversation. It's of no concern
You're already doing that. If you get a positive, you can safely ignore the exception. That sort of thing can happen due to the order of 'hanging up' the conversation. It's of no concern
ASKER
thanks
:-)
I see the Java TA is still a "cut troat" zone...
This usually occurs when you haven't received the full response and you unexpectedly closed the socket when the server was still doing stuff.
ellandrd