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

L

long990802

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?
 
G

Gordon Beaton

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top