Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy a file from data on my website
Message
From
29/01/2011 04:55:41
 
 
To
28/01/2011 19:06:17
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Environment versions
Visual FoxPro:
VFP 7
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01497730
Message ID:
01497738
Views:
66
Here's one function to use
Function GetFileFromURL
LPARAMETERS lcRemoteFile,lcLocalFile
DECLARE INTEGER URLDownloadToFile IN urlmon.dll; 
    INTEGER pCaller, STRING szURL, STRING szFileName,; 
    INTEGER dwReserved, INTEGER lpfnCB 

*LOCAL lcRemoteFile, lcLocalFile 
*lcRemoteFile = "http://www.news2news.com/vfp/downloads/w32data.zip" 
*lcLocalFile  = "c:\temp\w32data.zip" 

= URLDownloadToFile (0, lcRemoteFile, lcLocalFile, 0, 0)
Personally I mostly use this function
Function GetDataFromURL
LPARAMETERS pcUrlName
DECLARE INTEGER InternetOpen IN wininet.DLL STRING sAgent, ;
      INTEGER lAccessType, STRING sProxyName, ;
      STRING sProxyBypass, INTEGER lFlags

DECLARE INTEGER InternetOpenUrl IN wininet.DLL ;
   INTEGER hInternetSession, STRING sUrl, STRING sHeaders,;
   INTEGER lHeadersLength, INTEGER lFlags, INTEGER lContext

DECLARE INTEGER InternetReadFile IN wininet.DLL INTEGER hfile, ;
      STRING @sBuffer, INTEGER lNumberofBytesToRead, INTEGER @lBytesRead

DECLARE short InternetCloseHandle IN wininet.DLL INTEGER hInst

#DEFINE INTERNET_OPEN_TYPE_PRECONFIG 0
#DEFINE INTERNET_OPEN_TYPE_DIRECT 1
#DEFINE INTERNET_OPEN_TYPE_PROXY 3
#DEFINE SYNCHRONOUS 0
#DEFINE INTERNET_FLAG_RELOAD 2147483648
#DEFINE CR CHR(13)

local lsAgent, lhInternetSession, lhUrlFile, llOk, lnOk, lcRetVal, lcReadBuffer, lnBytesRead

* what application is using Internet services?
lsAgent = "VPF 5.0"

lhInternetSession = InternetOpen( lsAgent, INTERNET_OPEN_TYPE_PRECONFIG, ;
      '', '', SYNCHRONOUS)

* debugging line - uncomment to see session handle
* WAIT WINDOW "Internet session handle: " + LTRIM(STR(hInternetSession))

IF lhInternetSession = 0
   WAIT WINDOW "Internet session cannot be established" TIME 2
   RETURN .null.
ENDIF

lhUrlFile = InternetOpenUrl( lhInternetSession, pcUrlName, '', 0, ;
                             INTERNET_FLAG_RELOAD, 0)

* debugging line - uncomment to see URL handle
* WAIT WINDOW "URL Handle: " + LTRIM(STR(hUrlFile))

IF lhUrlFile = 0
   WAIT WINDOW "URL cannot be opened" Timeout 5
   RETURN .null.
ENDIF

lcRetVal = ""
llOk = .t.

DO WHILE llOK
   * set aside a big buffer
   lsReadBuffer = SPACE(32767)
   lnBytesRead = 0
   lnOK = InternetReadFile( lhUrlFile, @lsReadBuffer, LEN(lsReadBuffer), @lnBytesRead)

   if ( lnBytesRead > 0 )
      lcRetVal = lcRetVal + left( lsReadBuffer, lnBytesRead )
   endif

   * error trap - either a read failure or read past eof()
   llOk = ( lnOK = 1 ) and ( lnBytesRead > 0 )
ENDDO

* close all the handles we opened
InternetCloseHandle( lhUrlFile )
InternetCloseHandle( lhInternetSession )

* return the URL contents
RETURN lcRetVal
>Hello,
>
>I need to pull information from a website into FoxPro. The information is within a .txt file (comma delimited) on the website server.
>
>Ideally, I'd just like to copy the .txt files on to my hard drive and manipulate them further in FoxPro. When I try to:
>
>copy file "http://www.MYWEBSITE.com/_private/form_results10.txt" to c:\hold\form_results10.txt
>
>I get the error "Invalid path or filename". I tried something else earlier (don't recall what it was) that led me to believe FoxPro was "stuck" within the C:\ drive (something like it couldn't find c:\http://...).
>
>I also tried writing a macro in Excel to open the .txt file there and manipulate it. I'm not sure how to tweak that code to actually work.
>
>If there is a way to just copy the files, that's perfect. If not, help converting the following macro to "FoxSpeak" would be greatly appreciated.
>
>Thanks,
>Martha Kroll
>
>
>Sub Macro1()
>'
>' Macro1 Macro
>' Macro recorded 1/28/2011 by Martha Kroll
>'
>
>'
> ChDir "http://www.rivercitymotorsusedcars.com/_private"
> Workbooks.OpenText Filename:= _
> "http://www.MYWEBSITE.com/_private/form_results10.txt", Origin _
> :=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _
> , ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:= _
> True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
> Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 3), Array(7, 1)), TrailingMinusNumbers _
> :=True
> Selection.Copy
> Range("A2").Select
> ActiveSheet.Paste
> Range("A1").Select
> Application.CutCopyMode = False
> Selection.EntireRow.Delete
>End Sub
Previous
Reply
Map
View

Click here to load this message in the networking platform