Asheeown Posted February 16, 2007 Share Posted February 16, 2007 I'm trying to download everything from a directory using the script below, but it just the IF statement keeps coming up false, take a look $LocalDirectory = $LocalDirectory . $Type; $FtpConnect = ftp_connect($Server); $Login = ftp_login($FtpConnect, $Username, $Password); ftp_chdir($FtpConnect, $Directory); echo ftp_pwd($FtpConnect); echo "</br>"; $array = ftp_rawlist($FtpConnect, '/CDR'); $Files = GetFiles($array); ftp_close($FtpConnect); function GetFiles( $array ) { for ( $i = 1; $i < count($array); $i++ ) { $current = $array[$i]; $structure[$i]['perms'] = substr($current, 0, 10); $structure[$i]['number'] = trim(substr($current, 11, 3)); $structure[$i]['owner'] = trim(substr($current, 15, ); $structure[$i]['group'] = trim(substr($current, 24, ); $structure[$i]['size'] = trim(substr($current, 33, ); $structure[$i]['month'] = trim(substr($current, 42, 3)); $structure[$i]['day'] = trim(substr($current, 46, 2)); $structure[$i]['time'] = substr($current, 49, 5); $structure[$i]['name'] = substr($current, 55, strlen($current) - 55); } return $structure; } echo "<br><br>"; foreach($Files as $f) { $Remote = $f[name]; $Local = "CDRS/Raw/$f[name]"; if (ftp_get($FtpConnect, $Local, $Remote, FTP_BINARY)) { echo "Successfully written to $Local\n"; } else { echo "There was a problem\n"; } } The FTP connection is successful everything is fine till the get statement Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 16, 2007 Author Share Posted February 16, 2007 The only thing wrong that I've found so far is I closed the FTP connection before I tried the download, but still after I changed it no luck. Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 16, 2007 Author Share Posted February 16, 2007 Is their just a way to download the files, with their names Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 Anyway just to download the files without having to write them to a new? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 Are you sure that your "GetFiles" function is returning correct results? Try using ftp_nlist http://www.php.net/ftp_nlist Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 I echo out the names and everything of the file just fine Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 $LocalDirectory = $LocalDirectory . $Type; $FtpConnect = ftp_connect($Server); $Login = ftp_login($FtpConnect, $Username, $Password); ftp_chdir($FtpConnect, $Directory); echo ftp_pwd($FtpConnect); $Files = ftp_nlist($FtpConnect, "."); foreach($Files as $f) { $Remote = $f; $Local = "CDRS/Raw/$f"; if (ftp_get($FtpConnect, $Local, $Remote, FTP_BINARY)) { echo "Successfully written to $Local\n"; } else { echo "There was a problem\n"; } } ftp_close($FtpConnect); Sure it's more organized now but it still doesn't download any files Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 probbly something wrong with $local path Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 Well thats the thing, is this GET function just made to overwrite files or actually download the file right to the directory? Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 Or does it just need a directory to write the files to? does the directory have to have certain permissions? Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 i dont man it says local_file The local file path (will be overwritten if the file already exists). also well ftp_fget function exists too ftp_fget -- Downloads a file from the FTP server and saves to an open file ftp_fget() retrieves remote_file from the FTP server, and writes it to the given file pointer. so if its a pointer you can assign it to fopen() php functions and save it to whatever path you want and check if it exists and other stuff Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 Okay so now that I know that this will get the files without having to have a file already in place, whats wrong with my script, i even tried fget it's the same thing it always turns up false Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 Well I think that $local thing is just the filename of the local want you want to rename the file the files should all save around the php script it self if you make $local = f; I think the true why to set the paths would be to fiddle with the php.ini ftp saving paths etc... if you cant access them use ini_set() Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 Okay lost me there, I'm not following what your saying Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 im just saying maybe $local is just a filename not path like the old windows ftp.exe program you would just specify the file you wanted to download and the filename you wanted to rename it to IF you wanted to rename it that is.. it would download to desktop Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 $LocalDirectory = $LocalDirectory . $Type; $FtpConnect = ftp_connect($Server); $Login = ftp_login($FtpConnect, $Username, $Password); ftp_chdir($FtpConnect, $Directory); echo ftp_pwd($FtpConnect); $Files = ftp_nlist($FtpConnect, "."); ftp_chdir($FtpConnect,"/"); foreach($Files as $f) { $Remote = "/$Directory/$f"; $Local = "$f"; echo "File: $Remote is being written as $Local<br>"; if(ftp_fget($FtpConnect, $Local, $Remote, FTP_BINARY)) { echo "File: $Remote was downloaded successfully"; } else { echo "File: $Remote was not downloaded"; } } ftp_close($FtpConnect); The file path is now /CDR/"file", which is the exact path that it should be and still nothing Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 strange i see you tired to echo the password as well could really be the login thats bugged add to all functions like or die ("#1 error"); or die("#2 error"); my type of debugging I do Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 I'll set that up, but take a look at what the page returns http://waveleap.eonar.net/raw_cdrs.php All file names correct Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 I put a die error on the fget line or line 27 and thats where it gets stuck any way of finding out why? Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 confused it doesn't go up to line 27 and that link you posted is just listing files as File: blah.cdr is being written as blah.cdr File: blah.cdr was not downloaded maybe change FTP_BINARY To FTP_ASCII ok i see the not downloaded part is related to ftp_fget($FtpConnect, $Local, $Remote, FTP_BINARY its all that thats messed up I dont know I see no error there maybe on remote $Remote replace to '$Remote' on the ftp_fget line Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 17, 2007 Author Share Posted February 17, 2007 In my script it registers all the variables thats what the extra lines are but thats mostly FTP information thats not needed here FTP_ASCII doesn't work either, this is quite confusing, is their a log file or anything that I can look through, this is my server I can absolutely anything on Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 well try ftp_fget($FtpConnect, $Local, '$Remote', FTP_BINARY) with quotes I seen that off a php.net site a hour ago Confusing yes.. try some simple scripts that are proven to work maybe its a bad php configuration Example 360. Download a file and write it out $ftpStream = ftp_connect('my.ftp.server'); $loginResult = ftp_login($ftpStream, 'username', 'password'); if ($loginResult) { //local file location is in the same directory as the PHP file $destination = 'local.txt.'; //open a file pointer for writing in the same directory as the PHP file $fp = fopen($destination, 'w'); //retrieve the file from the FTP server and write it to the file pointer ftp_fget($ftpStream, $fp, 'remote.txt', FTP_ASCII); //close the file stream fclose($fp); //print out the contents of the file to the screen and close the file $fp = fopen($destination, 'r'); fpassthru($fp); } ftp_quit($ftpStream); Quote Link to comment Share on other sites More sharing options...
Asheeown Posted February 18, 2007 Author Share Posted February 18, 2007 Nope still coming up false Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 18, 2007 Share Posted February 18, 2007 than it has to be a php.ini problem says here on a FTP readme for some script that allow large file uploads and transfers, you may have to change these settings: in the file php.ini (directory C:\windows or /etc): upload_max_filesize, post_max_size, max_execution_time, memory_limit Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted February 18, 2007 Share Posted February 18, 2007 In your code you are passing $local as the string of the local filename, ftp_fget needs to receive the file handle E.g: $LocalF = fopen($local,'w'); ftp_fget($FtpConnect, $LocalF, $Remote, FTP_BINARY) fclose($LocalF); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.