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.