ksun Posted March 2, 2013 Share Posted March 2, 2013 ok, so i'm kinda new to ftp with php, i'm having difficulties with getting contents of my public_html directory (i'm using a free web hosting service) when i'm using ftp_rawlist(); to retrieve public_html content, it returns an empty array. <?php $ftpServer = "usetheforce.hostei.com"; $ftpUser = "*"; $ftpPass = "*"; $conn = @ftp_connect($ftpServer) or die("Couldn't connect to FTP server"); $login = @ftp_login($conn, $ftpUser, $ftpPass); $workingDir = ftp_pwd($conn); echo "Files for directory: $workingDir<br><br>"; $fList = @ftp_nlist($conn, $workingDir); if(is_array($fList)) { $newDir = $fList[4]; // public_html if(ftp_chdir($conn, $newDir)) { $fList1 = ftp_rawlist($conn,$newDir); echo ftp_chdir($conn, $newDir); if(is_array($fList1)) { echo "Files for directory: $newDir<br><br>"; echo sizeof($fList1); for($i = 0; $i < sizeof($fList1); $i++) { echo $fList1[$i] . "<br>"; } } else { echo "$newDir contains no files."; } } else { echo "An error occured while changing to $newDir or $newDir is not a directory"; } } else { echo "$workingDir contains no files."; } ?> i've kinda isolated the problem, when i use: echo chdir($conn, "public_html") , it says: Warning: ftp_chdir() [function.ftp-chdir]: Can't change directory to public_html:. if anyone could help that would be gr8 thanks Link to comment https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/ Share on other sites More sharing options...
lachild Posted March 4, 2013 Share Posted March 4, 2013 Question: Before I go digging into your code, does the user you're ftping with have read rights to that directory? Link to comment https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/#findComment-1416340 Share on other sites More sharing options...
ksun Posted March 4, 2013 Author Share Posted March 4, 2013 yes Link to comment https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/#findComment-1416366 Share on other sites More sharing options...
teynon Posted March 4, 2013 Share Posted March 4, 2013 Can you post the html output of your code here and also do a var_dump or print_r of the directory array? Link to comment https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/#findComment-1416376 Share on other sites More sharing options...
ksun Posted March 4, 2013 Author Share Posted March 4, 2013 i did print_r for the $flist(amount of files in the defult diirectory) and it said 5 items, i then did the amount of files in the directory i'm trying to get to(public html) and it ssyas there is no items in the array. ive tried to echo chdir($conn, "public_html"), but it says. Warning: ftp_chdir() [function.ftp-chdir]: Can't change directory to public_html: No such file or directory in /home/a3893538/public_html/test.php on line 25. but when i echo something like chdir($conn, "../"), it works fine. ty Link to comment https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/#findComment-1416377 Share on other sites More sharing options...
teynon Posted March 4, 2013 Share Posted March 4, 2013 I was hoping for the output of the print_r. Why exactly is @ftp_nlist muted? Link to comment https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/#findComment-1416379 Share on other sites More sharing options...
teynon Posted March 4, 2013 Share Posted March 4, 2013 I haven't used PHP FTP, but maybe you should try using the current PWD and the desired directory when you chdir? so echo ftp_chdir($conn, $workingDir . "/" . $newDir); Link to comment https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/#findComment-1416380 Share on other sites More sharing options...
ksun Posted March 4, 2013 Author Share Posted March 4, 2013 thanks it works Link to comment https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/#findComment-1416387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.