开发者

Setting FTP mode in PHP cURL

I have some code that is using the PHP cURL library to upload some files via FTP.

I've been told to switch the FTP mode from passive to active, but I can't find how to do that - there 开发者_运维问答doesn't seem to be an option in the documentation relating to it. I'm not actually sure what mode it is currently using, or how I can view that.


The answer to this question is to use:

$curl = curl_init()
curl_setopt($curl, CURLOPT_FTP_USE_EPRT, true);

this will allow you to do Active ftp uploads.


As I understand it, the difference between passive and active ftp is that passive always uses the same port while active allows the client to specify the port that the server replies on.

From the CURL man page:

If you want to switch to active mode you need to use -P/--ftp-port

I think this corresponds to setting the CURLOPT_FTPPORT option.

With all that in mind, you'd be better off using the FTP functions (as MetaCipher says)


Why are you using cURL? PHP has a set of FTP functions:

http://php.net/manual/en/book.ftp.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