0

I have a classic asp page in VBS and I am trying to create a file on the web server with the following code.

Set fso = CreateObject("Scripting.FileSystemObject")
Set file1 = fso.CreateTextFile("\\localhost\inetpub\wwwroot\cs\batch\123456dirs.bat", true)

This returns the following error:

|666|800a0034|Bad_file_name_or_number

Line 666 is the CreateTextFile line.

According to the Microsoft docs, this means that I'm trying to create a file with an invalid filename. Then it explains the rules for filenames and mine appears to be perfectly valid.

Any suggestions or ideas on how I can further troubleshoot this?

Anonymous Man
  • 2,776
  • 5
  • 19
  • 38
  • The createtextfile function runs on the web server but in the context of the local server itself. Any path you give it must resolve as if you were logged on to a windows desktop on the server and tried to CD to that path. Unless you created a – Vanquished Wombat Jul 29 '17 at 17:34

2 Answers2

1

first thing to check to make sure your users have access to the folder. Assuming you're not using windows authentication, make sure IUSR account has write access to the folder.

second, unless inetpub is set up as a share to folder, you're syntax won't work. if the root of your website is located in the CS folder, you can do something like:

Set file1 = fso.CreateTextFile(Server.MapPath( "/cs/batch/123456dirs.bat" ), true)
Josh Montgomery
  • 882
  • 5
  • 10
0

The createtextfile() function runs on the web server but in the context of the local server itself. Simply put, any path you give it must resolve as if you were logged on to a windows desktop on the server and tried to CD to that path.

The format \localhost... is a UNC path. See this question for a discussion about UNC paths and windows. Unless you know for sure that there is a UNC path mapped for \localhost then that is probably your issue. You may be making the assumption the \localhost will be a reasonable path to use, but as I said unless you know for sure it is available then this is an invalid choice.

Lastly, if you decide to set up a share for \localhost, you will be getting in to some interesting territory around the user context that the web server operates in. You see you will have to set up the share for the IIS user that is configured as the run-as identity for IIS, so you will need to know that and create the required config to give that user the share.

If it were me, I would switch to using a standard windows path, although even then you need to appreciate the run-as user context and security config, etc.

Vanquished Wombat
  • 9,075
  • 5
  • 28
  • 67