Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

apache commons FTPClient issue

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working with org.apache.commons.net.ftp.FTPClient class.
I've a directory on my ftp server and i am able to connect
to and get the name of all the files in that directory.

My task is to read the contents of each file. I've
created a Map in which i store the name of the file
and it's contents and iterate it to the number of files.

I can read the first file successfully using retrieveFileStream()
but after subsequent attempt to read the file, it says
I/O exception: bufferedReader closed.

I don't have any clue what's wrong with my approach.

Any kind of help will be highly appreciated.

Thanks in advance
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To quote from the API documentation for that method:

You must close the InputStream when you finish reading from it. The InputStream itself will take care of closing the parent data connection socket upon being closed. To finalize the file transfer you must call completePendingCommand and check its return value to verify success.


Perhaps you aren't doing that?
 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul for your promt reply.
I've written one method getXMLMessage() which opens the input stream and returns the content of
the file in String format. In finally block I've closed InputStream,BufferedInputStream and
BufferedReader objects. So it gets called every time the method terminates.

Every subsequent call to getXMLMessage method gives java.io.IOException: Stream closed.

I was infact not using completePendingCommand method. Where to use it? Shall I
use it in the same method where I am creating InputStream object?

 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing I'd like to mention is that once I call getXMLMessage method,I get printWorkingDirectory() returning null.

Please help me out.
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nandini lagunia wrote:I was infact not using completePendingCommand method. Where to use it? Shall I
use it in the same method where I am creating InputStream object?


As the documentation says, you use it to finalize the file transfer. That means you use it after you finish the file transfer.
 
nandini lagunia
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!!
I am able to read the file contents located on the ftp server but now I am getting
org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.

What could be the cause and what's the remedy for this?
I can very well read the files without any exception from my local filezilla ftp server. The problem arises when I try
to read the files on a remote server.
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

1.) The server maybe timing out (are you waiting quite some time before making a call after the list call?)
2.) There maybe a permissioning problem (e.g. Your user account on that FTP server only has permission to list files)
3.) You maybe connecting to a 'different' or unsupported type of FTP server, see FTPClient API docs for how to connect to UNIX/Windows/AIX etc based FTP servers.

Hope that Helps!
 
I found a beautiful pie. And a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!