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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading file from Access to remote server using http

Status
Not open for further replies.

ronnib

Programmer
Joined
Mar 29, 2005
Messages
5
Location
IE
Hi there,

As the subject suggests i was wondering if there was any way of uploading a file from Access using http rather than FTP? If so could someone tell me how to do it?

Thanks a million in advance
 
Microsoft ships a redistributable msinet.ocx with a number of products including
Visual Basic 5.0, 6.0, Office 2000 Developer, Visual FoxPro 6.0, Visual C++ 5.0, 6.0.
This file hosts Microsoft Internet Transfer Control which implements a number of
protocols including HTTP and FTP.
You need to know the commands that initiate the operations.

The code snippet given below shows how to use Microsoft Internet Transfer Control to upload
a file to a machine. To use the code, make sure that you add a reference to Microsoft Internet
Transfer Control. To add a reference to it

Select Tools | References....
Select Microsoft Internet Transfer Control from the available references.

If it is not available, click the Browse... button. You will be presented with the Add Reference dialog box.
Locate and select MSINET.OCX. This file is usually present in the System folder.
Click Open to dismiss the Add Reference dialog box.
Click OK.

Code:
Function UploadFile(ByVal HostName As String, _
  ByVal UserName As String, _
  ByVal password As String, _
  ByVal LocalFileName As String, _
  ByVal RemoteFileName As String) As Boolean
On Error GoTo ErrHandler

  Dim oInet As Inet

  Set oInet = New Inet
  With oInet
    .Protocol = [blue]icHTTP[/blue]
    .RemoteHost = HostName
    .UserName = UserName
    .password = password
    .Execute .url, "Put " + LocalFileName + " " + RemoteFileName
    Do While .StillExecuting
        DoEvents
    Loop
    UploadFile = (.ResponseCode = 0)
  End With

ExitHere:
  On Error Resume Next
  Set oInet = Nothing
  Exit Function
ErrHandler:
  Debug.Print Err, Err.Description
  Resume ExitHere
End Function

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
VBSlammer thanks a million for your help/advice. My problem is that i have already implemented a similar piece of code using Inet and it didnt work. If i choose the protocol icFTP then the file flies up onto the remote machine and is there in a flash, but when i use icHTTP even though i dont get any errors it does nothing.

I used the code you posted too - which is practically identical to mine - and i get the same problem.

Maybe i'm doing something blatently wrong but i dont think so.

Any ideas?
 
I've found no documentation anywhere that really explains the syntax for the Execute method using HTTP. Most examples are focused on downloading data. The PUT command is supposedly able to replace data at the specified url, but I've never been able to make it work.

This is all the documentation I have (from programmer's guide & msdn):

Using the Execute Method with the HTTP Protocol

The HTTP protocol allows client machines to request data from the server using the GET, HEAD, POST, and PUT commands. These operations are shown below:

GET Retrieves the file named in url.

[tt]Execute " & _
"/default.htm", "GET"[/tt]

HEAD Retrieves only the headers of the file named in the URL property.

[tt]Execute , "HEAD"[/tt]

POST Provides additional data to support a request to the remote host.

[tt]Execute , "POST", strFormData[/tt]

PUT Replaces data at the specified URL.

[tt][blue]Execute , "PUT", "replace.htm"[/blue][/tt]

The only other techniques I've seen used require communication between the local application and an ASP page on the web server. If you have the means to add an "Upload.asp" file to the web then that may be an option.



VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Thank you for your feedback. From what i managed to find on the web http can only be used by Inet for downloading a file and not uploading.

Eventually after much trial and error i managed to get an upload function written that works - and it does indeed interact with an asp page on the web server.

It uses the MSXML2.dll in both Access and on the asp page. You use MSXML2.DOMDocument to load the file and MSXML2.XMLhttp to send it using:

.Open "post", " False

followed by

.Send xmlDoc

The asp page then processes what you send it so it looks something like this (most basic form)

<%@ Language=VBScript %>
<% set xml = server.createObject("Msxml2.DOMDocument")
xml.async=false
xml.load(request)
Response.ContentType="text/xml"
xml.save(Server.MapPath("myfile.xml"))
%>

I hope this helps someone else - i know it was a pain to find anywhere that had any good, straightforward information on how to do it.

Thanks again for all your help VBSlammer - much appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top