Link to home
Start Free TrialLog in
Avatar of Andy1
Andy1

asked on

EXECUTE DIR to check if file exists using Internet Transfer ActiveX Control

I've got the code and the connection all setup to connect to my ftp site, I want to see if a file exists on the site, to do this I assume that I use the EXECUTE DIR command to find if the file name exists...

So far I have only dealt with using the PUT and GET commands I dont know how to run the DIR command or find out where/how the data is returned..

Help greatly appreciated!

Cheers,

`Andy
Avatar of rockiroads
rockiroads
Flag of United States of America image

Well the command to change to a directory is

CD

to list directory contents its

LS


How are u doing this ftp, is it raw ftp or u using something like WinInet

Avatar of Andy1
Andy1

ASKER

im using the Microsoft Internet Transfer ActiveX Control
Can u make use of OpenURL? although it says url, I dont know if it can be used to open dirs

Avatar of Andy1

ASKER

I've been told I need to use the EXECUTE DIR command, but I dont know how to recieve the response from it....
scrub that, its the URL u need to set I think
eg

typically u would have (I think, I dont have the control so cannot verify)

 myftpObjext..URL = "mydir"
 myftpObject.Execute "mydir", "Get " & strFile & " C:\" & strFile

I guess if u had an error handler, which displayed the error number and description
u can then check for that error number and handle the situation as u want
I dont have the design time license so I cant install it on mine :(

That control may have its own error handler as well so it might be worth puting a msgbox in there as well


In the vBA window, if u hit F2, it will bring up the object browser, find your control there and see what methods there are, u may find something to help you along the way
ASKER CERTIFIED SOLUTION
Avatar of Markus Fischer
Markus Fischer
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andy1

ASKER

Thanks harfang, its that confusing GetChunk thing I've got to use... I've got it working with that.

Cheers.

It's tricky. And again, do not use the activex control name, even if the  compiler accepts it. You will end up with a frozen application, hidden dead processes, etc. Instead, use:

Dim WithEvents objFTP As Inet

Private Sub Form_Load()
    Set objFTP = Me.acxFTP.Object
End Sub

Private Sub objFTP_StateChanged(ByVal State As Integer)
    ' as in MS's sample
End Sub

I tried a little more after posting and only got something stable once I did it like that. Then again, it's A2K, later versions might not be as touchy. I guess it's also possible to create the ActiveX entirely through code, but I didn't check that.

Cheers
(°v°)
Andy1, just a question then. Just so I would like to know
does using GetChunk help you determine whether a file exists or not then?
Do u just check for zero bytes received? What if the file was there but empty?
rockiroads,

If you ask for "dir readme*", the control would return all matching files, on separate lines. If no file is found, an empty string is returned. So if you ask for "dir readme.txt", you either get the same name back or an empty string. However, you have to wait for the .State=12 before you can use GetChunk, this is why the event is useful.

I don't know of a way to return the file size or file date, but folders are identified by a trailing slash.

Cheers!
(°v°)