DirectedInsight
NEWEST
Different ways to show the user they're wrong.
Helpful
Some simple queries that can save you some research time
NEWER
Complete AJAX example.
COOL
Dynamic file upload fields

small DI oval FTP Multiple Files with ASP and WScript.Shell

This is a simple example of how to send multiple files via FTP from an ASP page using a shell object and a commands file for the FTP executable. There are variety of shareware and even freeware components out there that can do this but doing it yourself is not nearly as hard as it might first sound.

There are only two pieces to this, the ASP page itself and a command file to hold the commands for the FTP executable.


small DI oval ASP Code

Your ASP code will look like this:

Set oShell = server.CreateObject("WScript.Shell")
cmdLine = "ftp.exe -v -i -s:D:\InetPub\wwwroot\siteName\includes\ftpCommands.txt"
tempRet = oShell.Run ("cmd.exe /c " & cmdLine, 0, false)
set oShell = nothing

' wait 2 seconds for each email created
waitTime = numberOfFiles * 2
startTime = Timer
do while timer < startTime + waitTime
loop
                

What we're doing here is creating a shell object so we can access the command line and from there the windows FTP executable.
The next line creates the command line instructions to be executed. The switches given to the FTP.exe are:

In the next line we are using the shell object to access the command line (cmd.exe) and telling it to execute the commands we built in the line above. The /c option tells it to run the command that follows and then stop. The three arguments to the run command are:

The final line just removes the shell object. The following 4 lines of code set up a timer that will delay for 2 seconds for every file being sent. This way we avoid any access violations if we need to do anything with the files later, like move them to an archive. If you don't, you can omit that step.


small DI oval Commands File

The commands file is simply a list of commands that the FTP executable will read and run in order.

open ftp.domainName.com
userName
password
cd destinationDirectory
mput D:\InetPub\wwwroot\siteName\ftpFiles\*.*
close
bye

In order, what is happening here is:

This example has all of the commands hard coded in the commands file, if you need to create it on the fly you can use the Scripting.FileSystemObject to create your commands file with whatever instructions you need. Just make sure you name it and save it to the directory you're referencing in the line:

cmdLine = "ftp.exe -v -i -s:D:\InetPub\wwwroot\siteName\includes\ftpCommands.txt"


I hope this helps someone out, if you have a question, comment, addition, correction, or better way of doing it let us know. We'll add it to the demo with the proper credit. comments@directedinsight.com

small DI oval