Can't Create FTP Account

youds

Verified User
Joined
Jul 11, 2008
Messages
490
Location
Lancashire, UK
Hi

I am trying to connect with DirectAdmin via admin user/pass details and am having trouble creating a user ftp account in the process.

Please see below.

Code:
class DirectAdmin {
	
	function newFtpAccount ($account, $domain, $username, $password) {
		
		// validation
		$account = addslashes($account);
		$domain = addslashes($domain);
		$username = addslashes($username);
		$password = addslashes($password);
		
		$sock = new HTTPSocket;  
		$sock->connect('***.***.***.***',2222);  
		$sock->set_login('admin','hidden');  
		$sock->set_method('POST');  
		$sock->query('/CMD_API_FTP',   array( 
			'action' => 'create', 
			'domain' => $domain, 
			'user' => $username, 
			'type' => 'custom', 
			'path' => "/home/$account/domains/$domain/public_html/", 
			'passwd' => $password, 
			'passwd2' => $password 
		)); 

		$result = $sock->fetch_body();   
		echo "<pre>";
		var_dump($sock); 
		var_dump($result);
	}
	
}

$directadmin = new DirectAdmin();
$directadmin->newFtpAccount('testing1', 'testing123.createwebsite.design', 'testing1-ftp', 'simplepass');

If you could point me in the right direction that would be great.

Many thanks
 
Note I can't get anything working, see results below:

Code:
object(HTTPSocket)#2 (20) {
  ["version"]=>
  string(5) "2.7.2"
  ["method"]=>
  string(4) "POST"
  ["remote_host"]=>
  string(14) "***.***.***.***"
  ["remote_port"]=>
  int(2222)
  ["remote_uname"]=>
  string(5) "admin"
  ["remote_passwd"]=>
  string(8) "password"
  ["result"]=>
  string(9) "HTTP/1.1 "
  ["result_header"]=>
  string(9) "HTTP/1.1 "
  ["result_body"]=>
  NULL
  ["result_status_code"]=>
  NULL
  ["lastTransferSpeed"]=>
  float(0.0087890625)
  ["bind_host"]=>
  NULL
  ["error"]=>
  array(0) {
  }
  ["warn"]=>
  array(0) {
  }
  ["query_cache"]=>
  array(1) {
    [0]=>
    string(292) "POST /CMD_API_FTP_SHOW HTTP/1.0
User-Agent: HTTPSocket/2.7.2
Host: 167.99.195.173:2222
Accept: */*
Connection: Close
Authorization: Basic YWRtaW46cTJMNSQhZGY=
Content-type: application/x-www-form-urlencoded
Content-length: 52

domain=testing123.createwebsite.design&user=testing1

"
  }
  ["doFollowLocationHeader"]=>
  bool(true)
  ["redirectURL"]=>
  NULL
  ["max_redirects"]=>
  int(5)
  ["ssl_setting_message"]=>
  string(76) "DirectAdmin appears to be using SSL. Change your script to connect to ssl://"
  ["extra_headers"]=>
  array(0) {
  }
}
return value from $sock->fetch_body():
NULL
 
So I carried on with this and found changing to GET instead of POST started to return results.

But now, I'm finding it difficult to create FTP accounts for users without knowing their passwords. So, trying to change their password, I get the following which is a bit strange

Code:
$sock->query('/CMD_API_USER_PASSWD',
		        array(
		                'username' => $account,
		                'passwd' => $password,
		                'passwd2' => $password,
		                'options' => 'no',
		                'system' => 'no',
		                'ftp' => 'yes',
		                'database' => 'no'
		        )
		);$result = $sock->fetch_parsed_body();
		echo "<pre>";
		var_dump($result);

array(3) {
  ["error"]=>
  string(1) "1"
  ["text"]=>
  string(25) "Unable to change password"
  ["details"]=>
  string(25) """ is an invalid username"
}

Anybody able to help?
 
I never got an answer on the said bug; however have managed to work around the problem using bash scripting.

Kind regards
 
Post #1. In order to create a FTP account under user "testing1", you should not connect to Directadmin as admin. You should connect as user "testing1"

PHP:
$sock->set_login('testing1','hidden');

Or use "Login-as" with the API https://www.directadmin.com/api.php

PHP:
$sock->set_login('admin|testing1','hidden');


if type=custom, you should use:

PHP:
'custom_val' => "/home/$account/domains/$domain/public_html/",

instead of

PHP:
'path' => "/home/$account/domains/$domain/public_html/",

See https://www.directadmin.com/features.php?id=350


Post #2. In the second post it alerts you about "DirectAdmin appears to be using SSL. Change your script to connect to ssl://"


Post #3. /
CMD_API_USER_PASSWD requires method POST: https://www.directadmin.com/features.php?id=736

And I believe /CMD_API_FTP also requires POST, but you should resolve the listed above issues.


Post #4. Forums aren't any kind of a live chat to get an instant response. Specially during week-days and holidays... Most of us here are users and administrators of our own servers with DA and we spare our free time to help others ;)


Probably there are some other issues, not noticed by me. Anyway you might try and fix the mentioned.
 
Back
Top