sun.net.ftp.FtpProtocolException: Error reading FTP pending reply

Discussion in 'Java' started by long990802@gmail.com, Dec 10, 2005.

  1. Guest

    I write a class which inherit form sun.net.ftp.FtpClient. In this
    class, there is a method named downLoadFile to download file from a ftp
    server. Here is some code of this method:

    byte[] content = new byte[1024];
    super.cd(remotePath);
    RandomAccessFile file = new RandomAccessFile(downLoadFileName, "rw");
    TelnetInputStream in = super.get(remoteFile);
    DataInputStream input = new DataInputStream(in);
    while(input.available() > 0) {
    input.read(content);
    file.write(content);
    }
    in.close();
    file.close();

    When I use this method, I got a error:
    sun.net.ftp.FtpProtocolException: Error reading FTP pending reply
    Anybody can help me?
     
    , Dec 10, 2005
    #1
    1. Advertising

  2. On 10 Dec 2005 06:12:12 -0800, wrote:
    > I write a class which inherit form sun.net.ftp.FtpClient. In this
    > class, there is a method named downLoadFile to download file from a ftp
    > server. Here is some code of this method:
    >
    > byte[] content = new byte[1024];
    > super.cd(remotePath);
    > RandomAccessFile file = new RandomAccessFile(downLoadFileName, "rw");
    > TelnetInputStream in = super.get(remoteFile);
    > DataInputStream input = new DataInputStream(in);
    > while(input.available() > 0) {
    > input.read(content);
    > file.write(content);
    > }
    > in.close();
    > file.close();
    >
    > When I use this method, I got a error:
    > sun.net.ftp.FtpProtocolException: Error reading FTP pending reply
    > Anybody can help me?


    Which of the operations causes the exception?

    This may be unrelated, but your read loop has a number of serious
    problems.

    First, the call to available() doesn't serve any useful purpose and in
    fact can give you problems on a slow network. Simply read from the
    input stream until you reach EOF.

    Second, don't expect read() to always read the amount you've
    requested. Instead, check the return value and write only the same
    number of bytes.

    Also, you should be using a plain InputStream to read from the remote
    and a plain OutputStream to write the file. Other stream types perform
    various types of data conversion that can corrupt the contents of most
    files.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Dec 10, 2005
    #2
    1. Advertising

  3. Roedy Green Guest

    Roedy Green, Dec 10, 2005
    #3
  4. Guest

    3Q all.
    I have fixed the problem with your suggestions.
     
    , Dec 11, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    2,902
  2. davidj411
    Replies:
    1
    Views:
    1,085
    Mike Driscoll
    May 27, 2008
  3. Replies:
    2
    Views:
    579
  4. Felipe Coury

    Net::SSH and STDIN / Pending jobs

    Felipe Coury, Nov 26, 2009, in forum: Ruby
    Replies:
    0
    Views:
    110
    Felipe Coury
    Nov 26, 2009
  5. D. Buck
    Replies:
    2
    Views:
    534
    D. Buck
    Jun 29, 2004
Loading...

Share This Page