commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Cohen <sco...@javactivity.org>
Subject Re: [NET] OS400 FTP FileEntry parser
Date Thu, 18 Mar 2004 01:45:14 GMT
Thanks, Gary, this is true.

Mario, thanks for submitting this!  Please don't be offended if I ask a few 
"due diligence" questions.  I don't want to release this and then get hit 
with a lot of bug reports.

Can you tell me how well tested this is?  Could you possibly write a JUnit 
test for the parser showing how it handles some typical listings?  There are 
examples under the src/test tree.  Copying from one of these patterns should 
be quite easy.  

I've never FTPd from an OS400 so I don't know what a listing looks like.  Do 
they do the "dance" that UNIX servers do with the date?  That is the year is 
only shown if the file is more than one year old, and if it is less than one 
year old, the timestamp is shown instead of the year?  It looks from your 
regular expression that this is not the case but I just want to be sure.

Also, if there is any way you can help us access an OS400 server for more 
testing this would be helpful.

One last point is very important.  We have implemented an auto-detection 
scheme which makes alternate parsers much easier to use with clients such as 
ant.  This capability relies on the FTP SYST command.  Based on the value 
that this returns, autodetection attempts to select the correct parser.  This 
is not essential, but it is very convenient.  So could you please answer for 
me how an OS/400 FTP server responds to the SYST command (or in commons-net 
terminology how does this system respond to FTPClient.getSystemName())?

Thanks

Steve Cohen




On Wednesday 17 March 2004 11:45 am, Gary Gregory wrote:
> I am not a [net] developer but I am sure it would facilitate integration
> if you could submit this as a bugzilla ticket.
>
> Thanks,
> Gary
>
> > -----Original Message-----
> > From: Mario Ivankovits [mailto:mario@ops.co.at]
> > Sent: Wednesday, March 17, 2004 07:32
> > To: Jakarta Commons Developers List
> > Subject: [NET] OS400 FTP FileEntry parser
> >
> > Here you will find my OS/400 FileEntry parser.
> > Maybe one would add this to commons.net?
> >
> > Ciao,
> > Mario
> >
> > ---cut here---
> > import org.apache.commons.net.ftp.FTPFile;
> > import org.apache.commons.net.ftp.FTPFileListParserImpl;
> >
> > import java.util.Calendar;
> >
> > public class OS400FTPEntryParser extends FTPFileListParserImpl
> > {
> >     private static final String REGEX =
> >         "(\\S+)\\s+"                // user
> >         + "(\\d+)\\s+"                // size
> >         + "(\\d\\d)/(\\d\\d)/(\\d\\d)\\s+" // year/month/day
> >         + "(\\d\\d):(\\d\\d):(\\d\\d)\\s+" // hour/minutes/seconds
> >         + "(\\*\\S+)\\s+"                // *STMF/*DIR
> >         + "(\\S+/?)\\s*";                // filename
> >
> >     public OS400FTPEntryParser()
> >     {
> >         super(REGEX);
> >     }
> >
> >     public FTPFile parseFTPEntry(String entry)
> >     {
> >
> >         FTPFile file = new FTPFile();
> >         file.setRawListing(entry);
> >         int type;
> >
> >         if (matches(entry))
> >         {
> >             String usr = group(1);
> >             String filesize = group(2);
> >             String yr = group(3);
> >             String mo = group(4);
> >             String da = group(5);
> >             String hr = group(6);
> >             String min = group(7);
> >             String sec = group(8);
> >             String typeStr = group(9);
> >             String name = group(10);
> >
> >             if (typeStr.equalsIgnoreCase("*STMF"))
> >             {
> >                 type = FTPFile.FILE_TYPE;
> >             }
> >             else if (typeStr.equalsIgnoreCase("*DIR"))
> >             {
> >                 type = FTPFile.DIRECTORY_TYPE;
> >             }
> >             else
> >             {
> >                 type = FTPFile.FILE_TYPE;
> >             }
> >
> >             file.setType(type);
> >
> >             file.setUser(usr);
> >
> >             try
> >             {
> >                 file.setSize(Integer.parseInt(filesize));
> >             }
> >             catch (NumberFormatException e)
> >             {
> >                 // intentionally do nothing
> >             }
> >
> >             Calendar cal = Calendar.getInstance();
> >             cal.set(Calendar.SECOND, 0);
> >             cal.set(Calendar.MINUTE, 0);
> >             cal.set(Calendar.HOUR_OF_DAY, 0);
> >
> >             try
> >             {
> >                 int year = Integer.parseInt(yr, 10);
> >                 if (year < 70)
> >                 {
> >                     year += 2000;
> >                 }
> >                 else
> >                 {
> >                     year += 1900;
> >                 }
> >
> >                 cal.set(Calendar.YEAR, year);
> >                 cal.set(Calendar.MONTH, Integer.parseInt(mo, 10));
> >                 cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(da,
>
> 10));
>
> >                 cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hr,
>
> 10));
>
> >                 cal.set(Calendar.MINUTE, Integer.parseInt(min, 10));
> >                 cal.set(Calendar.SECOND, Integer.parseInt(sec, 10));
> >
> >                 file.setTimestamp(cal);
> >             }
> >             catch (NumberFormatException e)
> >             {
> >                 // do nothing, date will be uninitialized
> >             }
> >
> >             if (name.endsWith("/"))
> >             {
> >                 name = name.substring(0, name.length()-1);
> >             }
> >             int pos = name.lastIndexOf('/');
> >             if (pos > -1)
> >             {
> >                 name=name.substring(pos+1);
> >             }
> >
> >             file.setName(name);
> >
> >             return file;
> >         }
> >         return null;
> >     }
> > }
> > ---cut here---
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message