Jump to content

Copying files and folders on the server


pwired
 Share

Recommended Posts

How do you copy files and folders on the server with FTP ?

1. Downloading and then re-uploading is not an option

2. Some FTP clients let you do "move" a file or folder on the server but none of them let you do "copy"

    (why is that anyway ?)

Ok, copying files and folders on the server can be done inside cpanel but this is very tedious,

lot's of mouse clicks and lot's of going up and down folder paths.

Does anyone know a FTP client with "copy" option for files and folders on the server ?

If not ftp, is there any other tool that can do this job ?

Link to comment
Share on other sites

Thanks Josh, tried WinSCP but it is downloading to a temp first and then upload it back to the server :(

If there is nothing else then ok will use Cpanel but that is not fun at all.

I guess there must be a nice php copy folder script somewhere that you can run directly on the server ?

Link to comment
Share on other sites

Thanks Soma, going to try wire copy asap!

In the mean time a php newbie like me found this after digging with google

and I tested it, and it is working ! This is much more fun than using CPanel ! :)

<?php
/**
     * /root/path/source/directory/htdocs/wire
     * 
     * /root/path/destination/directory/htdocs/backup/wire
     * 
*/
copyr("/root/path/source/directory/htdocs/wire","/root/path/destination/directory/htdocs/backup/wire");
echo "copying is done";

    function copyr($source, $dest){
    // Simple copy for a file
    if (is_file($source)) {
    $c = copy($source, $dest);
    chmod($dest, 0777);
    return $c;
    }
     
    // Make destination directory
    if (!is_dir($dest)) {
    $oldumask = umask(0);
    mkdir($dest, 0777);
    umask($oldumask);
    }
     
    // Loop through the folder
    $dir = dir($source);
    while (false !== $entry = $dir->read()) {
    // Skip pointers
    if ($entry == "." || $entry == "..") {
    continue;
    }
     
    // Deep copy directories
    if ($dest !== "$source/$entry") {
    copyr("$source/$entry", "$dest/$entry");
    }
    }
     
    // Clean up
    $dir->close();
    return true;
    }
?>

This code is not mine of course I found it on the net and managed to get my source and destination dirs right

I guess it is no problem to use this code in private use. Anyway this must look something very simple for you pro coders but for me php is still like chinese :lol:

What I also noticed:

I can't get this php code to work when I want to copy to a dir above the htdocs folder, but I CAN do this with ftp.

Somehow my hoster has blocked it for php but not for ftp

CPanel stays unbeatable when it comes to deleting a folder with many files in it. With CPanel I can delete a huge folder in seconds, while deleting that same folder with ftp can take half an hour !!

But running your own php scripts in htdocs is much more fun, so next try is going to dig a php script to delete a folder ^_^

Now gonna try Soma's WireCopy

Link to comment
Share on other sites

wireCopy() didn't show up anywhere with google, nor did it show up in the php file function list -

so long for wireCopy() on a sunday afternoon :P

Anyway this newbie php found works too:

<?php
recurse_copy("/root/path/htdocs/wire","/root/path/htdocs/backup/wire");
echo "copying is done";
function recurse_copy($src,$dst) {
    $dir = opendir($src);
    @mkdir($dst);
    while(false !== ( $file = readdir($dir)) ) {
        if (( $file != '.' ) && ( $file != '..' )) {
            if ( is_dir($src . '/' . $file) ) {
                recurse_copy($src . '/' . $file,$dst . '/' . $file);
            }
            else {
                copy($src . '/' . $file,$dst . '/' . $file);
            }
        }
    }
    closedir($dir);
    return true;
}
?>

Is that return true; safe to do for clean up ?

Enuf coding, time for cold beer + sofa + tv

Link to comment
Share on other sites

maybe i'm misunderstanding the op, but i copy files and folders all the time using Coda, never had a problem.... (it probably does it behind the scenes, creating the folder and uploading it etc..) and it's transparent to the user; so my recommendation would be to use a good ftp client that supports this?

Link to comment
Share on other sites

By the name, I woud say that this function belongs to a very nice framework called ProcessWire

Oops - sorry - missed that completely !! Was so focused on php code - pclzip.lib.php - pear - etc. etc.

Will have to look in that tomorrow, it's already deep in the night here. Time is always against us.

Already am curious what code or class is behind wirecopy.

my recommendation would be to use a good ftp client that supports this?

Thing is - there is no ftp client that supports copying folders on the server, has something to do with the ftp protocol. Strangely enough there are ftp clients that support moving folders on the server.

I think copying folders on a server is possible with the pear tar_archive class

If anyone knows a way how to (fast) copying folders on a hosting server, e.g. copying folders around in htdocs,

- but not using shell - telnet - ssh - or php system - - - please let me know.

Link to comment
Share on other sites

Coda http://panic.com/coda/

Copy Folder: Select Folder, Edit > Duplicate

Copy File: Select File > Duplicate

Edit: i use these functions so often i can't imaging working without being able to duplicate files and folders on the server. also you can option+drag files and folders to different directories and that copies them also.

Link to comment
Share on other sites

Coda is for mac os, - - - looking for os independent php script, e.g. see above, or browser app.

Also duplicate folder with ftp first download folder to temp and then second re-upload the folder to the

server (like winscp for windows) which is actually a waist of time and bandwidth in case of big folders.

A script running on the server will copy directly on the server and will be much faster.

Link to comment
Share on other sites

But running your own php scripts in htdocs is much more fun, so next try is going to dig a php script to delete a folder ^_^

http://php.net/rmdir should take care of that. And while you are on that page, read through all the "Filesystem Functions" in the left sidebar.

Also,  if you haven't seen it before, PYDIO is the best php/ajax driven file manager out there and it's free and open source:

http://pyd.io/

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...