[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1587
  • Last Modified:

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
0
aquasw
Asked:
aquasw
  • 3
  • 2
  • 2
1 Solution
 
ellandrdCommented:
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
0
 
CEHJCommented:
If you've got a complete transfer then it isn't a problem. Just catch it and ignore it
0
 
aquaswAuthor Commented:
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 ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
>>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
0
 
aquaswAuthor Commented:
thanks
0
 
CEHJCommented:
:-)
0
 
ellandrdCommented:
I see the Java TA is still a "cut troat" zone...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now