Results 1 to 22 of 22

Thread: Posting a local file to my web server

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Posting a local file to my web server

    Hi there,

    I have been searching the web for weeks now, on info to help me make my little hobby project work.

    On my local computer, I have a file that I want to upload to a web server. Lets just call it c:\information.txt

    Instead of having to open a web browser, browse to my site, click a Browse button on a <input type=file> field, then selecting the file and clicking Submit, I would like to have a .vbs file that I can just double-click, after which it posts the file, using HTTP POST, to my web server.

    So in short: How to make a .vbs script that can replace the following form:

    <form action=url-to-web-server.asp method=post enctype=multipart/form-data>
    <input type=hidden name=id value=thomashess>
    <input type=file name=thefile>
    <input type=submit value=send>
    </form>


    I know I might be able to do it using some 3rd party component, but the trick is to be able to do it from any Windows PC. I want other to be able to send the same file from their computer to my web server too, just with another value in the ID file. But I guess it should be able to do with just the WinSock component.

    The script should be in the VB Script language.

    Hope this makes sense, otherwise ask me for further info. Any help with pointers to the right direction is greatly appreciated..!!

    Sincerely,
    Thomas Hess

    Copenhagen, Denmark

  2. #2
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Posting a local file to my web server

    Can i ask what type of file it is? text, or binary?
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Re: Posting a local file to my web server

    Quote Originally Posted by kazar
    Can i ask what type of file it is? text, or binary?
    It is a plain text file. Here is a snip of the content:


    rpgoCPpref = {
    ["enabled"] = true,
    ["honorold"] = true,
    ["debug"] = false,
    ["questsfull"] = false,
    ["tooltipshtml"] = true,
    ["lite"] = true,
    ["scan"] = {
    ["inventory"] = true,
    ["talents"] = true,
    ["honor"] = true,
    ["reputation"] = true,
    ["spells"] = true,
    ["pet"] = true,
    ["equipment"] = true,
    ["professions"] = true,
    ["mail"] = true,
    ["skills"] = true,
    ["quests"] = true,
    ["bank"] = true,
    },
    ["ver"] = 10500,
    ["reagenthtml"] = true,
    ["talentsfull"] = true,
    }


    etc.

    -Thomas

  4. #4
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Posting a local file to my web server

    Well, are you okay with calling an object? Because if you are, and call the inet control, then you can simply use the code i have posted here.

    It needs an asp file on the server, and then call it, with each line of the file in the address string.

    Alternatively, if you were willing to use a vb program, it would be a lot easier. Insert a inet control into the exe, and then call the page. Vbscript it could be done, but you would have to call an inet object. Tell me which you want to do and i can post the code.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Re: Posting a local file to my web server

    Quote Originally Posted by kazar
    Well, are you okay with calling an object? Because if you are, and call the inet control, then you can simply use the code i have posted here.

    It needs an asp file on the server, and then call it, with each line of the file in the address string.

    Alternatively, if you were willing to use a vb program, it would be a lot easier. Insert a inet control into the exe, and then call the page. Vbscript it could be done, but you would have to call an inet object. Tell me which you want to do and i can post the code.
    Thanks for the answer. But as far as I can tell, your code opens the file, reads it line-by-line, then posts the lines to the server, which then creates a text file server-side and writes the lines back into the file.. right?

    What I need to be able to do is to "simulate" (in lack of a better word) a standard HTML form that posts a <input type=file> object using the enctype=multipart/form-data, so I can my Persits.Upload component catch it from the HTTP header and then save the file to disk.

    The thing is, the receiving file (which actually is in PHP) is already coded and I have a form that can upload the file. But many users are having a hard time finding the correct data file to upload. So instead, I wanted to code a .VBS script that would just post the file for them when they double-click it.

    Hope it makes sense... Can't find any info on the net how to to a HTTP post from VBScript.. :-(

    Sincerely,
    Thomas

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Posting a local file to my web server

    Maybe a redesign is in order? Just ftp the file, using a small dedicated program? (Many people won't run script files because of the connection with Trojans.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Re: Posting a local file to my web server

    Quote Originally Posted by Al42
    Maybe a redesign is in order? Just ftp the file, using a small dedicated program? (Many people won't run script files because of the connection with Trojans.)
    Unfortunately, that is not an option. And the people using this script won't be worried about trojans.

    But I guess it's not possible then..? Or at least, no one has the answer :-)

    -Thomas

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Posting a local file to my web server

    Oh, it's possible. But it can be a lot of work.

    You need to do some digging. To start with I suggest you write your script to use MSXML's XMLHTTPRequest object. If your customers have IE 5.0 or later installed their machines already have this component.

    The documentation you'll see on using this component from script tends to be a bit meager though. Most script uses are for GETs or for POSTs of a blob of XML data.

    To do an HTTP POST conforming to standards of an HTML form's submit action can be fiddly. More so if you are trying to act like a HTML form with an <INPUT type=file> element in it.

    One place to start may be IXMLHTTPRequest Members but be warned you will not find a cookbook there. The material is strongly C++ oriented, but with a few JScript and VB sample fragments in it.


    There is a good reason you will not see much on this topic on the web. The various renditions of XMLHTTPRequest (there are many copies of the IE component out there now, Mozilla has one, FireFox, etc. all slightly different but more or less the same thing) are most commonly used today to implement a thing people now like to call "Ajax."

    It's a rehash of a Microsoft technology called Remote Scripting, but what's important to us here is Ajax is done within the context of a web page. The security model of today's browsers does not permit script in a web page to open local files willy-nilly.

    Since script can't open local disk files, and script uses XMLHTTPRequest to GET/POST data to a web server, and to POST a file's contents you have to be able to read it... they don't.


    The good news is your WSH script will not have such limitations. Um, you ARE talking about a WSH script right? Not script in a web page?

    The bad news is since most XMLHTTPRequest users can't use POST with files (as I just described) there is a dearth of samples and advice out there.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Re: Posting a local file to my web server

    Quote Originally Posted by dilettante
    Oh, it's possible. But it can be a lot of work.

    You need to do some digging. To start with I suggest you write your script to use MSXML's XMLHTTPRequest object. If your customers have IE 5.0 or later installed their machines already have this component.

    The documentation you'll see on using this component from script tends to be a bit meager though. Most script uses are for GETs or for POSTs of a blob of XML data.

    To do an HTTP POST conforming to standards of an HTML form's submit action can be fiddly. More so if you are trying to act like a HTML form with an <INPUT type=file> element in it.

    One place to start may be IXMLHTTPRequest Members but be warned you will not find a cookbook there. The material is strongly C++ oriented, but with a few JScript and VB sample fragments in it.


    There is a good reason you will not see much on this topic on the web. The various renditions of XMLHTTPRequest (there are many copies of the IE component out there now, Mozilla has one, FireFox, etc. all slightly different but more or less the same thing) are most commonly used today to implement a thing people now like to call "Ajax."

    It's a rehash of a Microsoft technology called Remote Scripting, but what's important to us here is Ajax is done within the context of a web page. The security model of today's browsers does not permit script in a web page to open local files willy-nilly.

    Since script can't open local disk files, and script uses XMLHTTPRequest to GET/POST data to a web server, and to POST a file's contents you have to be able to read it... they don't.


    The good news is your WSH script will not have such limitations. Um, you ARE talking about a WSH script right? Not script in a web page?

    The bad news is since most XMLHTTPRequest users can't use POST with files (as I just described) there is a dearth of samples and advice out there.
    Thanks for the answer

    Yes, plans where to make a VBS/WSH script, that should be run at the command prompt. I've looked through the link above, and yeah, it's not a straight-on kinda thing to do. Hmm.. I guess the time is better spent trying to learn the users to find the right file, than starting to code this thing - which would probably make me run into other problems (security settings etc.)

    Thanks again for the answers :-)

    Sincerely,
    Thomas

  10. #10
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Posting a local file to my web server

    this isnt sending a file but shows in vbscript how to send a post to a website form .. im used to using GET myself but same idea .. if you had access to the remote server it would make it much easier to upload the file .. but it is doable either way.

    Also see this link ..
    http://www.motobit.com/tips/detpg_uploadvbsie/

    Code:
    Option Explicit
    
    Dim strURL
    Dim objHttp
    
    On Error Resume Next
    
    strURL = "http://www.myurl.com/url-to-web-server.asp?id=thomashess"
    
    Set objHttp = WScript.CreateObject("Microsoft.XMLHTTP")
    objHttp.Open "POST", strURL, False
    objHttp.Send ""
    
    Set objHttp = Nothing
    
    If Err = 0 Then
    	MsgBox "Data Sent"
    Else
    	MsgBox "Error" & vbCrLf & Err.Description
    End If
    Last edited by rory; Jul 3rd, 2006 at 02:48 AM.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Posting a local file to my web server

    If all you want to do is copy the file to the site, there's another way:

    Create a link to the site in Network Neighborhood. The link will work the same as any other folder on the desktop. Then you can just use any of the normal methods of file copying to copy the file to the folder. (If the site is password protected a standard ftp login/password form will open automatically. the user can choose to remember the password from use to use.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  12. #12

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Re: Posting a local file to my web server

    Just to clarify, no, it's not about just uploading a file. That's easy enough ;-)

    This is the form:
    http://www.serenity-guild.dk/roster/admin/update.php

    People need to navigate to the c:\program files\world of warcraft\***\Account\*Accountname*\SavedVariables folder and select the CharacterProfiler.lua file.

    But many are having trouble with this, due to lack of computer skills and some files sharing the same name (characterprofiler.lua, .bak, .txt, .xml etc)

    So people keep uploading the wrong files. Tried to help them countless times by giving directions on our forum, but some are still having problems.

    That's why I thought of making this program that "uploads" (read: POSTs) the file to the web server, just like the form on the above mentioned page.

    But from what I've learned reading this thread, that is a tedious exercise. :-(

    -Thomas

  13. #13
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Posting a local file to my web server

    if you post the web page that contains the upload form then ill have something to work with ...

  14. #14

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Re: Posting a local file to my web server

    Quote Originally Posted by rory
    if you post the web page that contains the upload form then ill have something to work with ...
    I just did? Anyways, here is the form:

    HTML Code:
                    <form ENCTYPE="multipart/form-data" method="POST">
                      <table class="bodyline" cellspacing="1" cellpadding="2">
    
                        <tr class="membersRow1">
                          <td colspan="2"><small>Click browse and upload your *.lua files<br />
    (These files are located in *WoW Directory*\***\Account\*Accountname*\SavedVariables\*.lua)<br /></small></td>
                        </tr>
                        <tr class="membersRow2">
                          <td>CharacterProfiler.lua (Required)</td>
                          <td><input type="file" accept="CharacterProfiler.lua" name="CharacterProfiler"></td>
                        </tr>
    
                        <tr class="membersRow2">
                          <td>Roster Update Password (Optional)<br />
                            <small>(This is required when doing a guild update)</small></td>
                          <td><input type="password" name="roster_update_password"></td>
                        </tr>
    
                        <tr class="membersRow1">
                          <td>Run "Update Triggers" on guild update?<br />
                            <small>(Warning: This may appear to "stall" the update)</small></td>
                          <td>
                            <input name="update_trigger" type="checkbox" value="1">
                          </td>
                        </tr>
                        <tr class="membersRow1">
                          <td colspan="2"><center><input type="submit" value="Upload"></center></td>
                        </tr>
                      </table>
                    </form>

  15. #15
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Posting a local file to my web server

    I don't have access to WOW on this computer (my wife's a Shaman but I'm at work now), so I'll ask - is the file always in the same place on the same drive, or does the user have installation options that may put it somewhere else? (The latter would make your task a bit more complicated.) If it's always in the same place, an ftp program that just uploads a single file from a single place to a single destination is a simple program.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  16. #16

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    9

    Re: Posting a local file to my web server

    Quote Originally Posted by Al42
    I don't have access to WOW on this computer (my wife's a Shaman but I'm at work now), so I'll ask - is the file always in the same place on the same drive, or does the user have installation options that may put it somewhere else? (The latter would make your task a bit more complicated.) If it's always in the same place, an ftp program that just uploads a single file from a single place to a single destination is a simple program.
    The file is in a different folder/drive, depending on where the users install her WoW. But still, just ftp'ing the file to the server wouldnt be enough. It still had to go through the script that parses it, forcing me to rewrite someone elses PHP code.

    :-(

  17. #17
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Posting a local file to my web server

    Quote Originally Posted by ThomasHess
    The file is in a different folder/drive, depending on where the users install her WoW.
    But many are having trouble with this, due to lack of computer skills and some files sharing the same name (characterprofiler.lua, .bak, .txt, .xml etc)

    So people keep uploading the wrong files.
    So you want to be able to upload a file that's almost anywhere on the computer without user intervention. I think I see a conflict between "without user intervention" and "anywhere".
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  18. #18
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Posting a local file to my web server

    Theoretically, AL42, the program could browse the system to find the file, and then upload it.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Posting a local file to my web server

    Does your "theoretically" include "may take half an hour or so, during which time the computer will appear to have died"? Searching a few hundred gigs of files in hundreds (thousands, maybe) of directories isn't a fast process.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  20. #20
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Posting a local file to my web server

    thats why i used the word 'theoretically'. it is possible, but impractical
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  21. #21
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Posting a local file to my web server

    So many things are possible theoretically, but insisting that your users spend the small amount of time and effort needed to learn to run your app successfully is practically possible. (And remember, not everyone is really intellectually qualified to use a computer. )
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  22. #22
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Posting a local file to my web server

    How irritatingly true. But worse is the people who think they are intellectually qualified but aren't. The number of times my clients have wondered why the program doesn't work if they move the dlls i use to run it....
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width