Link to home
Start Free TrialLog in
Avatar of aquasw
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("Connected to " + ftpServer + ".");

            // After connection attempt, you should check the reply code to
            // verify success.
            reply = ftp.getReplyCode();

            if (!FTPReply.isPositiveCompletion(reply)) {
                  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(SocketInputStream.java:168)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
        at org.apache.commons.net.telnet.TelnetInputStream.__read(TelnetInputStream.java:114)
        at org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:535)
        at java.lang.Thread.run(Thread.java:619)



do you know what is the problem and how can i solve it ?

thanks
Avatar of ellandrd
ellandrd
Flag of Ireland image

Hi

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
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aquasw
aquasw

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 ?
>>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
Avatar of aquasw

ASKER

thanks
:-)
I see the Java TA is still a "cut troat" zone...