take hostname, look if folder exsist, if not create and copy files

P

Paw

Greetings.
I use asp.
what I need is is when a visitor comes to the site, I need it to check
the host name. if "www.hometowndigest.com" is the host, then check a
folder named "something" and if the folder does not exsist, create
folder "www" and then copy folder "temp" and its contents.

If the folder "www" is there, look in it, check to see if the files in
folder "temp" are in there, if not, copy the files that are not from
folder "temp" into folder "www".


If instead of www.hometowndigest.com, it is
"vbscript.hometowndigest.com", I need it to do the same rountine. What
ever the subdomain name.


This file will be be drawn as an include file.


NOTE:


1. I do not need it to look in folder "Temp/www" or folder
"temp/vbscript", etc, only folder "temp"
2. Please note further includes along the way in the file will run
script. So, if it could not interfer with those by some kind of
statement.
3. if the host is "hometowndigest.com", or "tn-ol.com", etc, anything,
do nothing.
4. If the script cannot or would be too consuming of time or resources,

maybe i can manually add a listing of the files to look for in the
script through


Thanks in advance.
Paw.
 
M

Mike Brind

Paw said:
Greetings.
I use asp.
what I need is is when a visitor comes to the site, I need it to check
the host name. if "www.hometowndigest.com" is the host, then check a
folder named "something" and if the folder does not exsist, create
folder "www" and then copy folder "temp" and its contents.

If the folder "www" is there, look in it, check to see if the files in
folder "temp" are in there, if not, copy the files that are not from
folder "temp" into folder "www".


If instead of www.hometowndigest.com, it is
"vbscript.hometowndigest.com", I need it to do the same rountine. What
ever the subdomain name.


This file will be be drawn as an include file.


NOTE:


1. I do not need it to look in folder "Temp/www" or folder
"temp/vbscript", etc, only folder "temp"
2. Please note further includes along the way in the file will run
script. So, if it could not interfer with those by some kind of
statement.
3. if the host is "hometowndigest.com", or "tn-ol.com", etc, anything,
do nothing.
4. If the script cannot or would be too consuming of time or resources,

maybe i can manually add a listing of the files to look for in the
script through


Thanks in advance.
Paw.

So what is your question? Which bit are you having difficulty with?
 
P

Paw

Thank You for your response.
here is the code I have so far. Not working though. Paul Chambers

<%

'+--------------------------------------------------------------+
'| FOLDERS |
'+--------------------------------------------------------------+

DIM ROOT_PATH : ROOT_PATH = server.MapPath(".")
Dim LOCAL_FOLDER : = Root_path & "\local"

LOCAL_FOLDER = LOCAL_FOLDER & "\" &
mid(Request.ServerVariables("SERVER_NAME"),1 ,instr(1,
Request.ServerVariables("SERVER_NAME"), ".")-1)


'+--------------------------------------------------------------+
'| LOCAL CREATED FILES PATH |
'+--------------------------------------------------------------+
DIM SUB_PATH : SUBL_PATH = ROOT_PATH & LOCAL_PATH & "\default.asp"
DIM OTHERL_PATH : OTHERL_PATH = ROOT_PATH & LOCAL_FOLDER & "\user.asp"




%>

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">



'========================================
'---- Checks if the Sub files exist ----
'========================================
' if not copy from the default one
'========================================
'transform that as jscript
Sub CheckAllFiles()
Dim sText
Dim objFSO : Set objFSO =
server.CreateObject("scripting.Filesystemobject")
Dim objFile
Dim arrFolders
Dim arrFiles
Dim i

'We create missing folders
arrFolders = array(LOCAL_FOLDER)
for i=0 to uBound(arrFolders)
If not objFSO.FolderExists(arrFolders(i)) Then
objFSO.CreateFolder(arrFolders(i))
End if
next

'We create missing files
If NOT objFSO.FileExists(SUB_PATH) Then
Set objFile = objFSO.OpenTextFile(ROOT_PATH &
"\secure\master\default.asp", 1)
sText = objFile.ReadAll
Set objFile = nothing

Set objFile = objFSO.CreateTextFile(SUB_PATH, True)
Call objFile.Write(sText)
Set objFile = nothing
End If

If NOT objFSO.FileExists(OTHERL_PATH) Then
Set objFile = objFSO.OpenTextFile(ROOT_PATH & "\secure\master\user.asp",
1)
sText = objFile.ReadAll
Set objFile = nothing

Set objFile = objFSO.CreateTextFile(OTHERL_PATH, True)
Call objFile.Write(sText)
Set objFile = nothing
End If


Set objFSO = nothing

