03-17-2010 08:05 AM
Hi all,
I am creating an application where I need to copy the latest file created only from a remote FTP location. So for example, if my remote/ftp location contain some folders and some files, it would list only the file which was modified recently.
Right now, both NLST and LIST commands are giving me full list of folder and files directly, but I need only the file which was recently modified.
Can anyone help me out?
Solved! Go to Solution.
03-17-2010 08:57 AM - edited 03-17-2010 08:59 AM
Hi
Unfortunately the LIST command(s) don't return proper usable modification dates/times.
But there's a special FTP command 'MDTM' to get the modification date of a specified file.
You'll have to execute this command for each file individually.
Are you using the FTP functions from the Internet toolkit? Then you can do it like this:
In the reply string you'll get the reply code (250 for successful operation) and the modification date.
I think you'll have to find the latest file with some code on the host system based on these modification dates.
Hope this helps
03-17-2010 09:43 AM
Thanks, this works.
Is there any other command which would let me copy only the latest modified file?
03-17-2010 09:54 AM
I don't believe so.
Look in vi.lib\addons\internet\ftp\ftp1.llb for the tested and supported LabVIEW FTP raw client functions.
For a list of the defined FTP commands, see this document. Note that the server you are talking to may or may not support the full list.
03-17-2010 10:04 AM
Ok,
I believe creating a VI for parsing the reply string and comparing files on Time stamp returned by above function is too tedious task
03-17-2010 10:10 AM - edited 03-17-2010 10:12 AM
What about the file names, do you have access to the code that creates the files? If the file names would start with something like YYYYMMDD-hhmmss (wouldn't that be nice?) you can just retrieve the file list and sort it, then get the latest file.
I don't think an FTP server supports anything that helps you with that, I think you have to get the file list and work with it on the host.