0

I am looking for some advice on the best way to pull down an xml file off an ftp address and display the content in an article or module.

https://en-gb.wordpress.org/plugins/wp-expert-agent-xml-feed/ is exactly what I'm after for Joomla. It is for displaying houses/properties.

From initial research, I'm not finding anything that does this for Joomla, I would really appreciate some suggestions.

Thank you

4
  • Do you know any PHP? You could probably take a feed feeder and then add the authentication to the cURL request. Jun 7, 2018 at 12:19
  • I don't YellowWebMonkey unfortunately. Is there nothing in Joomla that can already do this? Thanks
    – phil_c64
    Jun 7, 2018 at 12:41
  • I actually want to do this too. Do you have access to Agent Expert? Reading an XML file is not an issue, I'm pretty sure you shouldn't need FTP.
    – Eoin
    Jan 5, 2019 at 19:31
  • If you're still interested perhaps contact me via my Twitter twitter.com/ImSquareBalloon
    – Eoin
    Jan 5, 2019 at 19:33

2 Answers 2

1

I don't know of any extension that out of the box will authenticate to get the feed.

Joomla Works makes a solid feed reader (https://www.joomlaworks.net/extensions/free/simple-rss-feed-reader). You might contact them to see if they could add the feature.

You could also try customizing the helper.php file in it include a cURL authentication similar to https://stackoverflow.com/questions/20064271/how-to-use-basic-authorization-in-php-curl/20064360. However, that would depend on how the FTP is configured and whether it would even accept that kind of request.

1
  • Thank you for the ideas YellowWebMonkey, I will have to pass on this information to see what can be done as this is out of my skillset.
    – phil_c64
    Jun 7, 2018 at 17:14
0

This is the part of the file that you would find most relevant. It is contained in /inc/admin/views/class-admin.php

  public function download_xml( $remote_file, $remote_user, $remote_pass )  {
    // Continue if FTP extension exists on the PHP server
    if(function_exists('ftp_connect')) {
      //#STEP 1 - Connect to FTP

      $ftp_host = 'ftp.expertagent.co.uk'; // this is constant
      $ftp_port = 21; // this is constant
      $ftp_timeout = 10; // 10 seconds timeout
      $ftp_username = $remote_user;
      $ftp_password = $remote_pass;

      $file = $remote_file;
      $extension = pathinfo($file, PATHINFO_EXTENSION); // gotta be 'xml'
      $filename = basename($file, '.xml');

      // make sure it's XML since that's what we do!
      if( $extension !== 'xml' ) {
        update_option( 'fse_wpeaxf_remote_file', '' );
        exit( __( 'File does not exist. Please specify an XML file.', $this->plugin_name ) . ' <a href="' . admin_url('admin.php?page='. $this->plugin_name ) . '">' . __( 'Go back', $this->plugin_name ) . '</a>.' );
      }

      //#STEP 2 - Download File
      $ftp_connection = ftp_connect( $ftp_host, $ftp_port, $ftp_timeout );
      if( !$ftp_connection ) {
        exit( __( 'Could not connect to FTP at the moment. Please check your FTP server status and try again.', $this->plugin_name ) . ' <br />' . __( 'If unsure, please contact Expert Agent at', $this->plugin_name ) . ' [email protected] <a href="' . admin_url('admin.php?page='. $this->plugin_name ) . '">' . __( 'Go back', $this->plugin_name ) . '</a>' );
      }

      $login_result = ftp_login( $ftp_connection, $ftp_username, $ftp_password );
      if( !$login_result ) {
        exit( __( 'Login details did not match. Please check your FTP login details and try again.', $this->plugin_name ) . ' <a href="' . admin_url('admin.php?page='. $this->plugin_name ) . '">' . __( 'Go back', $this->plugin_name ) . '</a>' );
      }

      $plugin_basename = explode( "/", plugin_basename( __FILE__ ), 2 )[0]; // get the plugin's directory name  // need to change

      // $upload_dir = wp_upload_dir(); // Array of key => value pairs // don't need
      $plugin_upload_dir = JURI::root() . 'media/' . $plugin_basename . '/';
      $plugin_upload_dir_xml = JURI::root() . 'media/' . $plugin_basename . '/xml/';

      // Create Directory /media/plugin_name/
      if(!file_exists( $plugin_upload_dir )) {
        mkdir( $plugin_upload_dir, 0755, true );
      }

      // Create Directory /media/plugin_name/xml/
      if(!file_exists( $plugin_upload_dir_xml )) {
        mkdir( $plugin_upload_dir_xml, 0755, true );
      }

      $local_file_path = $plugin_upload_dir_xml . $file;
      $server_file_path = $file;

      ftp_pasv( $ftp_connection, true ); // So we don't get a BINARY Warning...
      ftp_get( $ftp_connection, $local_file_path, $server_file_path, FTP_BINARY );
      ftp_close( $ftp_connection );

    } else {

      exit( __( 'Please enable FTP on your server before proceeding.', $this->plugin_name ) . ' <a href="' . admin_url('admin.php?page='. $this->plugin_name ) . '">' . __( 'Go back', $this->plugin_name ) . '</a>' );

    }
  }

In Joomla! you would need to change some parts, I made an extremely rough start on this but I'll probably create this as a commercial extension in time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.