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!

How can I read a txt file and..

Status
Not open for further replies.

Netguy2

Programmer
Jun 16, 2004
2
US
then execute it by using: Server.CreateObject("WScript.Shell")

Here is my example:

strSourcePath = "\\webserver\ Set fso = CreateObject("Scripting.FileSystemObject")
Set objTxtFile = fso.CreateTextFile (Server.MapPath("\gripanet\uploadtxtfile\ftpsend.txt"))
' Write the Header
objTxtFile.writeline( "ftp" )
objTxtFile.writeline( "open myweb.com" )
objTxtFile.writeline( "username" )
objTxtFile.writeline( "password" )
objTxtFile.writeline( "cd images" )
objTxtFile.writeline( "cd pdf" )

Set conn = createobject("adodb.connection")
conn.open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=username;Password=password;Initial Catalog=GRIPANET;Data Source=iisserver"

Set rsGetPDFS = Server.CreateObject("ADODB.Recordset")
rsGetPDFS.Open "exec usp_getpdfs ", conn, 3, 3

' Determine if there are any records
If Not rsGetPDFS.EOF Then

'Loop through records
Do While Not rsGetPDFS.EOF
objTxtFile.writeline( "put " & strSourcePath & "\" & rsGetPDFS("FileName") & "")
rsGetPDFS.MoveNext
Loop

'End the If record exists
END IF
'END THE FTP SESSION
objTxtFile.writeline( "close" )
objTxtFile.writeline( "quit" )
objTxtFile.writeline( "exit" )
'***************** Read
Set textStreamObject = fso_OpenTextFile(Server.Mappath("\gripanet\uploadtxtfile") & "\ftpsend.txt",1,false,0)
Response.Write textStreamObject.ReadLine

Set objShell = Server.CreateObject("WScript.Shell")
objShell.Run("cmd.exe")

Is there a way to now read this file and execute it using WScript.Shell ?

Also is there a way to do this that may not involve even writing the file? If so does it make more sense to do?
 
Use the FileSystemObject to rename your text file to a .bat.

You can then use

objShell.Run("cmd.exe /C ftpsend.bat")

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Take a look at the -s: command line switch of ftp.exe

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top