5

I'm about to get my hands dirty writing an FTP wrapper for PHP, I just need to perform the basics:

  • read / write and append to files
  • list / chmod and delete files / folders

Unfortunately I only had to mess with FTP within PHP once to answer this question, and I got somewhat disappointed with the ftp extension, mainly because it ain't trivial to distinguish between files and folders and the overall speed wasn't great.

As far as I know PHP has four distinct ways of interacting with FTP servers:

  1. Pure Socket Implementation
  2. File Wrappers
  3. FTP Extension
  4. CURL Extension

Now, I don't want to code the FTP client protocol myself, so option #1 is out of the equation.

File wrappers are great if I need to do something trivial like getting a single file, but they are extremely slow if I need to perform more complex operations since each call will open its own connection.

That leaves me with the FTP and CURL extensions, and here is where I need some guidance. As I said before I am not a big fan of the FTP extension, on the other hand I've never used CURL to FTP so I can't objectively compare one with the other.

Has anyone ever tried both approaches? What are your thoughts on them? Is the CURL option faster?

Also, are there any alternatives I'm not aware of?

Community
  • 1
  • 1
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
  • This is a small FTP library https://github.com/lazzard/ftp-bridge (not finished yet), it allows you to communicate with the server in a low implementation level (Stream Based) without the FTP extension, however i still working in it, and i wish to get some help. – Shakir El Amrani Aug 17 '20 at 20:24

2 Answers2

2

Have you looked at the PEAR package Net_FTP?

Jani Hartikainen
  • 42,745
  • 10
  • 68
  • 86
  • Didn't though of that, seems great - however, it still relies on the `ftp` extension and I'm afraid the performance won't be great. I would really like to hear some feedback on the CURL approach. – Alix Axel Apr 24 '11 at 00:59
1

I've tried both for one proj. Was needed to upload some file via ftps+auth connection with encryption and authentication then to get response code and XML info, kind of XML-RPC exchanging so at the end could not even come closer to the solution with php-ftp-extension and everything was accomplished with some debugging (CURLOPT_VERBOSE) and configuring with PHP-CURL. So I vote for CURL, it is from 1997-th and works great!

Igor
  • 2,619
  • 6
  • 24
  • 36