Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
long990802@gmail.com - 10 Dec 2005 14:12 GMT
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?
Gordon Beaton - 10 Dec 2005 14:51 GMT
> 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
[quoted text clipped - 15 lines]
> 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

Signature

[  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

Roedy Green - 10 Dec 2005 22:13 GMT
>>  while(input.available() > 0) {
>>      input.read(content);
>>      file.write(content);
>>  }

you can TEMPORARILY have no input available with a socket.

See http://mindprod.com/jgloss/readblocking.html
http://mindprod.com/jgloss/readeverything.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

long990802@gmail.com - 11 Dec 2005 02:46 GMT
3Q all.
I have fixed the problem with your suggestions.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.