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!

Copy online text file via HTTP

Status
Not open for further replies.

kentover

MIS
Aug 21, 2002
41
US
There is a daily text file that is accessible only through a URL such as I need to copy the file to a new network location. I have tried using the FileSystemObject methods but it does not like the URL path. Is there another method that will allow a copy through the URL?
 
One direct approach without beautifiers, modified from a previous sketch for a thread.
[tt]
'givens
dim surl,slocal
surl="slocal="d:\test\xyz.txt"

'start functional block
dim oxmlhttp,s
on error resume next
set oxmlhttp=createobject("msxml2.xmlhttp")
if err.number<>0 then
wscript.echo "msxml2.xmlhttp not installed. Operation aborted."
set oxmlhttp=nothing : wscript.quit 1 'or exit sub
end if
with oxmlhttp
.open "get",surl,false
.send
end with
if err.number<>0 then
wscript.echo "Resource unavailable for varied reasons. Operation aborted."
set oxmlhttp=nothing : wscript.quit 2 'or exit sub
end if
s=oxmlhttp.responseText
createobject("scripting.filesystemobject").opentextfile(slocal,2,true,-1).write s
if err.number<>0 then
wscript.echo "Local file creation error."
set oxmlhttp=nothing : wscript.quit 3 'or exit sub
end if
on error goto 0
'end functional block

wscript.echo "done"
[/tt]
 
Thank you for your response.

The code runs very well but is returning a XSL Stylesheet instead of the data within the text file.I have done additional research on the method you suggested but am still haveing trouble getting the actual data returned. The creation of the new text file works great. I just need to access the data to populate it. Here is the code:

Function Main()
DIM strPATH
DIM dtPrev
DIM strMONTH
DIM strDAY
DIM strYEAR
DIM strFILE
DIM oxmlhttp
DIM s

'File to replace
strFILE = "\\Servername\Foldername\TEXTNAME.txt"

'Get the new web path
dtPrev = NOW
strMONTH = Right("00" & Month(dtPrev), 2)
strDAY = Right("00" & Day(dtPrev), 2)
strYEAR = Year(dtPrev)
strPATH = " & strMONTH & "_" & strDAY & "_" & strYEAR & ".txt"

'Delete the old text file
DIM objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile strFILE

'Create a new copy of the web file
set oxmlhttp = createobject("msxml2.xmlhttp")
with oxmlhttp
.open "get",strPATH,false
.send
end with
s=oxmlhttp.responseText



createobject("scripting.filesystemobject").opentextfile(strFILE,2,true,-1).write s


Main = DTSTaskExecResult_Success
End Function


Here is the results saved within the new file:

<html>
<head>
<title>Apache Tomcat/5.0.25 - Error report</title>
<style>
<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}
B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;}
P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}
A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style>
</head>
<body>
<h1>HTTP Status 404 - /Servername/Foldername/Report_12_13_2007.txt</h1>
<HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b>
<u>/Servername/Foldername/Report_12_13_2007.txt</u>
</p><p><b>description</b>
<u>The requested resource (/Servername/Foldername/Report_12_13_2007.txt) is not available.</u></p>
<HR size="1" noshade="noshade">
<h3>Apache Tomcat/5.0.25</h3>
</body>
</html>
 
><u>The requested resource (/Servername/Foldername/Report_12_13_2007.txt) is not available.</u>
...and that's what it meant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top