if err<>0 then
err.Clear
Response.Write "<font face=arial><b>Warning :</b> To complete
installation of this SubDomain, you must give write permission to the
database and media directories (under IIS console, and explorer if you use
NTFS).</font>"
Response.End
end if

End Sub


</SCRIPT>



<SCRIPT LANGUAGE="JScript" RUNAT="Server">

//==================================================
// call the vbscrip function with an error trapping
//==================================================
function JSCheckAllFiles()
{
try
{
CheckAllFiles();
}
catch(e) {
Response.Write("<font face=arial><b>Warning :</b> To complete
installation, you must give write permission to the database and media
directories (under IIS console, and explorer if you use NTFS).</font><br>");
return false;
}
}

//==================================================
// Save an SUB file with FSO
//==================================================
function SavesubFile(sFileName, sContent)
{
var objFSO, objFile;

try
{
objFSO = new ActiveXObject("Scripting.FileSystemObject");
objFile = objFSO.CreateTextFile(sFileName, true, true);

}
catch(e) {
Response.AppendToLog("SavesubFile " + e);
Response.Write("<font face=arial><b>Warning :</b> To complete
installation, you must install VBScript runtime version 5.6.</font><br>");
return false;
}


try
{
objFile.Write(sContent);
objFile.close();
}
catch(e) {
Response.AppendToLog("SavesubFile " + e);
Response.Write("<font face=arial><b>Warning :</b> Can't save xml file.
Check the write permission.</font><br>");
//objFile = objFSO.CreateTextFile(sFileName + "." + GetGuid(6), true,
true);
//objFile.Write(sContent);
//objFile.close();
return false;
}

//Response.Write(sFileName + " is updated.<br/>");
}

</SCRIPT>
 
M

Mike Brind

1. How do you define "not work"?
2. Where have you put your response.write statements to check that the
values you expect are actually there?
3. Where are they failing?
4. What error messages do you get, if any?
 
P

Paw

1. How do you define "not work"?

I get server 500 error message., files are not being written.

2. Where have you put your response.write statements to check that the
values you expect are actually there?

The code in the last post is the code I have. If not there, I didn't. I
know the folders and files are there with correct permissions.

3. Where are they failing?

Not sure.

4. What error messages do you get, if any?
Don't have access to my server logs.

I did see one typo in the code, I fixed it. Is it ok to attach a txt file to
the post of the code?

Thank you, Paul Chambers
 
M

Mike Brind

What is the server 500 message and which line does it refer to?

--
Mike Brind
1. How do you define "not work"?

I get server 500 error message., files are not being written.

2. Where have you put your response.write statements to check that the
values you expect are actually there?

The code in the last post is the code I have. If not there, I didn't. I
know the folders and files are there with correct permissions.

3. Where are they failing?

Not sure.

4. What error messages do you get, if any?
Don't have access to my server logs.

I did see one typo in the code, I fixed it. Is it ok to attach a txt file to
the post of the code?

Thank you, Paul Chambers
 
P

Paw

Thanks for you help, Mike. The last post you sent made me think to stop and
start over, which I did. I came up with some code that will work.

I have inserted it below.

Basically, for any whose interested, I give am getting ready to give away
blogging sites, with upgradable features for a small cost. I needed away to
setup up the new users without cost or labor by our team, except for after
setup tech supports and upgrades. My team as well as myself are all
disabled, web enabled. So lower costs are important. We are wildcarding
several domains to widen our reach. Tn-ol.com, hometowndigest.com,
thatinternetplace.com.

I have a package of asp scipts for the new users. Just needed a scalable
deployment system.

So to close, I just needed to create new folders based on subdomain, and
then copy a template folder. This is generic. I will implement it into my
secure pages until I start from scratch.

Below is the code.

I haven't done coding in years, and forgot alot. But its coming back to me.
If you could guide me in one more way, I would appreciate it. It probably is
novice but I can't seem to remember it all yet.

I would like to run more script from the setup page. what would the script
setup be for doing the next routine after this one. In the code below,
instead of "bye", "I would like to say and "now I am doing something else,
hold on " run the next script and so on until the final.

Have a good day..
Paul Chambers

'start code-----

Hello. I am creating client folders <br>
please Stand By while I create your folders and files.<br><img
src=status.gif><br>

<%
dim fs,fo
SUBDONO=""
SUBDOYES=mid(Request.ServerVariables("SERVER_NAME"),1 ,instr(1,
Request.ServerVariables("SERVER_NAME"), ".")-1)

if inStr (SUBDOYES,SUBDONO)=1 then
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("put path to template folder in the form of
E:\something\template")
fo.Copy("D:\something\client\files\" & SUBDOYES)
set fo=nothing
set fs=nothing
else
end if
%>
ok, I am done. Bye.


'end code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top