• 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 FTPClient - listFiles() returns empty

 
Tha�s Manfrim Firmino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with the class
org.apache.commons.net.ftp.FTPClient

and the command listFiles() returns empty, when there are files there.

I read in the API that it uses the LIST command, which I didn't find on the ftp server (through "help" I saw that command option is not available on that server).

Does someone had that issue before? How was that solved?

Thank you in advance,

Tha�s.
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I use this library here and there. Yes is does use the LIST command, remember that the LIST command is not actually something you execute natively. On the command line you would use 'dir' or 'ls' (which translates to LIST).

Start by making sure that you're in the directory you think you are in by using the equivalent of 'pwd' e.g. printWorkingDirectory()
 
Tha�s Manfrim Firmino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already did that...

I'm posting my code below...

public static Vector getFiles(){

 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah easy fix I think, listFiles() can take a directory argument. If you've already changed directory to where you want to be then listFiles(".") should do the trick.
 
Tha�s Manfrim Firmino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't work yet. It return no files, when there is one there. :-(
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The listing of files can be filtered, have you applied one of these? What is the file that it is not picking up and what are the attributes on it? (e.g. rwxrwxrwx)
 
Tha�s Manfrim Firmino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just a text file called test.txt, with almost no content. I applied no filter on the listing method. See that my code above is really plain...
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps the FTP server you are connecting to is one of the obscure and not-quite-standard ones which is not supported by the product.
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Further to what Paul says, have you tried other FTP servers? I've run your code and it works just fine for me...
 
Tha�s Manfrim Firmino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I strongly believe the issue is on the server, because the code is very plain.
We'll, anyway I'll have to solve my issu. If you guys have any idea or suggestion, it will be very welcome. :-)
Thank you for all your help up to now!
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the documentation for the package org.apache.commons.net.ftp.parser. You will see a list of FileEntryParser classes which support the formats produced by a variety of servers. It appears that maybe the server you are connecting to is not one of these servers.

If that's the case then you can write your own implementation of FTPFileEntryParserFactory for this rogue server. Look at the source code for one of the existing parsers and mimic that, changing it to support the actual format which that server produces. (Connect to it via the command line to examine the format.)

There's a method for assigning that parser to your FTPClient, it's called setParserFactory.
 
Tha�s Manfrim Firmino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In fact I believe I found out my issue.

I'm working with apache commons 1.0 (because the server uses an old java version that is not compatible with 2.0 or others). The listFiles() would need the server to display the date/time format in a specific way. In the new apache commons you can configure the date/time format that will be used , but not in 1.0. In this case the listFiles() won't work for me unless I configure the server date/time to the expected way, which I cannot do (I'm not part of the team that supports that server). So I just can't use that command.

Thanks all that tried to help me bringing new ideas and possibilities!
 
Sunil swain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tha�s Manfrim Firmino wrote:Hi,

In fact I believe I found out my issue.

I'm working with apache commons 1.0 (because the server uses an old java version that is not compatible with 2.0 or others). The listFiles() would need the server to display the date/time format in a specific way. In the new apache commons you can configure the date/time format that will be used , but not in 1.0. In this case the listFiles() won't work for me unless I configure the server date/time to the expected way, which I cannot do (I'm not part of the team that supports that server). So I just can't use that command.

Thanks all that tried to help me bringing new ideas and possibilities!

>
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rox wz, please see you PM inbox for an Administrative matter.
 
Sunil swain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Filelist() is not acting properly.
It is not listing no of files/subdirectories inside a directory.
What could be the reason?

Sunil swain wrote:

Tha�s Manfrim Firmino wrote:Hi,

In fact I believe I found out my issue.

I'm working with apache commons 1.0 (because the server uses an old java version that is not compatible with 2.0 or others). The listFiles() would need the server to display the date/time format in a specific way. In the new apache commons you can configure the date/time format that will be used , but not in 1.0. In this case the listFiles() won't work for me unless I configure the server date/time to the expected way, which I cannot do (I'm not part of the team that supports that server). So I just can't use that command.

Thanks all that tried to help me bringing new ideas and possibilities!

>

 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you set the correct type of FTP server you are connecting to? e.g. UNIX, Windows
 
Sunil swain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Martijn,
I am using microsoft IIS FTP server.
The problem is that this method is returing null pointer exception whenever there is morethan one files/sub-directories.
But it is not showing any exception if there is only one file of any type.It returns 0.
May i know the reason..
Thanks for response.

Martijn Verburg wrote:Have you set the correct type of FTP server you are connecting to? e.g. UNIX, Windows

 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sunil,

Firstly, are you using the latest version of Apache commons net? Secondly, you need need to make sure that you've set the property that you're using a Windows FTP server. I forget where this is now, but it should be pretty clear in the documentation.
 
Darvesh Niz
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys
i have kind of same issue but with environments.
my application works fine on my local and prod, but does not find any files on our test environment.
We are using apache commons 2.

i dont think there is any issue with the code since its able to find the files using .listFiles command, its only on the TI box its not finding the files.

Any advice.
thanks
darniz
 
Hot dog! An advertiser loves us THIS much:
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!