Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-14-2007, 09:16 PM   PM User | #1
ccurle
New Coder

 
Join Date: Dec 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
ccurle is an unknown quantity at this point
Php Ftp

I am trying to transfer a folder with files from server to another.

I found a script online and it sort of works. What it does is copy files from the root folder (which it shouldn't) and puts into the folder I am trying to copy from.

What I need is it to copy from the $ftproot into the $srcroot/$srcela folder.

Can someone please tell me what I am doing wrong.

PHP Code:
// --------------------------------------------------------------------
// THE TRIGGER
// --------------------------------------------------------------------

// set the various variables
$ftproot "/mnt/channel/Upload/16_2/";
$srcroot "/var/www/html/slides/";
$srcrela "16_2/";

// connect to the destination FTP & enter appropriate directories both locally and remotely
$ftpc ftp_connect("localhost");
$ftpr ftp_login($ftpc,"username","password");

if ((!
$ftpc) || (!$ftpr)) { echo "FTP connection not established!"; die(); }
if (!
chdir($srcroot)) { echo "Could not enter local source root directory."; die(); }
if (!
ftp_chdir($ftpc,$ftproot)) { echo "Could not enter FTP root directory."; die(); }

// start ftp'ing over the directory recursively
ftpRec ($srcrela);

// close the FTP connection
ftp_close($ftpc);

// --------------------------------------------------------------------
// THE ACTUAL FUNCTION
// --------------------------------------------------------------------
function ftpRec ($srcrela) {
    global 
$srcroot;
    global 
$ftproot;
    global 
$ftpc;
    global 
$ftpr;

    
// enter the local directory to be recursed through
    
chdir($srcroot.$srcrela);

    
// check if the directory exists & change to it on the destination
    
if (!ftp_chdir($ftpc,$ftproot.$srcrela)) {
        
// remote directory doesn't exist so create & enter it
        
ftp_mkdir ($ftpc,$ftproot.$srcrela);
        
ftp_chdir ($ftpc,$ftproot.$srcrela);
    }

    if (
$handle opendir(".")) {
        while (
false !== ($fil readdir($handle))) {
            if (
$fil != "." && $fil != "..") {
                
// check if it's a file or directory
                
if (!is_dir($fil)) {
                    
// it's a file so upload it
                    
ftp_put($ftpc$ftproot.$srcrela.$fil$filFTP_BINARY);
                } else {
                    
// it's a directory so recurse through it
                    
if ($fil == "templates") {
                        
// I want the script to ignore any directories named "templates"
                        // and therefore, not recurse through them and upload their contents
                    
} else {
                        
ftpRec ($srcrela.$fil."/");
                        
chdir ("../");
                    }
                }
            }
        }
        
closedir($handle);
    }

ccurle is offline   Reply With Quote
Old 03-14-2007, 10:48 PM   PM User | #2
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,460
Thanks: 89
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
Ive got no idea but If I was doing it I would probably use simple file reading and writing. Its no fuss
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 03-14-2007, 11:23 PM   PM User | #3
ccurle
New Coder

 
Join Date: Dec 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
ccurle is an unknown quantity at this point
Quote:
Originally Posted by timgolding View Post
Ive got no idea but If I was doing it I would probably use simple file reading and writing. Its no fuss
With what I am doing, it is a fuss.
ccurle is offline   Reply With Quote
Old 03-15-2007, 12:20 AM   PM User | #4
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Looks like you've just got the remote and local file paths backwards on the ftp_put() function.
__________________
Fumigator is offline   Reply With Quote
Old 03-15-2007, 04:30 AM   PM User | #5
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
whilst I am one of the biggest culprits for trying to use PHP for everything ... surely this would be a better job for rsync or unison or similar ?
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 03-15-2007, 10:25 PM   PM User | #6
ccurle
New Coder

 
Join Date: Dec 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
ccurle is an unknown quantity at this point
I can't use those. I am trying to build an app that moves files when needed.

I need to find a way of copying a directory from one server to another.

The above sort of works, but copies the wrong things.
ccurle is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:28 AM.


Advertisement
Log in to turn off these ads.