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

ftp upload script 1

Status
Not open for further replies.

techskool

Technical User
Jun 20, 2002
151
GB
Does anyone have an example of an ftp upload script, that i can send files from a my client, via a browser, to my folder on the server.

I cannot use binary upload, as i do not have permissions access to the folder i am uploading to, only ftp access.

Many Thanks

Dave

 
I can not upload with just asp to the folder on the server.

It does NOT have write permissions.

I have a few working pure asp scripts, but they only work on my local machine.

Please, Please, Please does ANYONE know how i can write an ftp script.

I assume i can only upload this way, using my login and password, so i assume there must be ascript i can use, with these details, to allow me to move a file from my c:\ drive local, via a browser, to the folderon a server.

Please help this is absolutely urgent.

Ive spent a week on this now and am flummoxed.

Thanx

Dave
 
Listen... how can you expect to be able to write to a folder when you do not have write permission in this folder??

Sorry, but I cant see how this is possible.

Good luck
 
I just thought, if its possible for me to ftp to a folder that does not have write permissions, then i must be able to write an ftp script, to emulate the way i upload with Dreamweaver.

??


Thanks again

Dave

 
This is what I am saying... you are answering your own question...

Think about this, how would it be possible to write in a folder that does not have write permission..???
(because ftp in a folder is obviously writting data to this folder.. regardless what you are actually ftping in it. You actually "write" inside this folder.)
So once again, unless I am completely misunderstanding your question, you cannot obviously "write" in a folder when this folder does not have "write" permission... the same way that you cannot "read" in a folder when this folder does not have "read" permission...

Hope this help you.

Greetings
 
Re-reading your post, if you could uplaod by ftp to the folder, is this folder within the webserver folder?? If yes then you should be able to upload using pure asp script, if not then you wont never be able to use a script, but only be able via your ftp account,
Example, if you have access to your IIS account on the server and the directory is like this
yourAccount/htdocs/<webfiles>

Than the only folder that will accept web request here will be in the htdocs files.
Or to make it clearer, take exemple on your own IIS server (locally) you have inetpub/ asp upload will work if the script is run from within the folder, from there if you want to upload your files in the inetpub folder than simply specify it inside the script and you will be able to acheive what you want. But you must run you upload script from the folder or whatever the web folder server name is. And if your account has access to some parent folder on the server account than you specify where you want to upload it inside one of those folder in your script and it will work.

Hope this is clearer.
Greetings
 
I am not at home at the moment, but i will look into it when i get home in the next hour.

I can ftp, so as you say the folder must have write permissions, however, when i use pure asp upload, the message i get is, cannot upload file, permmission denied.

Thanks again

Dave
 
Right, the exact message i get when testing to upload the root folder on the server is:

Upload files to your server
Folder c:\inetpub\ does not have write permissions.
The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions.
After you correct this problem, reload the page.

Powered by Free ASP Upload

uploadsDirVar is set to the root of my site.

Seeing this would make me think im not goin to be able to do uploads.....how the heck does ftp work then??????

Thanks

Dave
 
I think ive got this now.

I need to include my login details in the script, to enable write permissions on the fly, as they arent set without login details.

I found a script:

I can see the logic, but can anyone see how i point it to a file i select on my local machine, and how to initialise it, it apperas to be set to look for a file to ftp in the directory in which the script resides??

********************************************
<%@ Language=VBScript %>
<%
Dim objFSO, objTextFile, oScript, oScriptNet, oFileSys, oFile, strCMD, strTempFile, strCommandResult
Dim ftp_address, ftp_username, ftp_password, ftp_physical_path, ftp_files_to_put

' Edit these variables to match your specifications
ftp_address = &quot;ftp.server.com&quot;
ftp_username = &quot;username&quot;
ftp_password = &quot;password&quot;
ftp_remote_directory = &quot;subdirectory&quot; ' Leave blank if uploading to root directory
ftp_files_to_put = &quot;file.txt&quot;

On Error Resume Next
Set oScript = Server.CreateObject(&quot;WSCRIPT.SHELL&quot;)
Set oFileSys = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
' Build our ftp-commands file
Set objTextFile = objFSO.CreateTextFile(Server.MapPath(&quot;test.ftp&quot;))
objTextFile.WriteLine &quot;lcd &quot; & Server.MapPath(&quot;.&quot;)
objTextFile.WriteLine &quot;open &quot; & ftp_address
objTextFile.WriteLine ftp_username
objTextFile.WriteLine ftp_password

' Check to see if we need to issue a 'cd' command
If ftp_remote_directory <> &quot;&quot; Then
objTextFile.WriteLine &quot;cd &quot; & ftp_remote_directory
End If

objTextFile.WriteLine &quot;prompt&quot;

' If the file(s) is/are binary (i.e. .jpg, .mdb, etc..), uncomment the following line' objTextFile.WriteLine &quot;binary&quot;
' If there are multiple files to put, we need to use the command 'mput', instead of 'put'
If Instr(1, ftp_files_to_put, &quot;*&quot;,1) Then
objTextFile.WriteLine &quot;mput &quot; & ftp_files_to_put
Else
objTextFile.WriteLine &quot;put &quot; & ftp_files_to_put
End If
objTextFile.WriteLine &quot;bye&quot;
objTextFile.Close
Set objTextFile = Nothing
' Use cmd.exe to run ftp.exe, parsing our newly created command file
strCMD = &quot;ftp.exe -s:&quot; & Server.MapPath(&quot;test.ftp&quot;)
strTempFile = &quot;C:\&quot; & oFileSys.GetTempName( )
' Pipe output from cmd.exe to a temporary file (Not :| Steve)
Call oScript.Run (&quot;cmd.exe /c &quot; & strCMD & &quot; > &quot; & strTempFile, 0, True)
Set oFile = oFileSys.OpenTextFile (strTempFile, 1, False, 0)

On Error Resume Next
' Grab output from temporary file
strCommandResult = Server.HTMLEncode( oFile.ReadAll )
oFile.Close
' Delete the temporary & ftp-command files
Call oFileSys.DeleteFile( strTempFile, True )
Call objFSO.DeleteFile( Server.MapPath(&quot;test.ftp&quot;), True )
Set oFileSys = Nothing
Set objFSO = Nothing
' Print result of FTP session to screen
Response.Write( Replace( strCommandResult, vbCrLf, &quot;<br>&quot;, 1, -1, 1) )
%>
*********************************************

Thanks again

Dave
 
&quot;Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions&quot;

What is in the uploadTester.asp page? Do you have &quot;c:\inetpub\ hardcoded?? If yes than for sure it will not work. You need to put your webserver directory there.. something like Server.MapPath(./myfolder)....

Let me know
 
Thanx for all the help REK2

Im sorted, kind of...

The scripts all work but....

thread333-553545
 
Hum.. I think you are getting the things more complex than they are here...

Tell me what's you ftp folder name in your account and what is the webfolder name also, and also where you wish to uplaod you're files. I will then help you out.

Also, did you change the variable value in the asp pure uplaod script to match this webserver folder?

Cheers
 
ftp://
reco711554 is the account (username) and also the root folder, within which i have folders: databases, logs and www.

The thing is REK2, i have a working script, but it wont upload cos it says i dont have folder permissions.

I use a script i found, perms.asp (below) which enables me to have write permissions, by letting me log in as i would do in an ftp connection, at this point the folder can be uploaded to, but never without this script.

All my scripts now work, i just dont want to have to enter the username and password, everytime i upload through my browser. The combination of a pure asp script i found a few days ago, and the perms.asp file let me do what i want, its just a bit messy

Thanx again for all your effort

Dave


perms.asp
------------------------------
<%
option explicit
'' on error resume next

dim url
url = Request.ServerVariables(&quot;SCRIPT_NAME&quot;)

dim logon
logon = Request.ServerVariables(&quot;LOGON_USER&quot;)

dim Folder
Folder = Request(&quot;Folder&quot;)


'' give us a 15-minute timeout, just in case we need it. The default is only like 90 seconds, and cacls can take a while...
Server.ScriptTimeOut = 900


if (logon = &quot;&quot;) then

if (Request(&quot;auth&quot;) <> &quot;&quot;) then


Response.Status = &quot;401 Authorization Required&quot;

%>

<P>This script just sent a &quot;401 Authorization Required&quot; challenge. Your browser should have prompted you for a username and password, and then let you through.</P>

<P>If you did not see a challenge for username and password *, that means that this web site is not configured for user authentication.</P>

<P>Have the administrator (or you, if you can do it) visit the Internet Information Server MMC, select this web site, select &quot;Properties&quot;, then &quot;Directory Security&quot;, then &quot;Anonymous Access and Authentication Control&quot;, and then to select one or more authentication packages, preferably &quot;Basic&quot;. Basic authentication is the only one that will work if your have a non-IE browser.</P>

<P>* A proper challenge looks something like <A HREF=&quot;

<%

Response.End

else

Response.Write(&quot;<P>You are not currently logged in to this web page with an NT account.</P>&quot;)

end if

else

Response.Write(&quot;<P>You are logged in as '&quot; & logon & &quot;'.</P>&quot;)

end if



%>

<P>[ <A HREF=&quot;<% = url %>&quot;>Refresh</A> ]</P>

<% if (logon = &quot;&quot;) then %>

<P><B>Step 1: </B><A HREF=&quot;<% = url %>?auth=1&quot;>Test Authentication</A></P>

<% elseif (Folder = &quot;&quot;) then %>

<%

dim ScriptPath

ScriptPath = Server.MapPath(url)

'' remove everything after the final &quot;\&quot;

dim X
X = instrrev(ScriptPath, &quot;\&quot;)

Folder = Mid(ScriptPath, 1, X - 1)

%>

