The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Copy a Full Directory via API

Discussion in 'cPanel Developers' started by spyke01, Sep 24, 2013.

  1. spyke01

    spyke01 Member

    Joined:
    Sep 24, 2013
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I am trying to copy all the files in 1 directory to another without the need to zip, copy, then extract. I have the following code:

    PHP:
    print $xmlapi->api2_query($account'Fileman''fileop', array( 'op' => 'copy''sourcefiles' => '/public_html/1000b0004''destfiles' => '/public_html/test' ) );
    This copies the files but it actually copies it to this file structure: /public_html/test/1000b0004 . How can I copy the files over and drop them into the 'test' folder
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    I don't believe that copy directory is an option in the cPanel File Manager. There's no option to copy a directory in the UI and the API call states that sourcefiles should be a comma-delimited list so it doesn't appear to be a recursive copy.

    Out of curiosity, why not just use FTP instead of the cPanel API? ftp_put has some code samples for copying directory structures.
     
  3. dalem

    dalem Well-Known Member
    PartnerNOC

    Joined:
    Oct 24, 2003
    Messages:
    2,577
    Likes Received:
    40
    Trophy Points:
    48
    Location:
    SLC
    cPanel Access Level:
    DataCenter Provider
    or easier yet just use ssh and use the

    cp-r

    command
     
  4. spyke01

    spyke01 Member

    Joined:
    Sep 24, 2013
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    This would be a nice solution for us in some cases but we have a client that has several directories around 200MB or more, with FTP it doesn't appear that we can copy from one remote directory to another remote directory so we'd have to download the files then re-upload. Alternatively a combination of FTP to get a list of the files and then using the API with the comma delimited list to copy them might work.

    This actually looks like a good way to accomplish this quickly. We will probably use the ssh2 php commands. Thanks for the heads up.
     
Loading...

Share This Page