How to parse directory structure from FTP LIST

L

lg

I downloaded a directory listing using FTP command LIST. The listing is like
below:
drwxr-xr-x 2 test directory 3072 Aug 8 17:16 .
drwxr-xr-x 4 test directory 9216 Aug 8 20:28 ..
-rw-r--r-- 1 test directory 72 Aug 2 16:32 20155.txt
-rw-r--r-- 1 test directory 76 Feb 14 18:02 41257.txt
-rw-r--r-- 1 test directory 75 Aug 2 16:32 43916.txt

First of all is the directory list standard? Does file/directory name start at
column 56 etc?

If not how do FTP programs parse info if it's not standardised?
 
U

usenet

First of all is the directory list standard? Does file/directory name start at
column 56 etc?
If not how do FTP programs parse info if it's not standardised?

FTP output (and even commands) differ widely between systems. For
example, on my system (AIX), LIST is not even a valid FTP command. In
AIX, if you do 'DIR' then you get a long listing (like you get with
LIST), but if you do 'ls' then you get a list of only the filenames.
Maybe your FTP program also has a command to list only the filenames.

But if you want to really assure that the system is as bullet-proof as
possible then you should use an FTP module such as Net::FTP instead of
relying on the result of system commands. With a module you always
know what to expect, and it is not affected by the vagaries of your
particular ftp program (and it won't break if your ftp program is
changed or upgraded and the output changes).
 
L

lg

FTP output (and even commands) differ widely between systems. For
example, on my system (AIX), LIST is not even a valid FTP command. In
AIX, if you do 'DIR' then you get a long listing (like you get with
LIST), but if you do 'ls' then you get a list of only the filenames.
Maybe your FTP program also has a command to list only the filenames.

But if you want to really assure that the system is as bullet-proof as
possible then you should use an FTP module such as Net::FTP instead of
relying on the result of system commands. With a module you always
know what to expect, and it is not affected by the vagaries of your
particular ftp program (and it won't break if your ftp program is
changed or upgraded and the output changes).

Thank you for your reply.

If system is only limited to those who understand LIST command is the list-file
structure standardised/documented somewhere?
 
T

Tad McClellan

The FTP protocol is standardised. FTP programs are not standardised.

If system is only limited to those who understand LIST command is the list-file
structure standardised/documented somewhere?


Maybe. The commands your FTP program have might be documented in the
docs for your FTP program.

But you have already been given the correct solution to your problem,
namely, rely on the FTP protocol (via a module) rather than on a
particular FTP program.

Do you have some reason for not adopting the suggested correct solution?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top