Jump to content
xisto Community
Sign in to follow this  
tansqrx

Does Astahost Allow Http Put

Recommended Posts

Does Xisto allow http PUT requests. I am writting a program and I am looking for a quick simple way to transfer a file to Xisto. I would like to use PUT but I'm not sure if Xisto is allowing it. The directory that I am working with has world write access.If Xisto does allow PUT then how would one enable it?

Edited by miCRoSCoPiC^eaRthLinG (see edit history)

Share this post


Link to post
Share on other sites
http://www.apacheweek.com/features/put <---Blant definition of how to use the PUT method.

As far as Xisto goes to support it, I'm pretty sure it is allowed, but since my hostings been down for a god awful amount of time, I've forgotten where everything in Cpanel is.

However, if I remember correctly there should be a Icon that handles either cgi scripts, or scripts, or something along those lines.

Sorry if I'm wrong, ~Spaceh

Share this post


Link to post
Share on other sites

are you talking about the "put" command in Dreamweaver, if you are then it should support it. I use it all the time...if your having a problem with the command if your using dreamweaver check to make sure your permissions on the directory your putting to are correct.

Share this post


Link to post
Share on other sites

are you talking about the "put" command in Dreamweaver, if you are then it should support it.  I use it all the time...if your having a problem with the command if your using dreamweaver check to make sure your permissions on the directory your putting to are correct.

1064331944[/snapback]


I am talking about the HTTP header meathod PUT. http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html section 9.6. I need to quickly store a log file generated by a remote machine without the use of FTP.

Share this post


Link to post
Share on other sites

Here is the vb.NET code that I am using.

Public Sub PUT()		Dim httpRequest As HttpWebRequest		Dim httpResponse As HttpWebResponse		Dim responseStream As Stream		Dim responseEncoding As Encoding		Dim responseStreamReader As StreamReader		Dim strPostData As String = ""		Dim strResponse As String		strPostData = "hello"		Dim bPostData() As Byte = ascii.GetBytes(strPostData)		Try			httpRequest = CType(WebRequest.Create("http://mypage.astahost.com/put/test.txt"), HttpWebRequest)			httpRequest.Method = "PUT"			httpRequest.ContentType = "application/x-www-form-urlencoded"			httpRequest.ContentLength = bPostData.Length			Dim httpRequestStream As Stream = httpRequest.GetRequestStream()			httpRequestStream.Write(bPostData, 0, bPostData.Length)			httpRequestStream.Close()			httpResponse = CType(httpRequest.GetResponse(), HttpWebResponse)			responseStream = httpResponse.GetResponseStream()			responseEncoding = System.Text.Encoding.GetEncoding("utf-8")			responseStreamReader = New StreamReader(responseStream, responseEncoding)			Dim strHTTPReturnCode As String			strHTTPReturnCode = httpResponse.StatusDescription			If responseStreamReader Is Nothing Then				'if stream good then read it			Else				strResponse = responseStreamReader.ReadToEnd				'if the streams contains nothing then error				If strResponse = Nothing Then					'start extracting values				Else				End If			End If		Catch ex As WebException			If WebExceptionStatus.Timeout = WebExceptionStatus.Timeout Then			End If			MessageBox.Show(ex.Status.ToString)		End Try	End Sub


The problem is that when I check my cPanel logs, I am getting a 403 error from the server back. Any suggestions?

Share this post


Link to post
Share on other sites

You need to change mypage.astahost.com to whatever the name of your mypage is. If you set the permissions correctly then it should work. However, you're best waiting for OpaQue to tell you.

Share this post


Link to post
Share on other sites

I still want an answer to my HTTP PUT question but I think I have managed to find an alternative solution. The original need was to upload a file to Xisto via HTTP, FTP will not work for my application. For any of you out there interested this is what I came up with.

