Skip to main content
Inspiring
June 9, 2006
Answered

cfftp and file's lastModifed question

  • June 9, 2006
  • 7 replies
  • 1413 views
Using cfftp, is there another way to get a file's LastModified DT stamp other that using action="listDir"?

I have a scheduled job that hits an ftp server every minute. The file I'm trying to check is in a folder with a handful of files that are all constantly updating, and my code intermittently bails on the "listDIr". My guess is one of the files are being updated at the moment I'm doing a "listDir", and ColdFusion can't read the directory and bails.

Thanks for reading,
JB
    This topic has been closed for replies.
    Correct answer juliebread
    BKBK, first off, thank you so much for all the time you've spent with me on this issue. Where can I send you your beverage of choice? (I'm not kidding)

    The system I inherited is quite 'mature', and was set up by the elders to not take advantage of CF's session management nor application.cfm file, so the cflock w/session tip probably won't work.

    Thanks for the 2 code bits for getting the modified DT stamp. However, the reason I need to check the modified DT stamp was to save bandwidth before grabbing the file in the first place (since I hit their ftp server every minute - maybe I didn't explain that bit).

    Anyway, I tried implementing jdeline's idea (to put a try/catch around the 'listdir' part and keep trying). I essentially set it up in testing to keep trying until it got a successful 'listdir' return. I noticed that if it did fail, it would always get it by the second try (to my surprise and relief). So that's the method I'm going with. So a big thank you to both of you!

    I'm calling this good so I can finally get on with some other work! Truly, thanks again for your time and patience and ideas!

    JB

    7 replies

    BKBK
    Community Expert
    Community Expert
    June 22, 2006
    !
    BKBK
    Community Expert
    Community Expert
    June 17, 2006
    Using cfftp, is there another way to get a file's LastModified DT stamp other that using action="listDir"?...The problem is listDir does more than I need (i.e., gets meta data for everything in the ftp directory). I just need the modifed DT stamp for one file. But I can't figure out any other way to get it than to list the whole directory and parse through that.

    I, too, might need such a functionality. Here is something I found. Download the free version of edtFTPj. It is a ZIP file. Extract it. Copy the JAR file, edtftpj-1.5.2.JAR, to Coldfusion's lib directory (e.g. c:\cfusionmx7\lib on my machine). Restart Coldfusion, to update it with the new JAR file.

    The code below assumes the following:

    FTP server: ftp.juliebread.com
    username: BKBK
    password: kbkb072
    File whose 'last modified date' you need: ftp://ftp.juliebread.com/testdir1/testdir2/report.xml

    For more information, go to the edtFTPj website. There you will find information about the edtftpj API and, in particular, about the FTPClient class.




    Inspiring
    June 22, 2006
    Thanks, BKBK!
    BKBK
    Community Expert
    Community Expert
    June 16, 2006
    Where can I send you your beverage of choice?
    It is as good as consumed...hic. Cheers.

    BKBK
    Community Expert
    Community Expert
    June 14, 2006
    is there another way to get a file's LastModified DT stamp
    Yes, if you don't insist on cfftp, then just use cfdirectory or the java.io.File package. But then, you must first find a way to get the files to your server.



    juliebreadAuthorCorrect answer
    Inspiring
    June 16, 2006
    BKBK, first off, thank you so much for all the time you've spent with me on this issue. Where can I send you your beverage of choice? (I'm not kidding)

    The system I inherited is quite 'mature', and was set up by the elders to not take advantage of CF's session management nor application.cfm file, so the cflock w/session tip probably won't work.

    Thanks for the 2 code bits for getting the modified DT stamp. However, the reason I need to check the modified DT stamp was to save bandwidth before grabbing the file in the first place (since I hit their ftp server every minute - maybe I didn't explain that bit).

    Anyway, I tried implementing jdeline's idea (to put a try/catch around the 'listdir' part and keep trying). I essentially set it up in testing to keep trying until it got a successful 'listdir' return. I noticed that if it did fail, it would always get it by the second try (to my surprise and relief). So that's the method I'm going with. So a big thank you to both of you!

    I'm calling this good so I can finally get on with some other work! Truly, thanks again for your time and patience and ideas!

    JB
    BKBK
    Community Expert
    Community Expert
    June 14, 2006
    Did you implement both locks earlier? Though the files are not modified there could be other concurrency issues. But then, you must enable session variables in the Coldfusion Administrator.

    Store the connection in session scope, i.e. by setting connection="session.Online" when the action is "open".

    <cflock name="lastMod" timeout="60" type="exclusive">
    scheduled ftp task
    </cflock>

    <cflock name="lastMod" timeout="10" type="readonly">
    listDir and find LastModified date stamp
    </cflock>


    BKBK
    Community Expert
    Community Expert
    June 13, 2006
    I think my initial diagnosis was wrong (i.e., problems getting a hook on the directory because the files are constantly being updated on their ftp server), because their files haven't updated for 2 days, and my script is still throwing intermittent exceptions trying to do the 'listdir'.
    Then named locks might not solve it.

    I have totally rewritten this section. I realized you use the connection attribute together with the listDir action. Experiment by dropping the connection attribute and adding the server attribute, thus
    <cfftp action="listdir" server="ftp.myDomain.com" directory="#remoteDir#" name="dirListing" stoponerror="yes">



    Inspiring
    June 13, 2006
    Do we need session management turned on for that?

    We don't. For better or worse, we have our own home grown session management.

    JB
    BKBK
    Community Expert
    Community Expert
    June 13, 2006
    Do we need session management turned on for that?
    I dropped the idea of sessions when I realized you had used the connection attribute with listDir action. I don't think you need the connection attribute.


    June 9, 2006
    Try <CFDIRECTORY FILTER="yourFileNameGoesHere" ... >. This should take the other files out of play.
    Inspiring
    June 9, 2006
    How would you use cfdirectory to check a file's LastModified when it's sitting on an ftp server? cfdirectory is just used local filesystems as far as I am aware.

    JB
    June 9, 2006
    Sorry, didn't read your posting close enough. Is ColdFusion running on the target server? If so, there may be other options for you.