02-16-2010 01:53 PM
I am trying to download a simple text file locally to the computer using CVI (Basic package).
i have seen numerous examples of Web browser and other crazy whistle programs. All I want to do is travel to a URL and download the text file in the background. I tried using the IWebBrowser program but could not figure out how to save the file to my specified output name without prompting the user.
To be even more specific, here is a sample URL. I want to save this file as yuma.txt in my working directory. No prompts or anything.
http://www.navcen.uscg.gov/archives/gps/2009/ALMANACS/YUMA/001.ALM
to be saved as yuma.txt
Please be specific on what instruments or dlls to use and where to get them.
Thanks alot!
Solved! Go to Solution.
02-17-2010 02:34 AM
I made up this sample application that performs reading through the web. Downloaded data are shown on screen: saving them to a file is up to you.
The program uses only windows API function to access remote file, so the only thing you will need to run it is full SDK that comes with CVI.
02-17-2010 10:44 AM
02-17-2010 12:11 PM
You could try something along the lines of this using the telnet library:
tlsession = InetTelnetOpen("www.navcen.uscg.gov", 80, 0);
tlstatus = InetTelnetWrite(tlsession, "GET http://www.navcen.uscg.gov/archives/gps/2009/ALMANACS/YUMA/001.ALM HTTP/1.1Host: www.navcen.uscg.gov", "\r\n", -1, &byteswritten, 25000);
tlstatus = InetTelnetRead(tlsession, tlread, 100000, &bytesread, 25000);
The complications are that upon reading you will either have to wait until the timeout, key off something on the page to know when you hit the end and use the function InetTelnetReadUntil(), or know the exact number of bytes the server is going to serve up. There will also be some header information you'll have to strip out.
You'll need the telnet library which is part of the internet library I do not know if it included in the more basic CVI package.
02-17-2010 12:30 PM
Internet is not included ... if it was, it would be much simpler!
Errors from the telnet example include:
Undefined symbol '_InetTelnetOpen@12' referenced in "telnet.c"
Undefined symbol '_InetTelnetRead@20' referenced in "telnet.c".
Undefined symbol '_InetTelnetWrite@24' referenced in "telnet.c".
Undefined symbol '_InetTelnetClose@4' referenced in "telnet.c".
Which by the way are really annoying when NI includes all these examples and yet half of them don't work because I have the Basic version.
02-18-2010 02:13 PM
I suggest you install the free cygwin package (get it at http://cygwin.com).
Then you can use the wget program as a simple solution. Plus you get a
lot of useful unix tools. It looks like there is also a version available at
http://gnuwin32.sourceforge.net/packages/wget.htm , but I haven't tried
that one.
#include <stdio.h> #include <utility.h> #include <ansi_c.h> int main(int argc, char *argv[]) { int ret; ret = LaunchExecutable("e:\\cygwin\\bin\\wget http://www.navcen.uscg.gov/archives/gps/2009/ALMANACS/YUMA/001.ALM"); if (ret) { fprintf(stderr, "ret is %d\n", ret); fprintf(stderr, "Press a key to exit.\n"); GetKey(); } exit(ret); }
I have tested the above and it seems to work.
---
Marty O.
02-19-2010 08:38 AM
That mini program does work, however, I am not sure how I would include and check to make sure that the end-user has that program upon installation.
The workaround i see with this though, is when the user does download, once he runs the program, I can check for a certain library/wget file in the registry, and if it's not there, ask them to download. If it is there, then I can download the file I need.
As i was thinking about it, another workaround is using the webbrowser program/fp and have it operate on a hidden panel, download the file automatically, then rename the file (if needed), then discard the panel. this, however would have alot of overhead.
02-19-2010 09:46 AM - edited 02-19-2010 09:47 AM
After installing the GnuWin wget program, I was able to extract just the wget.exe and .dll files from the bin directory and get the program to work on another computer. So, this would be the ultimate solution.
http://gnuwin32.sourceforge.net/packages/wget.htm
Because of this, the only losses are not having a preset file that comes with the program installed in the default path (which you can bypass any input in command line arguments anyway) and having the register of the installedpath.
So this solution seems to work! Thanks
08-15-2013 11:23 AM
RMonitor.zip was very helpful. Thanks a lot. Hats off