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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/ 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. Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-186641 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-186699 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? Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-186871 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-186876 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-186907 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187293 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 probbly something wrong with $local path Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187295 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? Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187296 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? Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187345 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187347 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187520 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() Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187536 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187547 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187548 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187556 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187560 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187562 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? Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187565 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187574 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187577 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); Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187581 Share on other sites More sharing options...
Asheeown Posted February 18, 2007 Author Share Posted February 18, 2007 Nope still coming up false Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187602 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 Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187607 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); Link to comment https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.