jjfletch Posted October 24, 2009 Share Posted October 24, 2009 The code below works insomuch that I can successfully download the directory recursively. But, I want to download the directories within this directory. So, when it connects it's in . Within the . directory is a subdirectory "IN". I want to recursively retrieve the contents within the "IN" directory. The directory names themselves will change, so I can't specify what that's going to be in the script itself... Anyone know how to do this? ftp_sync ("./In/"); ftp_close($conn_id); function ftp_sync ($dir) { global $conn_id; if ($dir != ".") { if (ftp_chdir($conn_id, $dir) == false) { echo ("Change Dir Failed: $dir<BR>\r\n"); return; } if (!(is_dir($dir))) mkdir($dir); chdir ($dir); } $contents = ftp_nlist($conn_id, "./In/"); foreach ($contents as $file) { if ($file == '.' || $file == '..') continue; if (@ftp_chdir($conn_id, $file)) { ftp_chdir ($conn_id, ".."); ftp_sync ($file); } else ftp_get($conn_id, $file, $file, FTP_BINARY); } ftp_chdir ($conn_id, ".."); chdir (".."); } Link to comment https://forums.phpfreaks.com/topic/178851-ftp-subdirectory-recursively/ Share on other sites More sharing options...
DavidAM Posted October 24, 2009 Share Posted October 24, 2009 I have never tried this before, so I can't speak about whether it will work or not. But I did notice, that in the middle of your function you have the directory "./In/" hard-coded in the ftp_nlist function call. Shouldn't that be $dir? Link to comment https://forums.phpfreaks.com/topic/178851-ftp-subdirectory-recursively/#findComment-943536 Share on other sites More sharing options...
jjfletch Posted October 24, 2009 Author Share Posted October 24, 2009 I have never tried this before, so I can't speak about whether it will work or not. But I did notice, that in the middle of your function you have the directory "./In/" hard-coded in the ftp_nlist function call. Shouldn't that be $dir? Yes, it actually is... That was just me trying to see if that would work... But, it didn't... Link to comment https://forums.phpfreaks.com/topic/178851-ftp-subdirectory-recursively/#findComment-943555 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.