Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP upload and download using WebBrowser1 1

Status
Not open for further replies.

MrMajik

IS-IT--Management
Apr 2, 2002
267
I found the code at the bottom of this message here in a thread and for some reason I can't get it to work. I have it pulling in a webpage to the Internet window in my form using this:

WebBrowser1.Navigate2 "ftp://user:password@ftp.site.com"
Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop

but when the code moves to the next line (exactly as typed)
Set ftpFolder = WebBrowser1.Document.Folder
I get the following error:

Run-time error 438:
Object does not support this object or method.

I have referenced
Microsoft Shell Controls and Automation
Microsoft Internet Controls
and have the Microsoft Internet Control component added.

Do you know what I am missing to get this to work?

Thank you.
========================================================

Option Explicit
' Webbrowser variant

Private Sub Command1_Click()
Dim ftpFolder As Folder

WebBrowser1.Navigate2 "ftp://user:password@ftp.site.com"
Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop

Set ftpFolder = WebBrowser1.Document.Folder
ftpFolder.CopyHere "c:\test.txt"
End Sub


Thank you,

MrMajik

There are 10 types of people in the world:
Those that understand binary and those that don't.
 
That looks like an incorrect version of my first example in thread222-1337638

Let's try and sort it out.

Firstly:
MrMajik said:
I have it pulling in a webpage to the Internet window
Well, no. The code was designed to use the FTP functionality in Internet Explorer. FTP is used to upload and download files to and from an FTP server. It isn't used to load a webpage into a browser. That's what we have HTTP for (unless, of course, you have a file on a server that is not a web server but is an FTP server, and that file is displayable in a webbrowser)

Secondly, even assuming that the 'unless' above is the case
MrMajik said:
WebBrowser1.Navigate2 "password@ftp.site.com" target="_blank">ftp://user:password@ftp.site.com"
You should be getting more than one error on this line. The first should be a design-time error, since the quotes are all wrong. And even if you correct that (by deleting from >ftp: onwards, I'd then expect a runtime error, since a) the named parameter of target is wrong for the Navgate2 method. It should be TargetFrameName. And then you are getting the named parameter sysntax wrong. = should be :=

So a corrected version of this line would be
Code:
ebBrowser1.Navigate2 "password@ftp.site.com", TargetFrameName:="_blank"

But this still won't work because of the URL you have tried to use; by default the Webbrowser works with HTTP (and you haven't told it any different), so what you are actually trying do is browse to a website called password@ftp.site.com. This should fail - so again the error should occur on the WebBrowser1.Navigate2 line.

Right now I don't actually understand how you are even getting to the following line ...

Set ftpFolder = WebBrowser1.Document.Folder


 
strongm,

Thank you for your reply.

I did not post the string that I use to gain access to my website as I do not want to tell the world the username and password for the site. What I posted is sudo-code replaced for the working code.

It is line that generates the error:

Set ftpFolder = WebBrowser1.Document.Folder



 
Sure, I assumed that you hadn't posted your actual username and password. However, I also assumed that you'd sent a reasonable variant of the real thing, simply repalcing your real password with the word 'password', real username with 'username', and real site with 'ftp.site.com'.

But if half of the code you have presented with is simply made up junk it makes it difficult to help you as we don't have a truie representation of the problem.

Let us play "Let's pretend".

Let us pretend that your user name is "MrMajik"
Let us pretend that your password is "password"
Let us pretend that your FTP site is "ftp.site.com"

Now, can you post the Navigate2 line you would use if all the above were true.
 
(I'm reasonably certain I know why you are getting the problem, and I think it is to do with the way you are trying to use Navigate2, but until I see what you are actually doing I don't want to speculate)
 
This is something of what the real line looks like:

WebBrowser1.Navigate2 "ftp://mrmajik:password@12.123.210.21//public_html/fpp/menus/picks.html"
Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop

Set ftpFolder = WebBrowser1.Document.Folder
ftpFolder.CopyHere "C:\picks.html"
 
Bingo!

A file Document doesn't have a Folder property - and in your Navigate2 your are FTP to a file, not a folder, hence the error message. You need to navigate to the folder the file is in.

WebBrowser1.Navigate2 "ftp://mrmajik:password@12.123.210.21//public_html/fpp/menus"

 
strongm,

THANK YOU! [2thumbsup]

I was searching for a more difficult solution to this and it blinded me to the answer. Sometimes a solution is so simple you don't see it looking right at you!

Your valuable time spent helping with this has saved me a lot of time and frustration.

May God bless you [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top