Check if a file exists on FTP, answer with yes or no

Posted on 2006-04-26
Last Modified: 2012-06-27
We have a system who storing files on a local server, where a part of the filenames contains an unique 8 char code.
This unique 8 char code is also stored in an access database.

Now I search for a function who:
1. On a click, makes this Access database connect to this local server through FTP (yes, ftp is a must).
2. Check if there is a filename having this unique 8 char code.
3. Tell Yes if the file exists, No if it doesn't exist.

And an overkill, but very useful if above is very easy:
4. If yes, click again and the file are transferred and runs with the computers associated software.

Is this possible? How do I do :)
Question by:dingir
    LVL 38

    Expert Comment

    by:Jim P.
    I've only have ever been able to shell FTP commands.  Someone pointed out this site to me to do FTP with api calls.

    I have never used any of it, so I am not the expert to ask on this.
    LVL 58

    Expert Comment


    I'm sure there is a better way, but you can always do this, from a batch file or a Shell command:

        ftp -v -s:test.ftp | find "filetocheck.txt" | find /v "ftp> " > test.out

    test.ftp contains this (which can be written from VB, naturally)
    ls filetocheck.txt

    After running the command, the file test.out will contain the name of the matching file, or nothing. It's easy to read that back into VB to proceed

    A similar technique can be used to retrieve the file.

    Hopw this helps
    LVL 1

    Author Comment

    Hi Jimpen! I'm about to trying this now.. I'm not sure how I get it into vbscript. I try to use Call Shell(..) as I use in some other similiar cases (just simple upload/download actions). You have any working vbscript-examples?
    LVL 1

    Author Comment

    Hi harfang! Thank's something like that - putted in a Shell, but I can't get that find-command works.. :/
    LVL 58

    Accepted Solution

    Ah, I knew it. Couldn't figure it out? There must be 1000 ways of doing this, but here is one:

    Try ? CheckFTP("*.txt")
    Option Explicit

    Const FTP_SITE = ""
    Const FTP_LOGIN = "anonymous" & vbCrLf & ""
    Const FTP_PATH = "deskapps/ACCESS/KB"

    Function CheckFTP(pstrFile As String)

        Dim strLine As String
        ChDir Environ("TEMP")
        ' ftp script:
        Open "~~check.ftp" For Output As #1
        Print #1, FTP_LOGIN
        Print #1, "cd " & FTP_PATH
        Print #1, "ls", pstrFile
        Print #1, "quit"
        Close #1
        ' batch file:
        Open "~~check.bat" For Output As #1
        Print #1, "ftp -v -s:~~check.ftp " & FTP_SITE _
            & "|find/v""ftp>"">~~check.out"
        Print #1, "del ~~check.ftp"
        Print #1, "del ~~check.bat"
        Close #1
        ' run batch
        CheckFTP = Null
        If Shell("~~check.bat") = 0 Then Exit Function
        Do While Dir("~~check.ftp") <> ""
            ' should add a timer here...
        ' read results...
        Open "~~check.out" For Input As #1
        Do Until EOF(1)
            Line Input #1, strLine
            strLine = Trim(strLine)
            If strLine <> "quit" And strLine <> "" Then _
                CheckFTP = CheckFTP + ";" & strLine
        Close #1
        Kill "~~check.out"
    End Function

    More about FTP scripting at

    LVL 1

    Author Comment

    PERFECT! What a nice solution. Thank's a lot :)
    LVL 58

    Expert Comment

    Glad you like it. It's low-tech (and shows my age) but it does seem to work...
    Good luck!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now