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

FTP with FoxPro (6 or 9) 2

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
Does anybody have any suggestions for Using FTP within FoxPro. My needs are modest at this time. Just send and get a few files. I have seen a few sample classes on line, but not sure how to evaluate them. Any suggestions, links or sample code would be appreciated.

Auguy
 
This isn't fancy, but it works great. Put, get, whatever you want. Launch a dos window, type 'ftp' and then a '?' at the prompt to see available commands.

There are lot's of FAQs and posts, probably mostly in the general forum if this solution doesn't suit you.

Brian

Code:
    lcScript =  "open ftp.yoursite.com" + CHR(10) +;
    "username" + CHR(10) + ;
    "password" + CHR(10)+ ;
    "binary" + CHR(10) + ;                 
    "cd ./TargetDir" + CHR(10) + ;
    "lcd " + lcDataFolder + CHR(10) + ;
    "put " + [file1_]+ DTOS(ldDate)+[.csv]+ CHR(10) + ;
    "put " + [file2_]+ DTOS(ldDate)+[.csv]+ CHR(10) + ;
    "bye"

    STRTOFILE(lcScript,"ftpscript.txt")
    RUN ftp -i -s:ftpscript.txt
 

Auguy,

Take a look at the Internet Transfer Control, which is one of the ActiveX controls that comes with VFP (6.0 and above).

You can drop it on a form, then call its Execute method. You pass the URL of the FTP site, and the complete FTP command that you want to send. For example, you can pass (as the second parameter): "GET anyfile.txt c:\downloads\anyfile.txt". That will copy a file from the server to your local hard drive.

There's more information about the control on MSDN.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks to both of you.

Auguy
 
Thanks Dave, that was already on my review list.

Auguy
 
I do something currently almost exactly like Baltman suggested. Every so often, the ftp doesn't execute properly. I'm not 100% sure why, probably an issue with connectivity. It's an automated process so I'm not there to observe or try to trap it. Is there a way to verify that the OS successfully completed the ftp command such as [RUN ftp -i -s:ftpscript.txt] ?
 
I guess you could pipe a DIR command to a text file (before and after?) and look to see if the new file is transfered...

Code:
 dir > c:\test.txt [\code]

Brian
 
I do something along that line in my current application. I capture the ftp dialog in a log file and then read that log file into a memo field and look for the text "TRANSFER COMPLETE" in the memo field. If this text is not present, then the file did not transfer properly. You may have to use other text to search for and possibly do more than one search if you are sending multiple files.

Something like RUN ftp -i -s:ftpscript.txt > Ftpxxx.Log

I change xxx to a sequential number each time the ftp procedure is run so I can review these files at a later time. You could also save the memo field that contains the log file. Hope this helps.

Auguy
 
I have used the routines on faq184-3234 by Dave Summers to build my FTP routines and it was worked well for me.

Good Luck,
JRB-Bldr
 
USMA99,
Your best bet would be to use something where you could retain the value returned on an error. Maybe the class Borislav mentioned does that. The routines I used in the FAQ I wrote does return values which you could later check to see why it failed.
If you use the ftp.exe you will have a harder time seeing what error occured if you're able to at all.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
I fully agree with all of the previous posts that suggest the use of code or classes to control the FTP process from within VFP. My suggestion to use the "Run FTP..." script was intended only to solve the trapping of the FTP command. I had to use this option on a FoxPro (2.6) Unix system where the other options are not available.

Auguy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top