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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inet control for FTP retrieval

Status
Not open for further replies.

JackTheC

Programmer
Feb 25, 2002
325
NL
Hi guys,

I try to retrieve the filenames from an FTP site with FTP-commands.
I have the component Microsoft Internet Transfer 6.0 SP6 on my form. (msinet.ocx)

In Visual Basic 6.0 this works:
With Inet1
.URL = "ftp://myftpsite.com"
.UserName = "emailaddress@myprovider.com"
.Password = "mypassword"
.Execute , "DIR"
End with

When I do the same (with Olecontrole1) in VFP 9 SP2 or VFP 6.0 Sp5 it won't work.
When i enter the name and password manually in the properties I see that the url is automatically rewritten in
"ftp://myemailaddress@myprovider.com:mypassword@myftpsite.com"
Then I get the error URL is malformed. That is because of the @-sign in de Username. So double @ in the URL.

This does not happen in VB. in VB the URL is not rewritten.

Question: How to retrieve filenames from FTP server in VFP. Or how to overcome the error message?

 
huh?
it must read

Code:
ftp://myemailaddress@myprovider.com:mypassword@myftpsite.com
 
I don't know why URL behaves this way in VFP only. There are many ways to do FTP in VFP anyway, look at the FAQ section for faq184-3234, use Craig Boyds vfpconnection.fll, use Carlos Alloattis libcurl port for VFP or use the FTP DOS command, to just give a few samples.

An email address as user name is bad, as the general syntax is ftp://username:passwort@servername.tld, so an @ is the seperator for credentials and site name.

Most probably what would work is urlencodeing the @ of the mail address, so set username = "emailaddress%40myprovider.com", haven't tried, thoug.

Bye, Olaf.
 
The forum seems to mangle ftp urls a bit, I got the same half html anchor tag as yoo.

Nevertheless the @ is a seperator you can only use once in a ftp URI, so you have to encode it for being part of an FTP username, as always in URLEncding this should be %hex, in case of @ that is %40. VB may do that behind the scenes, too, just not show it. The full program logic of the inet control is inside it, including how it reacts to setting it's properties, so I can't follow, how this would differ. Ar you saying you compared to VB with that same user/pass, or do you just compare your new case in VFP with your VB experience? In general you can also have user names not being a mail adress or anonymous FTP.

Bye, Olaf.
 
Thank you Olaf,

My email-provider also gives us webspace and the username for that webspace is the email address. So the @ is mandatory.

I first wrote a program in VB6 because i found an article on the internet about how to retreive directory content from FTP-server.
That worked.

Than i took the same commands and adapted them to VFP, but it does not work because of the automatic rewrite with double @ and when i do the porperty settings in code it won't connect to the ftp server with an OLE dispatch error. Unable to connect to server.

BTW: %40 does not give en error when i type it in the Olecontrol1 property, but the same OLE dispatch error is produced when tried to run it.

And yes i'am aware of the FTPGET, FTPPUT and FTPDELETE commands. I was going to use them. But before I can use them i need to know the names of the files i can retrieve or delete. They are different every time (camera uploads with timestamps)

So the right order of my program will be:
A.Get all the filenames (now in VB not VFP) alas.
B.Download them one by one (FTPGET)
C.Delete the one by one (FTPDELETE)
D.Show them in a VFP DBF Table with dates and pictures read from the copy on the harddisk etc.


 
I don't know if you talk about API, but take a look at this recent thread: thread184-1718704

Exactly your problem about getting dir. FtpFindFirstFile and InternetFindNextFile are the API functions to get a directory and used in Dave Summers FTP form.

Bye, Olaf.
 
No API, plain simple code in VB

Code:
Private Sub Form_Load()
    bst = "ftpfiles.txt"
    If Len(Dir(bst)) > 0 Then Kill bst
    
    pams = Split(Command, "|")
    Dim BUFFER() As String
    
    With Inet1
        .URL = pams(0)
        .UserName = pams(1)
        .Password = pams(2)
        .Execute , "DIR " & pams(3) & "/"
        While .StillExecuting: DoEvents: Wend
        
        BUFFER = Split(.GetChunk(1024, icString), vbCrLf)
        Open bst For Output As #1
        For Each Item In BUFFER
            Print #1, Item
        Next
        Close #1
    End With
    End
End Sub

In the parameters for starting the exe I give: ftpserver|username|password|directoryname
This code produces a TXT file that i can use to fill a DBF in VFP with Append from type sdf
I would like to write the entire program in VFP without the need of calling a VB-made.exe

Maybe it works in VFP with other ftp servers but not with a ftp server that needs a @ in the username (in VFP).
 
You've already given that code, my last answer wasn't referencing that, but your answer about FTPGET and FTPDELETE, there are more ftp commands in the Windows API you can use instead of the Inet control.

Have you tried encoding @ with %40? It's a simple URL encoding any web or ftp server should understand and decode to @.

Bye, Olaf.
 
Alas, even at ftp servers with a username without @ i get the same error. Cannot connect to server with inet control in VFP. Don't know why.
 
Also see Firewall. Using vfp9.exe you could allow vfp9.exe through your firewall at Port 21. Using Internetexplorer or other Browsers you use software allowed for internet services like FTP, VFP9.exe is no such application by default, unless you have allowed any software to communicate through these kind of Ports.

Bye, Olaf.
 
For the moment I use the VB6 program for retrieving a file list from the FTP server and then use the FTPGET procedure for each file in the filelist. That works great.

The FTPGET procedure consists of 3 parts:
1. Open the handles
2. Get the file (download the file)
3. Close the handles.

When retrieving 100 files the handles are 100 times opened and 100 times closed. So I thought I be smart:
1. Open the handles
2. Get the 100 files
3. Close the handles.

But it seems that my program is to fast for the FTP server. 2 out of every 3 files are not fetched. When i insert an inkey(0.5) between every "get" it works just fine. So I returned to the original setting of opening and closing 100 times......

Thanks for all the advice. I will look at Dave's FTPClient if I have more time to analyse and adapt that, but for the moment my solution works.




 
hi JacktheC:

i do lots of ftp everyday using vfp 9.xx
search the google for iFox.FTP by coliseo software.

basic syntax to connect:
t_ErrorFound = .f.
t_ftp = createobject("iFox.FTP")
t_ftp.SetLicenseCode("SOMEHEXADECOMALS") & You need to receive it from the author, it is free.
t_ftp.connect(p_HostName,p_UserName,p_Password)
inkey(.5)

i did try to use the inet version in vfp. it did work but had problems all the time. needs many settings.

i hope it helps


nasib
 
I have the component Microsoft Internet Transfer 6.0 SP6 on my form. (msinet.ocx)

I have never needed to use that to do FTP file transfers for my clients.

I have always used routine(s) based on the following:
How do I transfer files using FTP? faq184-3234

Obviously those routines need to be modified to meet the specific needs of the 'remote' ftp site, but they have always worked well for me.

Good Luck,
JRB-Bldr

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top