I am using FTP (com.jscape.inet.ftp.Ftp) in my java code to get file listing. I am using the following piece of code to get list of files.
Enumeration<String> files= ftp.getNameListing("test*");
The above code lists all the files with test* name.
However, I am facing issue while listing all the test files ending with A or B. I tried the below pattern to get the listing.
Enumeration<String> files= ftp.getNameListing("test*[A-B]");
Enumeration<String> files= ftp.getNameListing("test*[AB]");
However none of them are working and I am receiving an exception
501 Qualifier too long. Use MVS naming conventions.
com.jscape.inet.ftp.FtpException: Unable to connect to host **.**.**.**
at com.jscape.inet.ftp.FtpBaseImplementation.openDataConnection(Unknown Source)
at com.jscape.inet.ftp.FtpBaseImplementation.getNameListing(Unknown Source)
at com.jscape.inet.ftp.Ftp.getNameListing(Unknown Source)
Any help is appreciated.
FTP specification says that an argument to file listing commands (LIST
, MLSD
, etc) is a pathname. So there should be NO wildcard, whatsoever.
In practice though many FTP servers do support wilcards in the argument. But as the specification does not allow that, there's obviously no set standard for the wildcards supported.
vsftpd supports *
, ?
and {}
with LIST
. vsftpd does not support modern MLSD
.
proftpd supports *
, ?
and []
. But for LIST
only. It explicitly does not allow wilcards with modern MLSD
with comment:
RFC3659 explicitly does NOT support glob characters. So warn about this, but let the command continue as is.
pureftpd supports *
, ?
and []
for both LIST
and MLSD
.
But you are not using any of the above FTP servers, but rather some IBM server. I have no idea what kind of wildcards (if any) it supports.
But in general, you should not rely on the FTP server to support any wildcards at all.
The only reliable approach to is to retrieve a complete directory listing and filter the files locally.