基于IOS的FTP详解(一)获取列表

项目中有用到ftp对远程文件进行管理,这里整理一下,主要是通过CFNetwork来实现的。

首先对ftp进行一个小得概述,后面会通过抓包工具进行详细的讲述请求过程:

FTP地址格式:

无密码:

ftp://<服务器地址>

有密码:

ftp://<login>:<password>@<ftpserveraddress>

ftp采用两个TCP连接来传输一个文件,一个是控制连接,一个是数据连接,如下图所示:


通常Unix实现的ftp客户和服务器使用流方式传输

我们通过终端登录到FTP服务端以后会返回如下信息:

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.

通过实
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值