jadeg Posted March 31, 2014 Share Posted March 31, 2014 I am trying to list the files in a particular directly from a php script. ftp_pwd works fine but ftp_nlist or ftp_rawlist do not any idea why this could be so? Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/ Share on other sites More sharing options...
Zane Posted March 31, 2014 Share Posted March 31, 2014 Are the files on the same server as your script? If so, there is no reason to use FTP at all. You can use glob() to get an array of files. Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474510 Share on other sites More sharing options...
Psycho Posted March 31, 2014 Share Posted March 31, 2014 (edited) Did you turn on error reporting? If not, turn it on. If so, what errors are you receiving? Heck, you may be using the commands wrong for all we know, but since you failed to provide a single line of code we would only be guessing. Edited March 31, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474511 Share on other sites More sharing options...
jadeg Posted March 31, 2014 Author Share Posted March 31, 2014 (edited) The files are not on the same file as the script. This is my code so far <?php $ftp_server="eeeproject.host22.com"; $ftp_user_name="user"; $ftp_user_pass="password"; $conn_id = ftp_connect($ftp_server) or die ("Couldn't connect to $ftp_server"); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); if($login_result){ ftp_chdir($conn_id, "public_html"); echo ftp_pwd($conn_id); $buff= ftp_nlist($conn_id, '.'); var_dump($buff); } ftp_close($conn_id); ?> Edited March 31, 2014 by jadeg Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474513 Share on other sites More sharing options...
Psycho Posted March 31, 2014 Share Posted March 31, 2014 Works for me on my FTP server. Are you getting any output for the var_dump()? You should get a Boolean false if the function is failing. Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474515 Share on other sites More sharing options...
jazzman1 Posted March 31, 2014 Share Posted March 31, 2014 Most likely this library isn't installed to this version of php. Did you try to turn on error reporting as Psycho suggested above? I believe not. You would also check whether a ftp_connect function exists or not to your current version of laguage: if(!function_exists('ftp_connect')){ echo "Not exist"; } else { echo "Exists"; } // to get all defined functions echo '<pre>'.print_r(get_defined_functions(),true).'</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474522 Share on other sites More sharing options...
jadeg Posted March 31, 2014 Author Share Posted March 31, 2014 ftp_connect definitely exists I have tried that. Psycho as you mentioned I am getting a boolen false meaning the function is falling. My question is what can I do to correct that Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474526 Share on other sites More sharing options...
jazzman1 Posted March 31, 2014 Share Posted March 31, 2014 I'm not familiar with this library, however, at a starting point add the following error reporting functions on top of the file. <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); $ftp_server="eeeproject.host22.com"; $ftp_user_name="user"; $ftp_user_pass="password"; $conn_id = ftp_connect($ftp_server) or die ("Couldn't connect to $ftp_server"); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); if($login_result){ ftp_chdir($conn_id, "public_html"); echo ftp_pwd($conn_id); $buff= ftp_nlist($conn_id, '.'); var_dump($buff); } ftp_close($conn_id); What OS is the server running? Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474566 Share on other sites More sharing options...
jadeg Posted April 1, 2014 Author Share Posted April 1, 2014 It's on windows Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474612 Share on other sites More sharing options...
jazzman1 Posted April 1, 2014 Share Posted April 1, 2014 (edited) Try to set the second parameter of a ftp_nlist function to null or to empty string, both cases work to me (linux server). $buff= ftp_nlist($conn_id, ''); // or $buff= ftp_nlist($conn_id, NULL); You can also turn a passive mode on in case the ftp server required. Try, <?php $ftp_server = "eeeproject.host22.com"; $ftp_user_name = "user"; $ftp_user_pass = "password"; $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // turn passive mode to on ftp_pasv($conn_id, true); if ($login_result) { ftp_chdir($conn_id, "public_html"); echo ftp_pwd($conn_id); $buff = ftp_nlist($conn_id,'.'); var_dump($buff); } ftp_close($conn_id); Edited April 1, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474621 Share on other sites More sharing options...
Solution jadeg Posted April 3, 2014 Author Solution Share Posted April 3, 2014 Thanks! Got it working when passive mode was turned on Quote Link to comment https://forums.phpfreaks.com/topic/287414-ftp-commands/#findComment-1474775 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.