Get File Listing ending with A or B using Jscape FTP

喜夏-厌秋 提交于 2019-12-23 04:54:26

问题


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.


回答1:


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.




回答2:


The FTP server which you're connecting to isn't accepting the filename wildcard which you've specified. The FTP file-listing commands aren't very well-defined. Here is what RFC 959 says about the protocol commands:

LIST (LIST)
This command causes a list to be sent from the server to the passive DTP. If the pathname specifies a directory or other group of files, the server should transfer a list of files in the specified directory. If the pathname specifies a file then the server should send current information on the file. A null argument implies the user's current working or default directory. The data transfer is over the data connection in type ASCII or type EBCDIC. (The user must ensure that the TYPE is appropriately ASCII or EBCDIC). Since the information on a file may vary widely from system to system, this information may be hard to use automatically in a program, but may be quite useful to a human user.

NAME LIST (NLST)
This command causes a directory listing to be sent from server to user site. The pathname should specify a directory or other system-specific file group descriptor; a null argument implies the current directory. The server will return a stream of names of files and no other information. The data will be transferred in ASCII or EBCDIC type over the data connection as valid pathname strings separated by or . (Again the user must ensure that the TYPE is correct.) This command is intended to return information that can be used by a program to further process the files automatically. For example, in the implementation of a "multiple get" function.

You'll notice the complete lack of any discussion about what wildcards the client can send or how the server would interpret them. That's because there is simply no standard in that area. Unix ftp servers commonly implement file listing like the unix ls command with unix-like wildcards, but that is by no means required behavior,

You should check the documentation for the remote FTP server, or talk to the remote system's administrators, to see how you should ask for the file listing that you're looking for.



来源:https://stackoverflow.com/questions/28179920/get-file-listing-ending-with-a-or-b-using-jscape-ftp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!