Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
FTP Class
  • I wanted to test out included FTP class! I want to list all files in the root directory. I think that list_files() method is for that. Here's how far I have get...
    <?php
    
     class Controller_Index extends Controller {
    
      public function action_index() {
    
       $ftp = Ftp::factory( 'foobar' );
    
       $ftp->connect();
    
       Debug::dump( $ftp->list_files( 'public_html' ) );
    
       $ftp->close();
    
      }
    
     }
    

    Debug::dump returns 'bool(false)'. I thought that it should return something like array of files in that directory. Maybe there was a problem with connecting to server... How can I check it?
  • I assume that 'foobar' is a valid config item? you don't need to call connect(), the factory() method connects automatically. Dump the $ftp variable to see if the object has been created. If the connect failed, $ftp will be false. list_files() will return false if there is no connection, or if the remote ls command failed.
  • app/config/ftp.php:
    <?php
    
     return array(
    
      'foobar' => array(
       'hostname' => 'sftp://xxx.xxx.xxx.xxx',
       'username' => 'xxxxxx',
       'password' => 'xxxxxx',
       'port' => 21,
       'passive' => true,
       'ssl_mode' => false,
       'debug' => false
      )
    
     );
    

    It's possible to connect server using FileZilla (for example)! The problem is that Debug::dump( $ftp ) don't return 'false'. With correct data in app/config/ftp.php it return object with that data as properties. With incorrect data it do the same. No 'false' or whatever... ( When Debug::dump( $ftp->list_files() ) is done.. if data is correct... if incorrect... always 'false'. Help me, guys!
  • You speficied "sftp://xxx.xxx.xxx.xxx"; as hostname. However, the ftp class uses ftp_connect(), which only accepts a hostname without scheme, and besides that, it doesn't support sftp. You can get sftp working, but it requires ssh2, which is an optional pecl package, not something we want the fuel core to require. There is a possible solution by using the "PHP Secure Communications Library", a pure PHP implementation. It's LGPL so we should be able to include it if needed.
  • I hope you didn't think that I actually used x'es there. )) Last question: will this code would work if it would be simple ftp://?
  • With schema WanWizard is referring to the "sftp://"; so instead you just use "123.123.123.123" without the ftp:// of sftp://
  • Correct. The Class only supports plain FTP at the moment, no sftp.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion