Wrox Home  
 
Search P2P Archive for  go

More Wrox Resources

  Return to Index  

asp_web_howto thread: FTP


Message #1 by "O'Hara, Elliott M" <EMOHARA@k...> on Thu, 31 Jan 2002 08:47:19 -0500
Hey all,

2 or 3 weeks ago someone posted a page with an example of FTPing through asp

without any third party software. It was really good- problem is.. the web

site is now down!!!

Did anyone happen to copy that? Or better yet- if your still here (you

genius) could you post it again???



Thanks,

the nasa geek

Message #2 by Nikos <pappas@c...> on Thu, 31 Jan 2002 16:27:12 +0200
--=====================_81270000==_.ALT

Content-Type: text/plain; charset="iso-8859-1"; format=flowed

Content-Transfer-Encoding: quoted-printable



Hi Elliot

If this is what you want

Thanks to http://www.Benmeg.com

Great work

=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC

=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC

<%@ Language=3DVBScript %>

<%

' FTP via ASP without using 3rd-party components

' Ben Meghreblian 15th Jan 2002

' benmeg at benmeg dot com / http://benmeg.com

'

' This script assumes the file to be FTP'ed is in the same directory as

this script.

' It should be obvious how to change this (*hint* change the lcd line)

' You may specify a wildcard in ftp_files_to_put (e.g. *.txt)

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          =3D "ftp.server.com"

ftp_username         =3D "username"

ftp_password         =3D "password"

ftp_remote_directory =3D "subdirectory" ' Leave blank if uploading to root



directory

ftp_files_to_put     =3D "file.txt"

On Error Resume Next

Set oScript =3D Server.CreateObject("WSCRIPT.SHELL")

Set oFileSys =3D Server.CreateObject("Scripting.FileSystemObject")

Set objFSO =3D CreateObject("Scripting.FileSystemObject")

' Build our ftp-commands file

Set objTextFile =3D objFSO.CreateTextFile(Server.MapPath("test.ftp"))

objTextFile.WriteLine "lcd " & Server.MapPath(".")

objTextFile.WriteLine "open " & 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 <> "" Then

    objTextFile.WriteLine "cd " & ftp_remote_directory

End If



objTextFile.WriteLine "prompt"



' If the file(s) is/are binary (i.e. .jpg, .mdb, etc..), uncomment the

following line

' objTextFile.WriteLine "binary"

' If there are multiple files to put, we need to use the command 'mput',

instead of 'put'

If Instr(1, ftp_files_to_put, "*",1) Then

    objTextFile.WriteLine "mput " & ftp_files_to_put

Else

    objTextFile.WriteLine "put " & ftp_files_to_put

End If

objTextFile.WriteLine "bye"

objTextFile.Close

Set objTextFile =3D Nothing

' Use cmd.exe to run ftp.exe, parsing our newly created command file

strCMD =3D "ftp.exe -s:" & Server.MapPath("test.ftp")

strTempFile =3D "C:\" & oFileSys.GetTempName( )

' Pipe output from cmd.exe to a temporary file (Not :| Steve)

Call oScript.Run ("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True)

Set oFile =3D oFileSys.OpenTextFile (strTempFile, 1, False, 0)



On Error Resume Next

' Grab output from temporary file

strCommandResult =3D Server.HTMLEncode( oFile.ReadAll )

oFile.Close

' Delete the temporary & ftp-command files

Call oFileSys.DeleteFile( strTempFile, True )

Call objFSO.DeleteFile( Server.MapPath("test.ftp"), True )

Set oFileSys =3D Nothing

Set objFSO =3D Nothing

' Print result of FTP session to screen

Response.Write( Replace( strCommandResult, vbCrLf, "<br>", 1, -1, 1) )

%>

=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC

=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC=AC



Cheers Nikos

At 03:47 =EC=EC 31/1/2002, you wrote:

>Hey all,

>2 or 3 weeks ago someone posted a page with an example of FTPing through

 asp

>without any third party software. It was really good- problem is.. the web

>site is now down!!!

>Did anyone happen to copy that? Or better yet- if your still here (you

>genius) could you post it again???

>

>Thanks,

>the nasa geek

>




 $subst('Email.Unsub').







  Return to Index