<FORM METHOD=get ACTION=&quot;<% = url %>&quot;>
<TABLE BORDER=1>
<TR>
<TD ALIGN=right VALIGN=top>Script name:</TD>
<TD><% = url %></TD>
</TR><TR>
<TD ALIGN=right VALIGN=top>Script path:</TD>
<TD><% = ScriptPath %></TD>
</TR><TR>
<TD ALIGN=right VALIGN=top>Folder:</TD>
<TD><% = Folder %></TD>
</TR><TR>
<TD ALIGN=right VALIGN=top>Current Permissions:</TD>
<TD><PRE><% = Run(&quot;cacls &quot;&quot;&quot; & Folder & &quot;&quot;&quot; /C&quot;) %></PRE></TD>
</TR><TR>
<TD><BR></TD>
<TD><INPUT TYPE=submit VALUE=&quot;Make Writable&quot;></TD>
</TR>
</TABLE>
<INPUT TYPE=hidden NAME=&quot;Folder&quot; VALUE=&quot;<% = Folder %>&quot;>
</FORM>

<%
else


%><P>Attempting to make the folder &quot;<% = Folder %>&quot; writable...</P><%

dim command
command = &quot;cacls &quot;&quot;&quot; & Folder & &quot;&quot;&quot; /E /G Everyone:C /C /T&quot;

%>

<P>Executing command:</P>
<BLOCKQUOTE>
<PRE><FONT COLOR=#ff0000><% = Server.HTMLEncode(command) %></FONT></PRE>
</BLOCKQUOTE>

<P>Command response:</P>
<BLOCKQUOTE>
<PRE><FONT COLOR=#ff0000><% = Server.HTMLEncode(Run(command)) %></FONT></PRE>
</BLOCKQUOTE>

<TABLE BORDER=1>
<TR>
<TD ALIGN=right VALIGN=top>Folder:</TD>
<TD><% = Folder %></TD>
</TR><TR>
<TD ALIGN=right VALIGN=top>Current Permissions:</TD>
<TD><PRE><% = Run(&quot;cacls &quot;&quot;&quot; & Folder & &quot;&quot;&quot; /C&quot;) %></PRE></TD>
</TR>
</TABLE>
<%

end if




'' Executes the command given, and returns stdout and stderr as string:
function Run (command)
dim oShell, oFileSystem, strTempFile, strCommand
set oFileSystem = CreateObject(&quot;Scripting.FileSystemObject&quot;)
if (Err.Number) then
Run = &quot;Error creating object Scripting.FileSystemObject - &quot; & Err.Number & &quot; - &quot; & Err.Description
exit function
end if
strTempFile = oFileSystem.GetSpecialFolder(2) & &quot;\&quot; & oFileSystem.GetTempName()
set oShell = CreateObject(&quot;WScript.Shell&quot;)
if (Err.Number) then
Run = &quot;Error creating object WScript.Shell - &quot; & Err.Number & &quot; - &quot; & Err.Description
exit function
end if
strCommand = &quot;CMD /C &quot;&quot;&quot; & command & &quot; 1> &quot; & strTempFile & &quot; 2>&1&quot;&quot;&quot;
call oShell.Run(strCommand, 1, true)
if (oFileSystem.FileExists(strTempFile)) then
dim oFile
set oFile = oFileSystem.GetFile(strTempFile)
if (oFile.Size) then
dim oText
set oText = oFileSystem.OpenTextFile(strTempFile, 1, false)
Run = oText.ReadAll
oText.Close
set oText = nothing
else
Run = &quot;Failed to redirect command output.&quot;
end if
set oFile = nothing
else
Run = &quot;Failed to redirect command output.&quot;
end if
set oFileSystem = nothing
set oShell = nothing
end function
%>



<P><HR SIZE=1></P>

<P>This is an ASP page, written in vbscript, that will attempt to set NTFS directory permissions on the folder that this script is in. The permissions will extend to all subfolders and files.</P>

<P>The folder will be made world-writable by granting the &quot;Everyone&quot; group the &quot;Change&quot; permission. ACLs on files and folders are edited, not overwritten.</P>

<P><B>Dependencies</B></P>
<UL>
<LI> Windows NT or 2000 operating system running on server
<LI> Microsoft IIS web server software (current server software is <% = Request.ServerVariables(&quot;SERVER_SOFTWARE&quot;) %>)
<LI> IIS configured to allow User Authentication
<LI> NTFS file system
<LI> WScript.Shell and Script.FileSystemObject COM objects, which are installed by default on Windows with the Windows Scripting Host
<LI> the cacls program, provided with Windows NT/2000 by default
</UL>
<P><HR SIZE=1></P>

<P><B>Instructions for Use</B></P>
<OL>
<LI> Place this ASP file into a folder whose permissions you want to set
<LI> Request this file using a web browser
</OL>

<P>Copyright &copy; 2000, <A HREF=&quot; Milosevic</A>, All Rights Reserved</P>
<P><HR SIZE=1></P>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top