Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-06-04
11
Medium Priority
?
446 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:Andy1
  • 5
  • 3
  • 3
11 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 16830533
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

0
 
LVL 1

Author Comment

by:Andy1
ID: 16830573
im using the Microsoft Internet Transfer ActiveX Control
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16830659
Can u make use of OpenURL? although it says url, I dont know if it can be used to open dirs

0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 1

Author Comment

by:Andy1
ID: 16830662
I've been told I need to use the EXECUTE DIR command, but I dont know how to recieve the response from it....
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16830678
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
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16830708
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
0
 
LVL 58

Accepted Solution

by:
harfang earned 2000 total points
ID: 16831479
Hello Andy1

I answered this recently, but using command-line FTP, see {http:/Q_21827960.html}

Using Inet, you would go:

    acxFTP.Object.Execute "DIR"
    acxFTP.Object.Execute "DIR AreYouThere.txt"

But then, you would need to wait for the proper state by creating an event procedure for the object's StateChanged event and then use the GetChunk method to retrieve the directoy. This is explained fairly well here:

Using the Internet Transfer Control (Visual Basic 6)
Using the State Event with the GetChunk Method [towards the end]
http://msdn.microsoft.com/library/en-us/vbcon98/html/vbconusinginternettransfercontrol.asp

However, pay attention to the fact that it was written for VB6, not VBA. If you create the ActiveX control by inserting it on a form, you will have to use acxFTP.Object, not just the control's name!

Cheers!
(°v°)
0
 
LVL 1

Author Comment

by:Andy1
ID: 16832399
Thanks harfang, its that confusing GetChunk thing I've got to use... I've got it working with that.

Cheers.

0
 
LVL 58

Expert Comment

by:harfang
ID: 16832529
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°)
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16832971
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?
0
 
LVL 58

Expert Comment

by:harfang
ID: 16833535
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°)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Implementing simple internal controls in the Microsoft Access application.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

578 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