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

Writing a TXT file on a server - simple question! 1

Status
Not open for further replies.

fillup07

Vendor
Apr 1, 2002
62
US
Alright, I need to know how to write to a simple .txt file on the server. I tried using this code:
<%
Set FS=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set RS=FS.OpenTextFile(Server.MapPath (&quot;counter.txt&quot;), 1, False)
fcount=RS.ReadLine
RS.Close
fcount=fcount+1
Set RS=FS.OpenTextFile(Server.MapPath(&quot;counter.txt&quot;), 2, False)
RS.Write fcount
RS.Close
Set RS=Nothing
Set FS=Nothing
%>
<p>This page has been visited <%=fcount%>
times.</p>

To make a hit counter, but I get this error:
Microsoft VBScript runtime error '800a0046'
Permission denied
/asp/philly/counter.asp, line 9

Line 9 is:
Set RS=FS.OpenTextFile(Server.MapPath(&quot;counter.txt&quot;), 2, False)

Now, you may be thinking &quot;it's just his server, there's nothing he can do, because his server doesn't allow anythign to write to it&quot;. I know this isn't true because I made a guestbook using Frontpage and the webbot thing. So, I know I can write to the server.... I just can't figure out how to do it in ASP!

HELPPPP me please!!

fillup07@hotmail.com -Phil
fillup07@hotmail.com
 
It probably is a server setting. Frontpage knows who you are and sets permissions appropiately. If you hit an asp page(unless NT chalenge response is used for authentication) , IIS uses the IUSR_machinename as the user for that web page. Therefore this user must have permissions set appropiately to allow him to write to the server.
 
But how would that make sense... because I CAN write to the server when it's using Frontpage's little guestbook webbot thing, but when I use ASP (I included my code in the original post) to try to write to a txt file I get permission denied. -Phil
fillup07@hotmail.com
 
Front page sets its own permissions while asp does not. If you are creating asp pages(not using frontpage) then you have to set the permissions. Go to the folder you are writing to and give the IUSER_machinename write permissions. I bet your problem goes away.
 
But I AM using Frontpage to make the ASP page.

For the webbot thing, I just went into form properties and made it save the results to a txt file.

For the ASP (which I made in Frontpage as well) I can't get it to save to a text file.

-Phil
fillup07@hotmail.com
 
Oh, and you said &quot;Go to the folder you are writing to and give the IUSER_machinename write permissions.&quot;.

How would I do that?
The server, when I try to use CHMOD, says that we don't have access to change permissions. -Phil
fillup07@hotmail.com
 
I don't know if you've figured out the problem yet, but I'll help anyway.

I'm not sure how your changing permissions, but I was able to get it working pretty quick. I First off created an asp with your code, then created the counter.txt with read, write and script source access, using the IIS mmc, then I went into actual folder that these two files were located and gave them both read and write access to everybody. I don't know how secure you want to keep it, but I think you have the right Idea about the IUSER_**** Permissions. Anyways that's it. (I used Frontpage also, and it didn't work until I changed permissions manually).

Very handy asp might I ad.
If you have any questions
Lostboy3@pacbell.net
 
Thanks for your reply - I have not fixed it yet.

About changing permissions, how can I do that? When I right click the file or folder on the server and go into properties, Windows says that I can't change it on the server. Even when I go into SmartFTP and try to save permissions, it doesn't change anything. Is there some type of code I have to use in the ASP page that I'm not? Or is there some other way of changing permissions that would actually work for me? -Phil
fillup07@hotmail.com
 
Well, look for yourself...


The code it makes is:
<form action=&quot;--WEBBOT-SELF--&quot; method=&quot;POST&quot;><!--webbot bot=&quot;SaveResults&quot; startspan U-File=&quot;guestlog.htm&quot; S-Format=&quot;HTML/DL&quot; S-Label-Fields=&quot;TRUE&quot; S-Builtin-Fields=&quot;Date Time REMOTE_USER&quot; S-Form-Fields --><input TYPE=&quot;hidden&quot; NAME=&quot;VTI-GROUP&quot; VALUE=&quot;0&quot;><!--webbot bot=&quot;SaveResults&quot; endspan -->

