List files on ftp using cURL in Matlab
I'm trying to get a directory listing of files on an ftp server using cURL commands within Matlab. Currently I'm trying something like:
[s,w] = dos('curl "ftp://name:password@ftpurl/directory/"');
which correctly gets the data and stores it in the variable w.
To get a list of the files in that directory I could try to parse out the names from the 'w' variable, but that could get a little complicated. Is there an easier way to obtain a list of the file names within the ftp directory, or do I have to go about trying to grab it out of the w variable?
Thanks!
EDIT
Using the -l command:
[s,w] = dos('curl "ftp://name:password@ftpurl/directory/"');
The resulting w looks something like:
0 0 0 763 0 0 2319 0 --:--:-- 2437FTPtest-D20110322-T022705.bot
FTPtest-D20110322-T022705.idx
FTPtest-D20110322-T022705.raw
FTPtest-D2开发者_Python百科0110322-T022746.bot
So it looks much better, but since the first file doesn't have a line feed before, it may be a little more difficult. Any ideas on how to get around this?
Thanks!
Try the -l (that's a lowercase L) option:
When listing an FTP directory, this switch forces a name- only view. Especially useful if you want to machine-parse the contents of an FTP directory since the normal directory view doesn't use a standard look or format.
This option causes an FTP NLST command to be sent. Some FTP servers list only files in their response to NLST; they do not include subdirectories and symbolic links.
(quote originates from http://curl.haxx.se/docs/manpage.html#-l)
How about use Matlab's built-in ftp support instead of shelling out to curl? See "help ftp".
精彩评论