Check if a file exists to ftp directory

dmarop

Registered User.
Local time
Today, 07:11
Joined
May 17, 2013
Messages
41
Hello,

I will need your help.

I am using the following code to check if a file exists in an ftp directory.

If i make the check in a local directory the code is working.

Code:
Sub DirFile()
    Dim fso As New Scripting.FileSystemObject
    Dim sFile As String

    ConnectionFtp 'make login in an ActiveX Microsoft Web Browser to the ftp directory
    
    sFile = ftpWB.LocationURL & "img171615386.jpg"

    If fso.FileExists(sFile) Then
    'If Dir(sFile) Then also it's not working and with the method dir
        MsgBox "the file exists"
    End If
End Sub

Can you help me please?

Thank you in advance.

Dimitris
 
This site suggests

Code:
If Len(Dir("c:\example.mdb")) = 0 Then
   Msgbox "This file does NOT exist."
Else
   Msgbox "This file does exist."
End If

sort of code so in your case try
Code:
If Len(Dir(sFile)) = 0 Then
 
Last edited:
Thank you for your answer.

I want to check a directory that it is in a web server, if the file exists and not in the local directory of the pc.
 
Sorry about my previous post. I didn't read your post carefully enough.

I don't know what you mean by
Code:
 ConnectionFtp 'make login in an ActiveX Microsoft Web Browser to the ftp directory

in your code. From my googling FTP and Access it appears that FTP in Access isn't that simple. I came across some code at this site which I upgrading to a .accdb format and have uploaded. This appears to be a full blown FTP upload application but maybe you can use some of the code for your needs. I found a function in the FTP_Functions module named FTPList. I tested this with the following code which you can find in the Test Module module of the attached database.

Code:
Sub t()

Dim str As Variant
For Each str In FTPList("gatekeeper.dec.com", "anonymous", "wsftp605@", "pub")
    Debug.Print str
Next str

End Sub

This worked. In the Immediate Window I got a list of folders in the "pub" folder on that site. So maybe you could do this something like:
Code:
Function FTPFileExists(FileName As String, Path As String, URL As String, UserName As String, Password As String) As Boolean

Dim varFile As Variant
FTPFileExists = False
For Each varFile In FTPList(URL, UserName, Password, Path)
    If varFile = FileName Then
        FTPFileExists = True
    End If
Next varFile

End Function

You would need to add error check code but this might get you started.
 

Attachments

Last edited:
I forgot to mention that the database I attached in my previous post has a lot of Declare statements in this code. So this code won't work if you are using the Office 64 addition without a lot of work upgrading these statements with the ptrSafe stuff.
 

Users who are viewing this thread

Back
Top Bottom