adding ftp user via remoting script

Discussion in 'ISPConfig 3 Priority Support' started by saco721, Mar 20, 2019.

  1. saco721

    saco721 Member

    Hi,
    I am in the process of creating a remoting script that adds a new ftp user, but am getting the following errors :

    Here is the script :

    Code:
    <?php
    
    require 'soap_config.php';
    
    
    $client = new SoapClient(null, array('location' => $soap_location,
            'uri'      => $soap_uri,
            'trace' => 1,
            'exceptions' => 1));
    
    
    try {
        if($session_id = $client->login($username, $password)) {
            echo 'Logged successfull. Session ID:'.$session_id.'<br />';
        }
    
        //* Set the function parameters.
        $client_id = 1;
    
        $params = array(
            'server_id' => 1,
            'parent_domain_id' => $site_id,
            'username' => 'threep',
            'password' => 'woodietest',
            'quota_size' => 10000,
            'active' => 'y',
            'uid' => '5000',
            'gid' => '5000',
            'dir' => 'maybe',
            'quota_files' => -1,
            'ul_ratio' => -1,
            'dl_ratio' => -1,
            'ul_bandwidth' => -1,
            'dl_bandwidth' => -1
        );
    
        $affected_rows = $client->sites_ftp_user_add($session_id, $client_id, $params);
    
        echo "FTP User ID: ".$affected_rows."<br>";
    
    
        if($client->logout($session_id)) {
            echo 'Logged out.<br />';
        }
    
    
    } catch (SoapFault $e) {
        echo $client->__getLastResponse();
        die('SOAP Error: '.$e->getMessage());
    }
    
    ?>
    
    Any help is greatly appreciated.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    You have to set values that are valid for uid, gid and dir in the params array. Create an FTP user in ispconfig, then take a look into the dbispconfig database, table ftp_user, with phpmyadmin to see how the values must be.
     
  3. saco721

    saco721 Member

    Hi Till,
    I have manage to remove most of the errors, but am still getting :

    I have modified the script to :
    Code:
    <?php
    
    require('soap_config.php');
    
    $client = new SoapClient(null, array('location' => $soap_location,
    'uri' => $soap_uri,
    'trace' => 1,
    'exceptions' => 1));
    
    try {
    if($session_id = $client->login($username, $password)) {
    echo 'Logged successfull. Session ID:'.$session_id.'<br />';
    }
    
    $myname = 'testftp';
    $mypassword = 'QTr4R12345';
    
    $client_id = 13;
    
    $params = array(
    'server_id' => '1',
    'parent_domain_id' => '0',
    'username' => $myname,
    'password' => $mypassword,
    'quota_size' => '-1',
    'active' => 'y',
    'uid' => 'web263',
    'gid' => 'client13',
    'dir' => '/var/www/clients/client13/web263',
    'quota_files' => '100',
    'ul_ratio' => '-1',
    'dl_ratio' => '200',
    'ul_bandwidth' => '-1',
    'dl_bandwidth' => '100',
    );
    
    $affected_rows = $client->sites_ftp_user_add($session_id, $client_id, $params);
    
    
    echo "FTP User ID: ".$affected_rows."<br>";
    
    
    
    
    if($client->logout($session_id)) {
    echo 'Logged out.<br />';
    }
    
    
    } catch (SoapFault $e) {
    echo $client->__getLastResponse();
    die('SOAP Error: '.$e->getMessage());
    }
    
    ?>
    and I still get the following error, with no entry in ftp_users table :
    I have checked :
    server_id is 1 (in ftp_user table),
    parent_domain_id is 0 (in web_domain table),
    uid is web263 (a new uid, not in ftp_user table),
    gid is client13 (an existing gid in ftp_user table),
    dir is '/var/www/clients/client13/web263' (document_root entry in web_domain table),
    client_id is 13 (as in client table).

    Where have have I gone wrong?, thanks for your time!
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    The parent_domain_id is wrong, there cannot be a website with ID 0 which means that parent_domain_id cannot be 0 as well. And the uid and gid must match the web user and web group of the website where the FTP user belongs to, if there is another FRTP user with the same uid and gid does not matter as you can have as many FTP users for the same site that you want and all share the same uid and gid of the site.

    As I mentioned in my previous post, create an FTP user in ISPConfig interface and check out the values of the various fields.
     
  5. saco721

    saco721 Member

    Thanks for your advice Till!
     

Share This Page