NetTalk Central

Author Topic: Deciphering Custom FTP Directory Listings  (Read 29508 times)

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Deciphering Custom FTP Directory Listings
« on: September 20, 2007, 12:09:22 AM »
Preamble:

When using FTP a common command is to get a directory listing. Unfortunately the FTP spec does not specify the format of this listing. In theory each serer can return it in a different way, in practice there are a handful of common formats.

However every now and then you may interact with a server that has a completely obscure format. These are typically custom FTP servers used in specific companies and may be running on an obscure operating system. And in this situation you will need to add code to your program to correctly decipher the directory listing.

To do this is a 2 step process. Firstly you need to come up with a technique that identifies the format, and secondly you need to add code that deciphers the format into the internal nettalk fields.

Step 1

To identify the format, add code to the _FigureOutDirFormat method, which is a method of the NetFTPClientData class. You can add code to methods in your procedure, by clicking on the procedure in the application tree, and then searching for the method name.

After the parent call do a test to see if the test was successful, and if it wasn't then you can add additional code of your own to detect the format. For example

PARENT._FigureOutDirFormat(p_Data)
If self._DirFormatSet = 1 and self._DirListingFormat = 0
  ! do your check here, and set self._DirListingFormat to some number > 200 and < 250.
End


In the _FigureOutDirFormat method your goal is to determine the format, and give it a number (between 200 and 250). This format number is stored in the property _DirListingFormat. Reading the code in the NetSimp.Clw file, for the _FigureOutDirFormat method can be helpful in showing you how you might try and detect your format.

In this example I'll assume you do detect your format, and you assign this format to number 201. We'll use this number in step 2.

Step 2

Now that you know the format, you need to use this knowledge to populate the ControlConnection.DirListingQ Queue property.
The format of the Queue looks like this

Name                            string(FILE:MAXFILENAME)
Shortname                       string(13) ! Never used - just here because of the DirListing structure
Date                            long
Time                            long
Size                            long
Attrib                          byte
NoOfLinks                       long
Owner                           string(50)
GroupOwnership                  string(50)
AccessPermissions               string(50)


You won't necessarily have all the information in your listing, and hence you won't necessarily be able to fill in all the fields. Apart from the Name though the fields are optional.

Find the _FillDirListingQ_FormatCustom method in your procedure by right-clicking on your ftp procedure in your application tree, and choosing Source. Then search for _FillDirListingQ_FormatCustom. Again, after the parent call, add the code to dechiper the listing.

For example

  ReturnValue = PARENT._FillDirListingQ_FormatCustom(p_Line)
  If self._DirListingFormat = 201 ! The number we set in step 1
    ! decipher the string into the queue here. For example if the name is
    ! always in the string from position 1 to position 20
    self.ControlConnection.DirListingQ.Name =
    ! or, if the line contains dir in the first column then the file is a directory name
    if sub(p_line,1,4) = 'dir '
      self.ControlConnection.DirListingQ.Attrib = ff_:DIRECTORY
    end
  End
 

You will find the code that deciphers the known formats in the methods
_FillDirListingQ_Format01 etc. Having a look at these can be helpful in seeing what approaches you can take to filling the queue fields.

Cheers
Bruce