Error Reading Ftp Pending Reply Java
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 Advertisements Gordon Beaton Guest 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
or indirectly quoted someone who said : >> while(input.available() > 0) { >> input.read(content); >> file.write(content); >> } you can TEMPORARILY have no input available http://www.thecodingforums.com/threads/sun-net-ftp-ftpprotocolexception-error-reading-ftp-pending-reply.148422/ with a socket. See http://mindprod.com/jgloss/readblocking.html http://mindprod.com/jgloss/readeverything.html -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. . Follow-Ups: Re: sun.net.ftp.FtpProtocolException: Error reading FTP http://coding.derkeiler.com/Archive/Java/comp.lang.java.programmer/2005-12/msg01634.html pending reply From: long990802 References: sun.net.ftp.FtpProtocolException: Error reading FTP pending reply From: long990802 Re: sun.net.ftp.FtpProtocolException: Error reading FTP pending reply From: Gordon Beaton Prev by Date: Re: Running out of memory gracefully Next by Date: Re: RegEx problem Previous by thread: Re: sun.net.ftp.FtpProtocolException: Error reading FTP pending reply Next by thread: Re: sun.net.ftp.FtpProtocolException: Error reading FTP pending reply Index(es): Date Thread Flag as inappropriate (AWS) Security UNIX Linux Coding Usenet ArchiveAboutPrivacyImprint coding.derkeiler.com >Archive >Java >comp.lang.java.programmer >2005-12
sun.net.ftp.FtpProtocolException: Error reading FTP pending reply at sun.net.ftp.FtpClient.issueCommand(FtpClient.java:189) at error reading sun.net.ftp.FtpClient.closeServer(FtpClient.java:168) at com.eetrust.sdsc.main.common.FtpResource.close(Resource.java:161) 利用sun.net.ftp.FtpClient 进行文件上传下载过程中,报此错误 原因为 调用 client.nameList(),client.list()等方法后忘记关流。 记录一下,找了好久才找到这个小问题,引以为戒,不确定报此错误是不是都是此原因引起的,仅供参考。 分享到: 2014-03-25 16:02 浏览 236 评论(0) 分类:编程语言 相关推荐 参考知识库 Java error reading ftp SE知识库 14222关注 | 459收录 Java 知识库 16147关注 | 1305收录 Java EE知识库 7077关注 | 704收录 JavaScript知识库 7259关注 | 1372收录 评论 发表评论 您还没有登录,请您登录后再发表评论 枫奕辕 浏览: 236 次 性别: 来自: 北京 最近访客 更多访客>> YaenLi 文章分类 全部博客 (1) java (1) 社区版块 我的资讯 (0) 我的论坛 (0) 我的问答 (0) 存档分类 2014-03 (1) 更多存档... 最新评论 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。若作者同意转载,必须以超链接形式标明文章原始出处和作者。 © 2003-2016 ITeye.com. All rights reserved. [ 京ICP证110151号 京公网安备110105010620 ]
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to download a text file via FTP and read the contents to a string up vote 0 down vote favorite This is re-worded from a previous question (which was probably a bit unclear). I want to download a text file via FTP from a remote server, read the contents of the text file into a string and then discard the file. I don't need to actually save the file. I am using the Apache Commons library so I have: import org.apache.commons.net.ftp.FTPClient; Can anyone help please, without simply redirecting me to a page with lots of possible answers on? java android ftp apache-commons apache-commons-net share|improve this question edited Jul 25 '12 at 17:09 Dheeraj V.S. 8,93343573 asked Jul 25 '12 at 16:40 Kevmeister 7218 2 C'mon, man. It's right in the javadocs: commons.apache.org/net/api-3.1/org/apache/commons/net/ftp/… –duffymo Jul 25 '12 at 16:47 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote Normally I'd leave a comment asking 'What have you tried?'. But now I'm feeling more generous :-) Here you go: private void ftpDownload() { FTPClient ftp = null; try { ftp = new FTPClient(); ftp.connect(mServer); try { int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { throw new Exception("Connect failed: " + ftp.getReplyString()); } if (!ftp.login(mUser, mPassword)) { throw new Exception("Login failed: " + ftp.getReplyString()); } try { ftp.enterLocalPassiveMode(); if (!ftp.setFileType(FTP.BINARY_FILE_TYPE)) { Log.e(TAG, "Setting binary file type failed."); } transferFile(ftp); } catch(Exception e) { handleThrowable(e); } finally { if (!ftp.logout()) { Log.e(TAG, "Logout failed."); } } } catch(Exception