After poking around on the Net, I found that most people use CGI scripts to upload files to their web servers. I have never been that good at programming perl so I tried to stay away from this route as long as possible. I found several example scripts but none that fit my needs so I ended up converting one from The cgi-lib.pl Home Page [http://cgi-lib.berkeley.edu/ ]. Cgi-lib is actually a library used in many CGI scripts throughout the web. They have an upload file example using the cgi-lib package at http://cgi-lib.berkeley.edu/ex/perl5/fup.html and the original CGI source can be found at http://cgi-lib.berkeley.edu/ex/perl5/fup.cgi.txt. After modifying the perl code, I uploaded both cgi-lib.pl and fup.cgi to my cgi-bin directory on Xisto. Be sure to chmod fup.cgi to 755 otherwise you will get a 500 server error.

Below is my modified perl script. The biggest changes I made was to cut out most of the feedback messages, the ability to save the original file name, and the ability to save the file to a different directory. If you use this script be sure you change the $write_dir variable to the directory you want the files to be saved to.

#!/usr/local/bin/perl -Tw# Script adapted from cgi-lib.pl upload example#http://cgi-lib.berkeley.edu/ex/perl5/fup.html#added functionality to save original file name to disk and cut out alot of feedback## Copyright (c) 1996 Steven E. Brenner# $Id: fup.cgi,v 1.2 1996/03/30 01:33:46 brenner Exp $require 5.001;use strict;require "./cgi-lib.pl";MAIN: {  my (%cgi_data,  # The form data	  %cgi_cfn,   # The uploaded file(s) client-provided name(s)	  %cgi_ct,	# The uploaded file(s) content-type(s).  These are				  #   set by the user's browser and may be unreliable	  %cgi_sfn,   # The uploaded file(s) name(s) on the server (this machine)	  $ret,	   # Return value of the ReadParse call.	   	  $buf,		# Buffer for data read from disk.	  $write_dir,		  @arr_fields,	  $arr_size,	  $DOS_name	 );	   #This is the directory where the uploaded files will be stored     $write_dir = "../uploads/";  # When writing files, several options can be set..  # Spool the files to the /tmp directory  $cgi_lib::writefiles = $write_dir;      # Limit upload size to avoid using too much memory  $cgi_lib::maxdata = 50000;   # Start off by reading and parsing the data.  Save the return value.  # Pass references to retreive the data, the filenames, and the content-type  $ret = &ReadParse(\%cgi_data,\%cgi_cfn,\%cgi_ct,\%cgi_sfn);  # A bit of error checking never hurt anyone  if (!defined $ret) {	&CgiDie("Error in reading and parsing of CGI input");  } elsif (!$ret) {	&CgiDie("Missing parameters");  } elsif (!defined $cgi_data{'upfile'} or !defined $cgi_data{'note'}) {	&CgiDie("Data missing");  }  # Now print the page for the user to see...  print &PrintHeader;  print &HtmlTop("Upload Successful");   # Split original name string, assumes Windows full path format  @arr_fields = split(/\\/,$cgi_cfn{'upfile'});    # Find the last element number  $arr_size = @arr_fields-1;    # The original name we are after  $DOS_name = $arr_fields[$arr_size];  # Rename to the original name  rename $cgi_sfn{'upfile'},$write_dir . $DOS_name; print &HtmlBot;  # The following lines are solely to suppress 'only used once' warnings  $cgi_lib::writefiles = $cgi_lib::writefiles;  $cgi_lib::maxdata	= $cgi_lib::maxdata;}
After finishing the script I wrote a small VB.NET subroutine to automatically take advantage of the new script. The sub takes two inputs, strServer and strFileName. The strServer variable is the URL to the cgi-bin directory on your Xisto webserver. A possible value would be http://forums.xisto.com/no_longer_exists/. The strFileName variable is the full path to the local system file that you would like to upload. A possible value to this would be âc:\my_file.txtâ. The application uses a HttpWebRequest with the content-type set to âmultipart/form-dataâ. Getting the multipart code was very tricky so if you need to modify it then refer to http://www.dotnet247.com/. Below is the sub used to upload a file.

Public Sub CGI(ByVal strServer As String, ByVal strFileName As String)		Dim httpRequest As HttpWebRequest		Dim httpResponse As HttpWebResponse		Dim strPostData As String = ""		Dim strBoundaryID As String = "--xxxformboundryxxx"		strPostData += strBoundaryID + vbCrLf		strPostData += "Content-Disposition: form-data; name=""upfile""; filename="""		strPostData += strFileName		strPostData += """" + vbCrLf		'simple case, should be other for exe		strPostData += "Content-Type: text/plain" + vbCrLf + vbCrLf		'open data file and then read it into the stream		Dim fStream As New FileStream(strFileName, FileMode.Open, FileAccess.Read)		Dim fStreamReader As New StreamReader(fStream)		Do Until fStreamReader.Peek = -1			strPostData += fStreamReader.ReadLine + vbCrLf		Loop		strPostData += strBoundaryID + vbCrLf		strPostData += "Content-Disposition: form-data; name=""note""" + vbCrLf + vbCrLf + vbCrLf		strPostData += strBoundaryID + "--" + vbCrLf		Dim bPostData() As Byte = ascii.GetBytes(strPostData)		Try			httpRequest = CType(WebRequest.Create(strServer), HttpWebRequest)			httpRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"			httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"			httpRequest.Method = "POST"			httpRequest.ContentType = "multipart/form-data; boundary=xxxformboundryxxx"			httpRequest.ContentLength = bPostData.Length			Dim httpRequestStream As Stream = httpRequest.GetRequestStream()			httpRequestStream.Write(bPostData, 0, bPostData.Length)			httpRequestStream.Flush()			httpRequestStream.Close()			httpResponse = CType(httpRequest.GetResponse(), HttpWebResponse)		Catch ex As WebException			If WebExceptionStatus.Timeout = WebExceptionStatus.Timeout Then			End If			MessageBox.Show(ex.Status.ToString)		End Try	End Sub

The entire project can be found at http://forums.xisto.com/no_longer_exists/. The project was written in VB.NET 2005.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.