humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений

get_file

get_file($server,$remote_file,$local_file,$flag_fail_exist=true,$file_attributes="128",$transfer_attributes="2",$context="1"); - получить файл с фтп на локальный диск

Функция на вход принимает параметры:

  • $server – адрес уже подключенного фтп подключения
  • $remote_file – путь к файлу, который надо скачать с фтп
  • $local_file – путь куда надо записать файл на локальном диске
  • $flag_fail_exist – прекратить операцию, если на локальном диске есть такой файл (true)
  • $file_attributes – после получения установить у файла заданные атрибуты
  • $transfer_attributes – аттрибуты передачи
  • $context – контекст

    После отработки функция возвращает результат своей работы в скрипт :
  • true – успешно получили
  • false – в процессе получения произошли ошибки

    Пример использования
    <?php
    // Scenario: Upload and download files from FTP server with different options
    
    $xhe_host = "localhost:7010";
    if (!isset($path)){
        // Path to the init.php file for connecting to the XHE API
        $path = "../../../Templates/init.php";
        // Including init.php grants access to all classes and functionality for working with the XHE API
        require($path);
    }
    
    // Beginning
    echo "\n<font color=blue>ftp->".basename (__FILE__)."</font>\n";
    
    // FTP account
    $ftp_server = "ftp://127.0.0.1";
    $login = "test";
    $password = "test";
    $port = "";
    $is_passive = true;
    $timeout = 3;
    $encoding = "";
    
    // Step: Connect to FTP server
    echo "1. Connect to FTP server: ".$ftp_server." : ";
    echo WEB::$ftp->connect($ftp_server, $login, $password, $port,  $is_passive, $timeout, $encoding) . "\n";
    
    // Step: Upload file to FTP server
    $localFilePath = "test/put_test.txt";
    $remoteFilePath = "/test.txt";
    $overwrite = false;
    echo "2. Upload file to FTP server: ";
    echo WEB::$ftp->put_file($ftp_server, $localFilePath, $remoteFilePath, $overwrite) . "\n";
    
    // Example 1: Download file from FTP server regardless of local existence
    $remoteFile = "test.txt";
    $localFile = "test/get_test.txt";
    echo "\n\nExample 1: Download file from FTP server regardless of local existence: ";
    echo WEB::$ftp->get_file($ftp_server, $remoteFile, $localFile, false) . "\n";
    
    // Example 2: Download file from FTP server only if it doesn't exist locally
    echo "Example 2: Download file from FTP server only if it doesn't exist locally: ";
    if (!WEB::$ftp->get_file($ftp_server, $remoteFile, $localFile, true))
    	echo "already exists\n";
    
    // Step: Disconnect from all FTP servers
    echo "3. Disconnect from all FTP servers: ";
    echo WEB::$ftp->disconnect_all();
    
    // End
    echo "\n\n";
    
    // Quit
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7013"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>ftp.xxxxxxxxx</font><hr>")
    
    # FTP аккаунт
    ftp_server = "ftp://127.0.0.1"
    login = "test"
    password = "test"
    port = 21
    is_passive = True
    timeout = 3
    encoding = ""
    
    # 1
    echo("1. Соединится с FTP сервером '" + ftp_server + "': ")
    echo(ftp.connect(ftp_server, login, password, port , is_passive, timeout, encoding), "\n")
    
    # 2
    echo("2. Запишем на FTP файл : ")
    echo(ftp.put_file(ftp_server, "test/put_test.txt", "test.txt", false), "\n")
    
    # 3
    echo("3. Получим с FTP файл в любом случае : ")
    echo(ftp.get_file(ftp_server, "test.txt", "test/get_test.txt", false), "\n")
    
    # 4
    echo("4. Получим с FTP файл, только если такого нет на локальной машине : ")
    if not ftp.get_file(ftp_server, "test.txt", "test/get_test.txt", true):
    	echo("уже есть\n")
    
    # 5 
    echo("5. Отсоединится от всех серверов : ")
    echo(ftp.disconnect_all(), "\n")
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>ftp.get_file</font><hr>");
    				
    			// FTP аккаунт
    			string ftp_server = "localhost";
    			string login = "test";
    			string password = "test";
    			int port = 21;
                bool is_passive = true;
                int timeout = 3;
                string encoding = "";
    
    			// 1
    			echo("1. Соединится с сервером '" + ftp_server + "': ");
    			echo(ftp.connect(ftp_server, login, password, port, is_passive, timeout, encoding) + "\n");
    			
    			// 2 шаг
    			echo("2. Получим с FTP файл в любом случае : ");
    			echo(ftp.get_file(ftp_server,"test.txt", "test/get_test.txt", false) + "\n");
    			
    			// 3 шаг
    			echo("3. Получим с FTP файл, только если такого нет на локальной машине : ");
    			echo(ftp.get_file(ftp_server,"test.txt", "test/get_test.txt", true) + "\n");
    			
    			// 4 шаг
    			echo("4. Отсоединится от всех FTP серверов: ");
    			echo(ftp.disconnect_all());
    
    			// конец
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>ftp.get_file</font><hr>");
    
    // FTP аккаунт
    const ftp_server = "ftp://127.0.0.1";
    const login = "test";
    const password = "test";
    const port = "";
    let is_passive = true;
    let timeout = 3;
    const encoding = "";
    
    // 1
    echo("1. Соединится с FTP сервером '" + ftp_server + "': ");
    echo(ftp.connect(ftp_server, login, password, port,  is_passive, timeout, encoding) + "\n");
    
    
    // 2 шаг
    echo("2. Получим с FTP файл в любом случае : ");
    echo(ftp.get_file(ftp_server,"test.txt", "test/get_test.txt", false) + "\n");
    
    // 3 шаг
    echo("3. Получим с FTP файл, только если такого нет на локальной машине: ");
    echo(ftp.get_file(ftp_server,"test.txt", "test/get_test.txt" ,true) + "\n");
    
    // 4 шаг
    echo("4. Отсоединится от всех FTP серверов : ");
    echo( ftp.disconnect_all() + "\n");
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    FTP    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум
    .