FTP’ing Files with ASP - Variable: Having No Fixed Quantitative Value
(Page 2 of 4 )
The very first thing I do is create an ftp.asp file, and all the coding will go in there. Then wherever we need to make use of the wonder-function, we just include the page into whatever file we’re working with. (<!--#include virtual="/includes/ftp.asp"--> )
Let’s start working with ftp.asp. First, we declare our variables:
Dim strHost
, strUser, strPass, strMode, LocalDir, RemoteDir
Dim Output, ReturnCode, strScript
Const COMMAND_FTP = "ftp.exe -i -s:"
Most of the variable will be set, but are purposefully variable. This is in case we want to use the scrip for more that one host or file, as I will explain later on.
The only constant is COMMAND_FTP. This is to prevent errors, as we should only ever need to use it with the ‘-i’ switch (disables multiple file transfer prompting) and the ‘–s:’ switch (indicates a text file containing the FTP commands).
Here are some initial values for the other variables:
strHost
= "mydomain.com"
strUser = "ftpadmin"
strPass = "myPassword"
strMode = "ascii" '=== "ascii" / "binary"
LocalDir = Request.ServerVariables("APPL_PHYSICAL_PATH") & "published"
RemoteDir = "/public_html/"
Now these are just the initial settings, preferably set to provide for your most common use within the application. But chances are you will want to make use of FTP for something uncommon, and in that case it would be an absolute pain in the butt to have to duplicate all the code for one use. So, we would quite simply just reset a variable or two after including the page (they are variables after all!). This would not affect the default values anywhere else the page is included. This means that we could bastardize these variants however we chose, and they’d be right back to their glorious selves the next time the page is requested! Here’s an example:
strMode
= “binary”
LocalDir = “C:MyBabyPictures”
RemoteDir = “/outgoing/”
This would be handy if we have an image or a zip file or anything really that needs to be thrown somewhere, anywhere, you name it!
Ok, enough with that, I wish not to be accused of beating a deceased Equus caballus. Let us move onto greater things!
Next: The Great FTP Function >>
More ASP Articles
More By Justin Cook