Scandir() and ftp_nlist or ftp_rawlist | Get specific file names by date

There is a ftp server where files are received everyday but the files are stored on a single folder so I want to get the file listing of today’s files only. is that possible with with ftp_nlist or ftp_rawlist. The only way I know is from ftp_rawlist where we can find the date in the string and compare to get todays files. Is there any other way? I also want scandir() to search for todays files. Thanks

I can’t think of another way you’d do that since neither of the ftp functions you list offer a means to specify any kind of file specification other than the directory. A function should be quite simple to develop, though, just pass in the date and return an array of any files newer than that date.

If you have control of the ftp server and want to implement some kind of retrieval of files that have appeared since the last time you ran the code, renaming or moving the file after you’ve processed it can work.

well the thing is that the files keep increasing on a daily basis and the function will have to search more file names everyday.

That’s another good reason to move them once they’ve been processed. Whatever else is dealing with those files will also have to cope with ever-increasing numbers of files as the days go by. I had a quick look around and the only other thing I found was that you can use ftp_mdtm (if the server supports it) to get the last-modified-date-time for each file rather than trying to decipher raw_list output, but that still relies on you getting each filename and checking them individually.

What kind of number of files per day are we talking about, a number that will cause a significant delay to perform this check presumably once a day?

There are around 110 servers which puts files on the ftp server. Each server may put around 4-10 files on the ftp server. The files received on the ftp server ( received folder ) are temporary and are deleted later however their copies are stored in archives. Since I will be reading files from archives I will be having a lot of files to check. I also checked the mdtm function but will need to check each file.

I think even if you found a more advanced ftp library, it would simply be shielding the selection-by-date process from you. Looking at the RFC FTP commands it doesn’t specifically say that FTP can or cannot support file selection by date, so I would expect it’s down to the FTP server software running as to whether it’s possible. Even if you had an FTP server that supported it, you’d be hard-coding with the assumption that the server would never change to one that didn’t have such support.

Again, if you have any control over it, suggesting that the archived files are archived into folders by date would help you. Of course, that might make it more complex for anyone trying to find a file in the archive.

Only read access on the ftp server.I think I will have to talk to the admin about it. Thanks.

I did experience that ftp_nlist always return FALSE until I used ftp_pasv, it is useful only when your client is behind a firewall otherwise ftp_nlist worked just ok. I am really not aware of all the implications of using ftp_pasv but if you want to experience then ftp_nlist, ftp_get, ftp_nb_get doesn’t work. Try adding the following:

ftp_pasv($conn_id,true);

I do get the file list but I only need the files created today not all of them.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.