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!

FSO & local PC help 2

Status
Not open for further replies.

scribbler

MIS
Feb 4, 2002
206
GB
Please can anyone tell me if it is possible to read a file on my local pc and use it's information to populate a database on the server ?

I have used fso to read files Ive uploaded onto the server but hoped to save the hassle of uploading large files and then running thro' them to read the conents for a 2nd time.
 
Is there any way you can get this data in a ZIP or other archive format? ASCII text usually compresses very well so this might help cut down on the transfer times to you server.

Actually, with the scale of data that you are dealing with, I'd consider a two part solution...

On the remote machine you have a little scheduled task that grabs the file and zips it, then opens an FTP session to your IIS machine and moves the compressed file over FTP instead of HTTP.

On the other end you have SQL Server. You create a DTS package that grabs the zip file off the FTP folder, inflates it, and then imports it. The DTS packages uses a visual workflow interface that is quick to learn and then the customized scripting can be done in VBScript so it is a lot like developing for ASP except the entire point is moving data around so it is much better at these sorts of things.
 
Sheco

I can zip the data up but didn't realise that I could run unzip on the remote server.

As I'm a newbie to most of this the tasks you mention seem a little daunting for my limited knowledge. I think what I will do is to continue my attempt at developing the site and return to this when I have more time available to devote to it. I will also take a look at the sql server stuff to see if there are benefits to changing.

Thanks very much for your information though it has given me food for thought.
 
scribbler, if you want to test it here is a file upload script.
This code is to do binary uploads to a server.
On the HTML page you select your file and when submitted it passes to an ASP page which reads the file type and binary encodes it and passes it up to the server to a file path stated in the ASP page. You just need to make sure that the path is setup correctly and that the access rights on the server are appropriate for the script to write the file.
At the bottom of the ASP page you can insert your processing code.
This can semi-automate the process for you. I suspect the binary encoding that this script does may be slower for you than copying manually but it is something you could start and walk away from and not worry about and is simple to implement.

Sheco's suggestion is the best if you have the resources to put it in place. It's just a question of whether you have control over the source feed of data or not and if you have the ability to setup the extraction on the destination server. It would be the fastest method by far.

There are three files to this upload script. This is a slightly simplified version of code that can be found at:

First file.
Save this as insert.htm
<html>
<head>
<title>File Uploading with ASP</title>
<style>
body, input { font-family:verdana,arial; font-size:10pt; }
</style>
</head>
<body>
<p align="center">
<b>File Uploading with ASP</b><br>
</p>

<table border="0" align="center">
<tr>
<form method="POST" enctype="multipart/form-data" action="Insert.asp">
<td>File :</td><td>
<input type="file" name="file" size="40"></td></tr>
<td>&nbsp;</td><td>
<input type="submit" value="Submit"></td></tr>
</form>
</tr>
</table>
</body>
</html>

Second file. This is the file you would put your own processing code into where I have marked near the bottom.
Change the path to save the file in the pathToFile variable.
Save this as insert.asp
<!--#include file="Loader.asp"-->
<%
Response.Buffer = True

' load object
Dim load
Set load = new Loader

' calling initialize method
load.initialize

' File binary data
Dim fileData
fileData = load.getFileData("file")
' File name
Dim fileName
fileName = LCase(load.getFileName("file"))
' File path
Dim filePath
filePath = load.getFilePath("file")
' File path complete
Dim filePathComplete
filePathComplete = load.getFilePathComplete("file")
' File size
Dim fileSize
fileSize = load.getFileSize("file")
' File size translated
Dim fileSizeTranslated
fileSizeTranslated = load.getFileSizeTranslated("file")
' Content Type
Dim contentType
contentType = load.getContentType("file")
' No. of Form elements
Dim countElements
countElements = load.Count
' Value of text input field "name"
Dim nameInput
nameInput = load.getValue("name")
' Path where file will be uploaded
Dim pathToFile
pathToFile = Server.mapPath("uploaded/") & "\" & fileName
' Uploading file data
Dim fileUploaded
fileUploaded = load.saveToFile ("file", pathToFile)

' destroying load object
Set load = Nothing

If fileUploaded = True Then
Response.Write fileName & " data uploaded..."
' ######## Insert your file processing code here #######
Else
Response.Write "<font color=""red"">File could not be uploaded...</font>"
Response.Write "<br>Please select a file before hitting the 'Submit' button."
End If
%>

Third file. This does all of the work.
Save as Loader.asp
<%
' -- Loader.asp --
' -- version 1.5.2
' -- last updated 12/5/2002
'
' Faisal Khan
' faisal@stardeveloper.com
' ' Class for handling binary uploads

Class Loader
Private dict

Private Sub Class_Initialize
Set dict = Server.CreateObject("Scripting.Dictionary")
End Sub

Private Sub Class_Terminate
If IsObject(intDict) Then
intDict.RemoveAll
Set intDict = Nothing
End If
If IsObject(dict) Then
dict.RemoveAll
Set dict = Nothing
End If
End Sub

