?
Solved

Need to upload file to web server

Posted on 2003-03-18
11
Medium Priority
?
325 Views
Last Modified: 2008-03-03
All,

We need to receive files from a trading partner.  The files are zipped (for size) and we need them to be transmited over ssl for security.

We are looking at hosting FTP/SSL, but we also want to look at HTTP/SSL.

There are libraries (plenty) for the FTP side, and there appear to be third-party libraries for the HTTP side as well, but we'd like to do this with XMLHTTP if possible.

Is there a way to attach a file on the client O/S (Win32) to an XMLHTTP Post or Put?  We do not want to read the file and embed it as I've seen elsewhere, we want to deliver the file to the server in the same format and manner as would happen if someone used a form and selected it.

We really need an example of doing this if it's possible.
0
Comment
Question by:klamerus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +1
11 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8159450
hearing...
0
 
LVL 1

Author Comment

by:klamerus
ID: 8160783
boosting points
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8161031
Well, to this moment, i only knows as FTP. Sorry.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:Shaka913
ID: 8161562
Let me recap this question, and correct me if I mess something up. you want to create a client to client secure file transmission system, whereby a trading partner, opens a website, and "uploads" a file, the file is received on your host system, and is available for download anytime?

is this correct?
0
 
LVL 1

Author Comment

by:klamerus
ID: 8162354
Some right/some wrong.

This isn't a client-to-client scenario.  We have the servers and we can host either FTP or HTTP.

We can easily do FTP.  We have several libraries for doing so, with or without SSL.

We know that an individuals can upload files (either with or without SSL) via standard web forms.  We know how to "catch" the files on the server (we use IIS) several ways.

What we don't know how to do is send files from a client to the server via the XMLHTTP object (or some other MS provided component).  That's what we want to do.

We're not looking to allow user downloads.  That's fairly simple though.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 8162529
If someone uses a browser with a form to upload a file, it then is "encoded and embedded" in the POST as you have seen elsewhere.  This is part of the HTTP specification, which you will find hard to get around if you are uploading to a web server...  So what are you looking for that is different?
0
 
LVL 3

Accepted Solution

by:
Shaka913 earned 2000 total points
ID: 8162734
This uses xmlhttp to stream a file via a put to the server.

it uses vbscript on a client side implementation.


<script language=VBSCRIPT>
dim strURL
function sendit( sfileName, sType)
sData = getFileBytes(sfileName, sType)
sfileName= mid(sfileName, InstrRev(sFileName,"\")+1,len(sfileName))
dim xmlhttp
set xmlhttp=createobject("MSXML2.XMLHTTP.3.0")
strURL = "http://localhost/" & sFileName
msgbox "URL is: " & strURL
xmlhttp.Open "PUT", strURL, false
xmlhttp.Send sData
show.innerText= "Status: " & xmlhttp.statusText
set xmlhttp=Nothing
End function

sub showresult()
document.write "<CENTER>Take A look!<BR><A href=" & strURL & ">"& strURL & "</a></CENTER>"
end sub

function getFileBytes(flnm, sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="on" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="on" then
getFileBytes=objStream.Read
else
getFileBytes= objStream.ReadText
end if
objStream.Close
Set objStream = Nothing
end function
</script>

<TABLE align=center>
<TR><TD><input type=FILE id=filedata ></TD></TR>
<TR><TD><input type=submit onclick="Call sendit( filedata.value, filetype.value)"></TD></TR>
<TR><TD><input type=checkBox id=filetype checked >Type Binary (Uncheck for Type Text)</TD></TR>
<TR><TD><input type=button value = "SHOW IT" onclick ="showresult()"></TD></TR>
</TABLE>
<div id=show align=center></div>

0
 
LVL 1

Author Comment

by:klamerus
ID: 8163179
To PaulHews:

Actually, I want the file embedded in the upload, but I need for the upload to to seem like a normal browser upload, not some encoded data in an XML request.  We need to decode (catch) the data with SA FileUp (our corporate standard).

To Shaka913:

Does the sample translate to standalone VB or VBScript?  Our trading partners aren't going to manually enter files in a browser window.  We need something they can automate via some scheduler.  It looks like like it should.  It looks like all I need is the code.

I'll give it a shot at work tomorrow when I have a server avalailble.
0
 
LVL 1

Author Comment

by:klamerus
ID: 8163333
To PaulHews:

Actually, I want the file embedded in the upload, but I need for the upload to to seem like a normal browser upload, not some encoded data in an XML request.  We need to decode (catch) the data with SA FileUp (our corporate standard).

To Shaka913:

Does the sample translate to standalone VB or VBScript?  Our trading partners aren't going to manually enter files in a browser window.  We need something they can automate via some scheduler.  It looks like like it should.  It looks like all I need is the code.

I'll give it a shot at work tomorrow when I have a server avalailble.
0
 
LVL 1

Author Comment

by:klamerus
ID: 8163336
That was weird
0
 
LVL 1

Author Comment

by:klamerus
ID: 8163531
Shaka913 seems to have hit on a winner.  I took the liberty of converting the example (and I found the source of the sample in a web search as well) into a stand-alone vbscript file and ran it uploading to an IIS server running on my WinXP workstation and it ran perfectly.

It stated "Forbidden" status when I had security off
It stated "Created" status when I got an upload
It stated "OK" status when I did an upload for a file that I uploaded previously
It uploaded either text or binary as text or binary correctly (and as specified)
It generated an error when I specified the wrong file type (text or binary)

Everything worked exactly as needed:


Dim strUploadURL
Dim strUploadFileName          ' Set equal to whatever
Dim strUploadFileType          ' Set equal to "Binary" or "Text"

strUploadURL = "http://localhost/Uploads/"
strUploadFileName = "C:\Temp\Test.txt"
strUploadFileType = "Text"

Call SendIt()


Function SendIt( )
     
     Dim objXMLHTTP
     Dim strURL
     Dim varData
     
     varData = GetFileBytes( strUploadFileName, strUploadFileType )
     strFileName = Mid( strUploadFileName, InStrRev( strUploadFileName, "\" ) + 1, Len( strUploadFileName ) )
     
     MsgBox strFileName

     Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
     
     strURL = strUploadURL & strFileName
     
     MsgBox "URL is: " & strURL
     
     objXMLHTTP.Open "PUT", strURL, false
     objXMLHTTP.Send varData
     
     MsgBox "Status: " & objXMLHTTP.statusText
     
     Set objXMLHTTP = Nothing
     
End Function

Function GetFileBytes( strFileName, strFileType )

     Dim objStream
     
     Set objStream = CreateObject("ADODB.Stream")
     
     If strFileType = "Binary" Then
          objStream.Type = 1          ' adTypeBinary
     Else
          objStream.Type = 2          ' adTypeText
          objStream.Charset = "ascii"
     End If
     
     objStream.Open
     objStream.LoadFromFile strFileName
     
     If strFileType = "Binary" Then
          getFileBytes=objStream.Read
     Else
          getFileBytes= objStream.ReadText
     End If

     objStream.Close
     
     Set objStream = Nothing
     
End Function
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question