Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.9k views
in Java FTP by (200 points)
Hi,

I am using the trial version. My FTP Server is on UNIX i.e. ClearPath LX Series FTP version 52.150.015 (MCP version 52.189.8313). I am trying to download files. Now how do I check if it's a file then download if a directory don't download. I tried using

FTPFile[] fg = ftp.dirDetails(ftp.pwd());


but it does not works. printing ftp.pwd() gives me the following (TESTUSER) ON TECH01. I can't hard code the directory as it is dynamically checking if a specific directory is provided else pick files from the root directory and that's where ftp.pwd() does not seems to work in this case.

If my FTP Server is on windows using the following works fine.

FTPFile[] fg = ftp.dirDetails(".");



Any work arround.

Thanks

5 Answers

0 votes
by (162k points)
try dirDetails("")
0 votes
by (200 points)
I tried that but does not work either. Here is a code snippet:

.........................
........................

ftp = new FTPClient();
ftp.setRemoteHost(host);
FTPMessageCollector listener = new FTPMessageCollector();
ftp.setMessageListener(listener);      
ftp.connect();               
ftp.login(user, password);
ftp.setConnectMode(FTPConnectMode.PASV);
ftp.setType(FTPTransferType.ASCII);

System.out.println("PWD: " +ftp.pwd());
FTPFile[] fg = ftp.dirDetails("");
System.out.println("COUNT: " +fg.length);
for(int j=0; j < fg.length; j++)
{
  System.out.println("IF DIRECTORY: "+fg[j].isDir());
}
System.out.println("SYSTEM: "+ftp.system() );

String[] files = ftp.dir();
for (int i = 0; i < files.length; i++)
{
   
   byte[] by = ftp.get(files[i]);
   System.out.println("Name: "+files[i]+", Size: "+by.length);
}

...............................
...............................


And here is the output I see for the above:

PWD: (TESTUSR) ON TECH01
COUNT: 0
SYSTEM: ClearPath LX Series FTP version 52.150.015 (MCP version 52.189.8313)
Name: TESTING_TXT, Size: 7
Name: TESTING_200611101044, Size: 0
Name: TESTING_200611091422, Size: 0
Name: TESTING_200611091451, Size: 0
Name: TESTING_200611141635, Size: 22506
Name: TESTING_200611101044, Size: 119040
Name: TESTING_200611091422, Size: 7185180
Name: TESTING_200611091451, Size: 7626


Any work arround. Thanks
0 votes
by (162k points)
Oh I see. It is returning a weird directory listing format - certainly not a 'normal' Unix one.

You might have to use dir() rather than dirDetails() if all you are interested in is filenames. Otherwise pass in full=true and parse the result.
0 votes
by (200 points)
I am trying to download the files only but having issues if it's a directory. Using full=true I still need a directory name and that's where it does not work. Any work arround.

Thanks
0 votes
by (51.6k points)
That directory format looks quite simple. Why don't you write a directory parser? You do this by extending from FTPFileParser and then installing the parser into FTPClient using:
ftpClient.setFTPFileFactory(new FTPFileFactory(myFileparser));

- Hans (EDT)

Categories

...