API Problem : FILE Manager : Delete a folder or file

cpsync

Verified User
Joined
Apr 9, 2010
Messages
11
Hi
I am trying to delete a folder/file using the api, but it it not working

Code:
[root@da backups]# pwd
/home/ykbrgyxrx/domains/ykbrgyxrx.com/public_html/backups
[root@da backups]# ls
2010  i.html
[root@da backups]#

There is a folder "2010" and a file "i.html"

Here is my api call ( php )

PHP:
$da_username = "ykbrgyxrx";

$path = "/domains/ykbrgyxrx.com/public_html/backups/";
$file = "i.html";



$array = array('action' => 'multiple',
    'path' => $path ,
    'button' => 'delete',
    'path' => $path ,
    'select0' => $file
    );  
    
        
$result = connect_da('/CMD_API_FILE_MANAGER',$array,"GET",$da_username);
      
echo "<pre>";
print_r($result);


The above function will login as the user, using the admin password ( login-as method , admin|{username}

I get this output

Array
(
[error] => 0
)


However, when I checked the file it is not deleted



Debug info

[root@da directadmin]# ./directadmin b2000 | grep string

Code:
Post string: action=multiple&path=%2Fdomains%2Fykbrgyxrx.com%2Fpublic_html%2Fbackups%2F&button=delete&select0=i.html

Please let me know why Da is not deleting file
 
Hello,

Using the "./directadmin b2000" method, delete the file using your web browser. Compare what the browser passes DA with what your script is passing DA.

John
 
Hello,

Note that select0 should point to the full path filename, not just the local filename.

eg:
select0=/domains/ykbrgyxrx.com/public_html/backups/i.html

I'll update the docs to clarify this.

Also, the path doesn't need the trailing / character, but shouldn't matter.

Lastly, since the browser POST's the data, I'd recommend also doing a POST.
However, I did check the code and using a GET should also work fine, as per the documentation.
In general when debugging, I find it best to try and simulate the real thing as closely as possible.

PHP:
$path = "/domains/ykbrgyxrx.com/public_html/backups"; 
$file = $path."/i.html"; 

$array = array('action' => 'multiple', 
    'path' => $path , 
    'button' => 'delete', 
    'path' => $path , 
    'select0' => $file 
    );
John
 
Hello,

As mentioned in the error, /public_html is a link.
You would only be able to delete the link.. or the true path.. but not a path below the link.

eg, you can delete:
/public_html

but you cannot delete:
/public_html/files

The link actually points to:
/domains/domain.com/public_html

so the correct value you'd delete would be:
/domains/domain.com/public_html/files

and not /public_html/files

John
 
Code:
:2222/CMD_API_FILE_MANAGER?action=multiple&path=/domains/ykbrgyxrx.com/public_html/backups&button=delete&select0=/domains/ykbrgyxrx.com/public_html/backups/2002

output

error=1&text=Unable to delete files&details=Unable to delete directory /domains/ykbrgyxrx.com/public_html/backups/2002: <b>The directory /domains/ykbrgyxrx.com/public_html/backups/2002 is not empty</b><br>
<br>



please advise how can I remove a directory with contents ( recursive delete )
 
Hello,

That is likely not related to an API issue, but more likely a permission issue.
Check to see if you can delete the path via your browser.

Likely there are root or apache owned files, or something like that preventing the directory from being removed.

John
 
Hi
So directadmin support recursive folder deletion through api ?

edit:
Found the issue, the folder was under root:root

:)
 
Last edited:
Back
Top