I'm new to server management. 1) What is the VB code to automatically upload a file, such as the results of a test, to a web server online? 2) What must I do and have on my web server to get this to work?
Here's some code I found that I think will do the trick. I want the user to click a Submit button so it submits the results of a quiz to the WEb server:
To use XFile from Visual Basic, add XFile to your list of VB references.
Exercise 3: A Simple Visual Basic Upload
1. Create a new, standard, Visual Basic project.
2. Open the Project menu, select References, and check "SAXFile 1.0 Type Library".
3. Create a command button on your form, name it cmdSendFiles, and give it an appropriate caption (such as, "Upload").
4. Enter the following code in the code section of your form.
Private Sub cmdSendFiles_Click()
'--- Create an instance of the XFRequest object, XFile's principal object
Set XFile = New XFRequest
'--- Set the Server to which you are uploading
XFile.Server = "localhost"
'--- Set the specific script to which you are uploading
XFile.ObjectName = "/SAXFileSamples/asp/post/onefile/formresp.asp"
'--- Set a file to upload
XFile.AddFile "C:\boot.ini", "File1"
'--- Begin transferring the files
XFile.Start
'--- Destroy the XFRequest Object
Set XFile = Nothing
End Sub
5. Run the project and click on the upload button. Boot.ini will be uploaded to the local server.
Understanding the Script
* Set XFile = New XFRequest creates an instance of the XFRequest object. XFRequest is XFile's principal object. XFRequest sends the HTTP request (Get, Post, or Put) to the server.
* SAXFile.Server sets the domain to which the file will be posted. In this example we use "localhost." If we were posting through the Internet, we would use the format "www.domain.com."
* SAXFile.ObjectName specifies the exact page to which our request will be posted. In this case, it is formresp.asp, located in /saxfilesamples/asp/post/onefile. Formresp.asp uses SoftArtisans FileUp to process the upload.
* SAXFile.AddFile presets a file to upload. Addfile takes two parameters: the path and file name on the client, and an item name for reference to the file on the server.
* SAXFile.Start initiates the file transfer.
* Set XFile = Nothing destroys the project's instance of the XFRequest object. This prevents draining of your resources.
It does not sound like this will work for you. This uploads a file to a server, what you need is to send data to the server, not a whole file.
There are two ways you can do this.
The first, is to develop a server-side page on the server to accept the results (with ASP, PHP, ColdFustion, Perl, etc). Then you would develop an application to connect with the server and pass the quiz results.
The second would be to develop both a server application and a quiz application. This would probably be more messy for what you want, however.
Do you have any experience with the Winsock control?
"I don't want to live alone until I'm married" - M.M.R.P
Ive attached a program i made to this thread, download it, extract the files to somewhere, and load up the project.. Its a very simple winsock tutorial i made, each line is noted to let you know what it does.
When you have it on yourside, compile it, and run the compiled code, then run it again from VB or again from the .EXE you compiled.
After there both running, click the 'Server' button on 1, and click 'Connect' on the other.
I kept it very simple, but it works. If you have any questions please let me know.
Ok tried that and my folder is now on 766 but i still cant get it to work. Here's my remote connection:
domain/folder
Is this alright?
My server is Unix, does that help?
Looks like your trying to send a file from the client to the server or vice-versa, but when you send the file, it looks like your sending it to the IP(or domain) with the path included.. If you do that you need to parse it out on the receiving side.
you gotta send the other computer signals, or markers so that it knows what to do with the incoming information, you could also use multiple winsock controls doing this. Sometimes you'll run into problems and have to use multiple winsock controls, but for what im about to tell you, you only need to do it with one.
In your winsock control under DataArrival, you do your command to get the data, and put it in a string.
Then use Select Case to check the first character or 2 or 3 or however many you want, depending on how much is going into your program..
Those first characters are your markers, use Left$, Right$, and/or Mid$ to pull out the markers, and use Select Case to check what it is. And in your case, the first data you send will have a marker noting that its the path to put the file, and then the 2nd packet will be your filename(could include that in your first if you want), and 3+ packets would be the data for the file.
I'll just send you my code... if you go to KelceyCoe.com you'll find my email address. Send me an email so I know its you and then ill send you my project files. Thanks.
frmMain
txtRemoteCon.text : You can remove this, and the label for it. Since your program will most likely send to the same place each time. If it changes, hide it and use it to store the IP address or something. Dont use your .com address, you need to use the IP address.
txtRemotePort.text: Same goes with this, should be the same always, so you can just type in the code instead of having an extra useless control in your program.
for your SendFile sub, thats where you will have the host and port. For RemoteHost, only use the IP address, for RemotePort, just type in the value yourself.
txtFileName: You probably dont really need this either, and you probably dont even need to save it as a file on your computer unless you need to save the record of it to view it later on, on that same computer. Instead just dont unload the forms that have the info, hide them with FormName.Hide. Thats upto you though, sometimes using a file is much easier.
Under Send File is where you'll do all the work before sending the actual data. You'll do something like
Path and everything else the server should already know, if not then
VB Code:
SckSendFile.SendData "[Path]" & strPathName 'or whatever the path variable might be
On the receiving end, the server should be setup to check the first 6 of the incoming data, like this:
VB Code:
Select Case Left(Data, 6)
Case Is = "[File]" 'This is the filename
Data = Right(Data, Len(Data) - 6)
Case Is = "[Size]" 'This is the size of the file
Data = Right(Data, Len(Data) - 6)
Case Is = "[Path]" 'This is the directory to put the file in
Data = Right(Data, Len(Data) - 6)
Case Else 'This is the actual file, if the incoming data begins with anything else, its data.
End Select
Under Case Else is where all the code for receiving the file needs to go..
My only question is... This is looking like your trying to upload it to a web server. Do you have the domain being forwarded to your IP address and the server is your home computer? Or are you actually uploading this to another server where you cant put your own code?
1) I dont know anything about your web server or how you login or the username and pass or anything, becuase you have to have that to do this.
and 2) Isnt this homework?
I can help you with code and sample code, and i can help point you in the right direction, but actually finishing it for you i cant do. Im not sure anybody here will do that, but some people may try =)
Ok, for this you gotta make a whole seperate program just to play around with.
Your gonna want to setup the winsock control to connect to your server, and somewhere on your form have it display the .GetData
That way you can figure out exactly what needs to be sent and when, most likely you'll get encoded strings back which are gonna be hard to figure out how to get through, but since its a webserver it might just be short bursts of HTML requesting information like username, password, things like that..
Ive never done this part before successfully, but this is how i got my start on it, and i did get somewhere.. Play around with that, and maybe start up a new thread to see if anybody knows how to upload to a web server.
Since you cant just throw a server program you made on there, you gotta connect and upload the way the server expects you too..
Quick question... does this server support ASP coding? If so, why not just write an ASP page and have your client program submit [POST] the file to an ASP script which uploads it?
You'll need a bit more headers information because you want to POST form information (technically, at least). If you don't know how to do that then I'll look into it. (I know basically how it's done, but haven't yet done it.)
"I don't want to live alone until I'm married" - M.M.R.P
How can a program meant to download help me in uploading? I know nothing about uploading or downloading. I am going to contact my server host for further details with the other script but look forward to further replies from you guys. Thanks.
Because when you upload a file, you end up downloading a webpage in response. When you upload a file, you would give additional HTTP headers telling the server what you're uploading, and then it would give you a response.
"I don't want to live alone until I'm married" - M.M.R.P