Jump to content

Help with ftp_get


mtorbin

Recommended Posts

Hey all,

 

I've got the following script I'm working on.  It's probably not the best way to go about accomplishing my goal, but I'm new to PHP and I understand what I've written (which is what counts):

 

<?php
// Set your FTP variables here
$hostPhoenix = "[PUT DOWNLOAD HOST HERE]";
$userPhoenix = "[PUT DOWNLOAD USERNAME HERE]";
$passPhoenix = "[PUT DOWNLOAD PASSWORD HERE]";
$hostMaven   = "[PUT UPLOAD HOST HERE]";
$userMaven   = "[PUT UPLOAD USER HERE]";
$passMaven   = "[PUT UPLOAD PASSWORD HERE]";

// set up a connection or die
$connectionPhoenix = ftp_connect($hostPhoenix) or die("Couldn't connect to HOST");
$loginPhoenix = ftp_login($connectionPhoenix, $userPhoenix, $passPhoenix);

if (!$connectionPhoenix) {
    echo "FTP connection has failed!";
    exit;
}
elseif (!$loginPhoenix) {
    echo "Attempted to connect to $hostPhoenix for $userPhoenix";
    exit;
}
else {
    echo "Connected to $hostPhoenix for $userPhoenix<br><br>";
    $highlightContents = ftp_nlist($connectionPhoenix, "ARENA FOOTBALL 2008 SEASON/Weekly Highlights/");
    $dirStructure = "ARENA FOOTBALL 2008 SEASON/Weekly Highlights/Week ";

    for($x = 0; $x < sizeof($highlightContents); $x++) {
        for($weekNumber = 1; $weekNumber < 18; $weekNumber++)  {
            $weekStructure = $dirStructure . $weekNumber;
            if($highlightContents[$x] == $weekStructure) {
                // this is where I do all my work for each folder
                $weekNumberContents = ftp_nlist($connectionPhoenix, $weekStructure);

                for($y = 0; $y < sizeof($weekNumberContents); $y++) {
                    // this contains the actual url to the file with the file name
                    $justFileName = substr($weekNumberContents[$y], 52);
                    $localPath = "c:/phoenixWMV/" . $justFileName;

                    // the download process starts here
                    // If you comment the line below and uncomment the if loop, it fails.
                    echo $localPath . "<BR>";
                    /*echo "Starting download attempt for $justFileName<br>";
                    if (ftp_get($connectionPhoenix, $localPath, $weekNumberContents[$x], FTP_BINARY)) {
				    echo "Successfully downloaded to $justFileName<br><br>";
				} else {
				    echo "There was a problem with $justFileName<br><br>";
                    }*/
                }
            }
        }
    }
}

ftp_close($connectionPhoenix);
?>

 

I'm sorry I had to take out some of the constants, but that's a privacy protection issue.  With a little tweaking you should have no problems adapting this to make it work for testing.  The part that I'm most concerned about is this:

 

                    // the download process starts here
                    // If you comment the line below and uncomment the if loop, it fails.
                    echo $localPath . "<BR>";
                    /*echo "Starting download attempt for $justFileName<br>";
                    if (ftp_get($connectionPhoenix, $localPath, $weekNumberContents[$x], FTP_BINARY)) {
				    echo "Successfully downloaded to $justFileName<br><br>";
				} else {
				    echo "There was a problem with $justFileName<br><br>";
                    }*/

 

I can have the script shoot out all the names I want but when I go to download, it literally fails on the third one, yet the the third one is fully downloaded.  My questions are these:

 

1) Is there a buffering or timeout issue I should be looking into?

2) What could possibly be causing the script to not complete?

 

Thanks,

 

- MT

 

Link to comment
Share on other sites

Just as a follow up, here's the output with the echo left in:

c:/phoenixWMV/Week2VoicedOverPackage.wmv
c:/phoenixWMV/Week2TopPlays.wmv
c:/phoenixWMV/Week2Utah-Cleveland.wmv
c:/phoenixWMV/Week2Orlando-NewOrleans.wmv
c:/phoenixWMV/Week2Philadelphia-Chicago.wmv
c:/phoenixWMV/Week2sanjose-grandrapids.wmv
c:/phoenixWMV/Week2la-arizona.wmv
c:/phoenixWMV/WK1-DAL-GA.wmv
c:/phoenixWMV/WK1Columb-Color.wmv
c:/phoenixWMV/WK1ORL-PHILLY.wmv
c:/phoenixWMV/WK1-TB-KC.wmv
c:/phoenixWMV/WK1-NO-LA.wmv
c:/phoenixWMV/WK1-ARZ-UTAH.wmv
c:/phoenixWMV/WK1VoicedoverPackage.wmv
c:/phoenixWMV/WK1PlaysOfTheWeek.wmv
c:/phoenixWMV/DRAGONS_GLADIATORS.wmv
c:/phoenixWMV/Wk1-sabercats_rush.wmv

 

And here is the output with the if loop restored:

Starting download attempt for Week2VoicedOverPackage.wmv
Successfully downloaded to Week2VoicedOverPackage.wmv

Starting download attempt for Week2TopPlays.wmv
Successfully downloaded to Week2TopPlays.wmv

Starting download attempt for Week2Utah-Cleveland.wmv

 

The third file is fully downloaded but nothing beyond that happens.  Each of these files is approximately 4.9MB.

 

Thanks,

 

- MT

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.