问题描述
我在我的java代码中使用FTP(com.jscape.inet.ftp.Ftp)来获取文件列表。我使用下面的一段代码来获取文件列表。
枚举< String> files = ftp.getNameListing(test *);
上面的代码列出了所有带有test * name的文件。
但是,在列出所有以A或B结尾的测试文件时,我遇到了问题。我尝试使用以下模式获取列表。
枚举< String> files = ftp.getNameListing(test * [A-B]);
枚举< String> files = ftp.getNameListing(test * [AB]);
然而,他们都没有工作,我收到一个例外
501限定词太长。使用MVS命名约定。
com.jscape.inet.ftp.FtpException:无法连接到主机**。**。**。**
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)
任何帮助表示感谢。
规范说文件列表命令( LIST , MLSD 等)的一个参数是一个路径名。所以应该没有任何通配符。无论如何。
实际上,尽管许多FTP服务器在参数中支持wilcards。但是,由于规范不允许,支持通配符显然没有设置标准。
$ b vsftpd 支持 * ,?和 {} with LIST 。 vsftpd不支持现代 MLSD 。
$ bproftpd 支持 * ,?和 [] 。但仅限于 LIST 。它明确地不允许现代 MLSD 带有注释的wilcards:
pureftpd 支持 * ,<$ c对于 LIST 和,$ c>?和 [] MLSD 。
但你没有使用任何上述的FTP服务器, IBM服务器。我不知道它支持什么样的通配符(如果有的话)。
但是一般来说,你不应该依赖FTP服务器来支持任何通配符。 / p>
唯一可靠的方法是检索完整的目录列表并在本地过滤文件。
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:
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.
这篇关于获取文件列表使用Jscape FTP以A或B结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!