Check if ftp file exists

Giordano Bruno

Well-known Member
Joined
Jan 7, 2007
Messages
1,341
I have this code from MrExcel which used to work well until the http site closed.

<font face=Courier New><SPAN style="color:#00007F">Function</SPAN> FileExistsURL(<SPAN style="color:#00007F">ByVal</SPAN> URL <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN><br><SPAN style="color:#007F00">'> Supplied by Juan Pablo Gonzalez</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> objXmlftp <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br><br><SPAN style="color:#00007F">Set</SPAN> objXmlftp = CreateObject("MSXML2.XMLftp")<br><br>objXmlftp.Open "HEAD", URL, <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> ErrChk:<br>objXmlftp.send ""<br>FileExistsURL = objXmlftp.Status = 200<br><br><SPAN style="color:#00007F">Set</SPAN> objXmlftp = <SPAN style="color:#00007F">Nothing</SPAN><br><SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Function</SPAN><br>ErrChk:<br>FileExistsURL = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">Set</SPAN> objXmlftp = <SPAN style="color:#00007F">Nothing</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN></FONT>

I'm trying to make it work with files kept in an ftp environment. The address is something like "ftp://ftp.acme.com/XYZ/acme.xls"

I would be grateful if someone could point me in the right direction.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Set objXmlftp = CreateObject("MSXML2.XMLftp")

So, is the MSXML2.XMLftp object a real object or did you make that up yourself ... ? Is your intention to find out if the file exists or to actually get it?
 
Upvote 0
Thanks zenou,

Ultimately I want to open the file, but first I want to check if it exists.

I'm not sure what the MSXML stuff does, I was just trying to adapt it from the previous code.
 
Upvote 0
Just try to get it. Failure will mean it doesn't exist or that it does but you can't get it. Either way, you don't have the file.

Here's a recent thread on FTP. My advice is to always do your transfer first "live" from the command line to be sure that you have the right commands, then to script it. Actually, my advice is to use a secure protocol (FTP is not secure and your password is sent plain text for all to see). But that's up to you.

ξ

Edit: Oops. Forget "MSXML2ftp". It doesn't exist, as far as I know. You can't access the services of a non-existent class. Nice try, though. ;)
 
Last edited:
Upvote 0
Hi Xenou,

I can get it manually, it requires a user name and a password. Dont know how to go about this via VBA though.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top