230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
下面我们开始具体的实现:
Downloading a directory listing via FTP is slightly different from downloading or uploading a file. This is because the incoming data has to be parsed. First, set up a read stream to get the directory listing. This should be done
as it was for downloading a file: create the stream, register a callback function, schedule the stream with the run loop (if necessary, set up user name, password and proxy information), and finally open the stream. In the following example you do not need
both a read and a write stream when retrieving the directory listing, because the incoming data is going to the screen rather than a file.
In the callback function, watch for the kCFStreamEventHasBytesAvailable event.
After the data has been read to a buffer, set up a loop to parse the data. The data that is parsed is not necessarily the entire directory listing; it could (and probably will) be chunks of the listing. Create the loop to parse the
data using the functionCFFTPCreateParsedResourceListing,
which should be passed the buffer of data, the size of the buffer, and a dictionary reference. It returns the number of bytes parsed. As long as this value is greater than zero, continue to loop. The dictionary thatCFFTPCreateParsedResourceListing creates
contains all the directory listing information.
It is possible for CFFTPCreateParsedResourceListing to return a positive value, but not create a parse dictionary. For example, if the end of the listing contains information
that cannot be parsed, CFFTPCreateParsedResourceListing will return a positive value to tell the caller that data has been consumed. However, CFFTPCreateParsedResourceListing will
not create a parse dictionary since it could not understand the data.