Question

I was trying to retrieve files from a mainframe FTP server, so i was using this org.apache.commons.net.ftp.FTPClient method:

FTPClient ftpClient = ......
ftpClient.listFiles("path")

let's say the dir was "AAAA.BBBB.CCCC.DDDD":

ftpClient.changeWorkingDirectory("..");
FTPFile[] files = ftpClient.listFiles("AAAA.BBBB.CCCC.DDDD");

When I print out

files.length

result is 1. Doesn't matter if it's a file or a folder, the result is still 1. I want to know why.

My test on a regular, non-mainframe, ftp using a folder name and file names worked fine.

I wish to know:

How to correctly traversal a directory in mainframe ftp.

Was it helpful?

Solution

There are two file systems available with z/OS. One is the "classic" file system (my term, I don't know how IBM differentiates) which has roots going back half a century to OS/360, the other is more recent and is Unix compatible.

You are using the "classic" file system. There are no directories. Sometimes there is syntactic sugar available in an FTP client that makes the dataset name qualifiers (the "AAAA" and "BBBB" parts between the dots) seem like directories. They aren't.

I suggest you use wildcards in the argument to your listFiles method. See if "AAAA.BBBB.CCCC.DDDD.**" gets you what you expect.

Something else you could try would be to pass the argument "AAAA.BBBB.CCCC" to your changeWorkingDirectory method.

Depending on the implementation of the library you're using, either of the above may do the equivalent of the ISPF DSLIST command.

OTHER TIPS

I was investigating this issue with a customer's mainframe very recently, and the working solution was first adding a DefaultFtpSessionFactory with the following configuration:

<bean class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
   <property name="host" value="???.???.???.???" />
   <property name="port" value="21" />
   <property name="username" value="ftp" />
   <property name="password" value="ftp" />
   <property name="config">
      <bean class="org.apache.commons.net.ftp.FTPClientConfig">
         <constructor-arg value="MVS" />
      </bean>
   </property>
</bean>

the filePattern we use on the session object is 'FILE.FILE.FILE.FILE.FILE.**' (inlcuding the single quotes)

the java code for getting the list of file is

Session<FTPFile> session = factory.getSession();
FTPFile[] files = session.list("'FILE.FILE.FILE.FILE.FILE.**'");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top