When you submit a new comment (feel free to play with it if you want) it brings you to this page:

I don't understand how the /_vti_bin/shtml.dll/ part gets in there, and I can't even view a &quot;_vti_bin&quot; directory on the server...


Note: This Frontpage thing I made saves the results to an HTML file - guestlog.htm instead of a TXT File. If that makes any difference, and if you know how to make ASP save to an HTML file (but not TXT) be my guest and let me know. -Phil
fillup07@hotmail.com
 
Do you have permission To change Permissions? This is a good question to start with. You may need to be an administrator or have administrative rights on your domain as well as on that computer. To find out is to visit the control panel/users and passwords sections or under the startbar under administrative tools. If so all you should have to do I right click on the folder or file and there should be a security tab. There are also a lot of security programs out there you can use to change security, Try different methods. Use the WIn2k or NT40 tek-tips section, to figure out different ways of hacking your folders and files.
A good place to look is Or look for Security Explorer and see if you can download a demo version or something. One time use is all you really need right?

Blixx
I=PRT
 
A quesion. How are you creating your pages, Manually or through Frontpage? I create my pages manually (meaning I create a text file inside the folder enter the code then change the extension), this may also help with permissions in the fact that you are creating the text file so therefore you have ownership of the text file.

Blixx
I=PRT
 
Blixx,

I don't really have permission to change permissions. I'd like to work with what I have (no permission to change permissions) before I go hunting down my hosting company.

I create my ASP pages through Frontpage, and then save the file as an ASP file most of the time. Does it really matter though? I mean, the HTML ends up being the same... why would it be different if I just used the same code and then changed the extension (without Frontpage) if it ends up the same? -Phil
fillup07@hotmail.com
 
As sarkman was saying earlier Frontpage creates funky permissions and I've notice that most all of the files that I create are read only by default.

Security Explorer Undermines a lot of the NT Security, You can still get permission even if you don't have permission.
 
So are you saying that if I don't use Frontpage to make my ASP page to write to a TXT or HTML file that it will work different then if I were to just open Notepad, write my code, and save it as an ASP file and upload it? -Phil
fillup07@hotmail.com
 
Okay, I was wrong. I tested my method They are the exact same, but I also noticed while I was doing it. The files have different Permissions when created in different folders, Which means that either permissions on the folder that your creating your files in, has read only permissions (propagating). Or the server your uploading to, has read only permissions that are propagating to all desending files and folders (which would make a lot of sense trying to keep the server secure). If the latter is true then you will have to contact your administrator.

Blixx
I=PRT
 
What I don't understand is how can Frontpage make the webbot file actually save to a text file when I cannot? The permissions are the same (as far as I know... I mean, I noone changed any of them) for all the files and folders.. so unless Frontpage did something automatically, I dont get it. And if it did, can't I recreate whatever it did? -Phil
fillup07@hotmail.com
 
The Problem with Front Page is, you really don't know what's going on with the coding or anything else. It's mostly wysiwyg, and it has the ability to use files such as shtml.dll. I don't know what shtml.dll handles, but I can guess that it's part of the puzzle. Why don't you try editing your code if you get my drift. add your txt code inside the Guestbook. save it as something else or run it with your guestbook and then run it, if it works you will then have at least a working page.
Delete The Guestbook coding little by little see if anything changes. If nothing changes you have a complete working file. If it does change then don't delete that portion of code and maybe you'll have your answer.

Blixx
I=prt
 
Blixx, thanks a lot. I'll try that I guess. How do I mark your posts as helpful?

If anyone can think of ANY other POSSIBILITY that would be great...

-Phil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top