Public Property Get Count
Count = dict.Count
End Property

Public Sub Initialize
If Request.TotalBytes > 0 Then
Dim binData
binData = Request.BinaryRead(Request.TotalBytes)
getData binData
End If
End Sub

Public Function getFileData(name)
If dict.Exists(name) Then
getFileData = dict(name).Item("Value")
Else
getFileData = ""
End If
End Function

Public Function getValue(name)
Dim gv
If dict.Exists(name) Then
gv = CStr(dict(name).Item("Value"))

gv = Left(gv,Len(gv)-2)
getValue = gv
Else
getValue = ""
End If
End Function

Public Function saveToFile(name, path)
If dict.Exists(name) Then
Dim temp
temp = dict(name).Item("Value")
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fso.CreateTextFile(path)
For tPoint = 1 to LenB(temp)
file.Write Chr(AscB(MidB(temp,tPoint,1)))
Next
file.Close
saveToFile = True
Else
saveToFile = False
End If
End Function

Public Function getFileName(name)
If dict.Exists(name) Then
Dim temp, tempPos
temp = dict(name).Item("FileName")
tempPos = 1 + InStrRev(temp, "\")
getFileName = Mid(temp, tempPos)
Else
getFileName = ""
End If
End Function

Public Function getFilePath(name)
If dict.Exists(name) Then
Dim temp, tempPos
temp = dict(name).Item("FileName")
tempPos = InStrRev(temp, "\")
getFilePath = Mid(temp, 1, tempPos)
Else
getFilePath = ""
End If
End Function

Public Function getFilePathComplete(name)
If dict.Exists(name) Then
getFilePathComplete = dict(name).Item("FileName")
Else
getFilePathComplete = ""
End If
End Function

Public Function getFileSize(name)
If dict.Exists(name) Then
getFileSize = LenB(dict(name).Item("Value"))
Else
getFileSize = 0
End If
End Function

Public Function getFileSizeTranslated(name)
If dict.Exists(name) Then
temp = 1 + LenB(dict(name).Item("Value"))
If Len(temp) <= 3 Then
getFileSizeTranslated = temp & " bytes"
ElseIf Len(temp) > 6 Then
temp = FormatNumber(((temp / 1024) / 1024), 2)
getFileSizeTranslated = temp & " megabytes"
Else
temp = FormatNumber((temp / 1024), 2)
getFileSizeTranslated = temp & " kilobytes"
End If
Else
getFileSizeTranslated = ""
End If
End Function

Public Function getContentType(name)
If dict.Exists(name) Then
getContentType = dict(name).Item("ContentType")
Else
getContentType = ""
End If
End Function

Private Sub getData(rawData)
Dim separator
separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)

Dim lenSeparator
lenSeparator = LenB(separator)

Dim currentPos
currentPos = 1
Dim inStrByte
inStrByte = 1
Dim value, mValue
Dim tempValue
tempValue = ""

While inStrByte > 0
inStrByte = InStrB(currentPos, rawData, separator)
mValue = inStrByte - currentPos

If mValue > 1 Then
value = MidB(rawData, currentPos, mValue)

Dim begPos, endPos, midValue, nValue
Dim intDict
Set intDict = Server.CreateObject("Scripting.Dictionary")

begPos = 1 + InStrB(1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
nValue = endPos

Dim nameN
nameN = MidB(value, begPos, endPos - begPos)

Dim nameValue, isValid
isValid = True

If InStrB(1, value, stringToByte("Content-Type")) > 1 Then

begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))

If endPos = 0 Then
endPos = begPos + 1
isValid = False
End If

midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "FileName", trim(byteToString(midValue))

begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
endPos = InStrB(begPos, value, ChrB(13))

midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "ContentType", trim(byteToString(midValue))

begPos = endPos + 4
endPos = LenB(value)

nameValue = MidB(value, begPos, ((endPos - begPos) - 1))
Else
nameValue = trim(byteToString(MidB(value, nValue + 5)))
End If

If isValid = True Then

intDict.Add "Value", nameValue
intDict.Add "Name", nameN

dict.Add byteToString(nameN), intDict
End If
End If

currentPos = lenSeparator + inStrByte
Wend
End Sub

End Class

Private Function stringToByte(toConv)
Dim tempChar
For i = 1 to Len(toConv)
tempChar = Mid(toConv, i, 1)
stringToByte = stringToByte & chrB(AscB(tempChar))
Next
End Function

Private Function byteToString(toConv)
For i = 1 to LenB(toConv)
byteToString = byteToString & chr(AscB(MidB(toConv,i,1)))
Next
End Function
%>
 
There are lots of options for zipping and unzipping programmatically. The most straightforward would be to execute a shell command line to do it but you could also look for a COM object to use in code.
 
Thanks theniteowl you supplied quite a lot of code for me and I'll give it a try and see what results I obtain.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top