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

is_directory_exists

is_directory_exists($server,$dir_name); - Проверить существование папки на FTP сервере

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

  • $server – адрес FTP сервера
  • $dir_name – относительный путь к папке FTP

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

    Пример использования
    <?php
    // Scenario: Check if a directory exists on FTP server
    
    $xhe_host = getenv("RPABOT_HOST_URL");
    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";
    
    // Example 1: Check if FTP directory exists
    $directoryName = "test_folder";
    echo "\n\nExample 1: Check if FTP directory exists: ";
    echo WEB::$ftp->is_directory_exists($ftp_server, $directoryName) . "\n";
    
    // Step: Disconnect from all FTP servers
    echo "2. 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:3039"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>ftp.is_directory_exists</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.is_directory_exists(ftp_server,"test_folder"), "\n")
    
    # 3 
    echo("3. Отсоединится от всех FTP серверов: ")
    echo(ftp.disconnect_all(), "\n")
    
    # конец
    
    # 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 = "127.0.0.1:3039";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>ftp.connect</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.is_directory_exists(ftp_server,"test_folder") + "\n");
    			
    			// 3 шаг
    			echo("3. Отсоединится от всех FTP серверов: ");
    			echo(ftp.disconnect_all() + "\n");
    
    			// конец
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:3039";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>ftp.connect</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.is_directory_exists(ftp_server, "test_folder") + "\n");
    
    // 3 шаг
    echo("3. Отсоединится от всех FTP серверов: ");
    echo( ftp.disconnect_all() + "\n");
    
    // конец
    
    // Quit
    app.quit();

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