Code Examples
1. Using IIS
IIS5 (Windows 2000), 5.1 (Windows XP), or IIS6 (Windows Server 2003 family) Web servers can use
JustFTP in ASP, ASP.NET pages (or other COM / ActiveX aware server
applications) to call the FTP methods provided.
To use JustFTP in with IIS, a COM+
application must be created to "hold" or "wrap" the
JustFTP dll
component.
1. Create a COM+ empty application
using the Component Services GUI. (Start /
Programs / Administrative Tools / Component Services).
2. Add
justftp.dll to the application.
3. Assign a user credential that
can access the network and local file system as the COM+ "Identity".
4. If using Windows 2003
uncheck the security option to "Enforce access checks".
See the example walkthrough with screen
shots to see exactly how to do this.
The main reason for creating a COM+
"application" for JustFTP is so that an "identity" for the
FTP method calls
can be specified. The ASP or ASP.NET page / application does not need
any special authentication changes.
ASP code calling the JustFTP "COM+"
component is the same as if the DLL were simply registered. No changes
to the code are required when calling JustFTP as a COM+ application.
COM+ "wraps" the DLL as a "configured component" and
is always the preferred installation scenario for JustFTP for all uses.
| When creating the
JustFTP
object in code, always use the version
independent ProgID "JustFTP.FTP" for CreateObject (VBScript) or
Server.CreateObject (ASP Script). |

ASP Code Example
IIS5 (Windows 2000), IIS5.1 (Windows XP), or IIS6 (Windows Server 2003 family) Web servers can use
JustFTP in ASP and ASP.NET pages.
Using JustFTP to transfer a file to a
remote server.
The code example below shows an ASP
page calling JustFTP to send the file backup.log to a central server.
Note that
the Program Identifier (progid) is "JustFTP.FTP".
<html>
<head>
</head>
<body>
<%
Dim objFtp, Result
Set objFtp = Server.CreateObject("JustFTP.FTP")
Result = objFtp.Send("d:\backups\backup.log",
"admin7.mycorp.com", "/backups", "server32-backup.log",
"robot05", "secret")
Response.Write Result
Set objFtp = Nothing
%>
</body>
</html>
|

2. Using VBScript
Using
JustFTP is a simple process. For example, the following VBScript
code will retrieve the file "rfc35.txt" from
the "/rfc" directory of the public IETF FTP server. The
file is then placed in the root of the local c:\ drive with the
file name test.txt
| 'Sample
VBScript code to retrieve a file from a remote server.
'Simply save this as a
file called test.vbs and double click it to run.
(Assumes you have an Internet connection).
Dim objFtp, Result
MsgBox("Start")
Set objFtp = CreateObject("JustFTP.FTP")
Result = objFtp.Get("c:\test.txt", "ftp.ietf.org", "/rfc", "rfc35.txt",
"anonymous", "you@your.domain")
MsgBox(Result)
Set objFtp =
Nothing
MsgBox("Done") |
A primary feature of JustFTP is the predictable return result.
All methods return a simple text string. This is either "OK"
or "Fail", depending on the success (or not) of the
operation requested.
This allows predictable testing
for success in script code. Code such as:
If Result = "Fail" Then
MsgBox("File transfer failed")
End If
All the methods are self explanatory and the
sample code above shows how to use the component. Values are
always passed into the methods.
The "Dir" method however is
slightly different in that the directory listing is returned in
the DirList parameter.
Simply pass a variable in VBScript that will
receive this information. This is shown below, the variable Dirinfo has been used.
| 'Sample
VBScript code to retrieve a directory listing from a remote server.
Option Explicit
Dim objFtp
Dim Dirinfo, Result
Wscript.echo("Start")
Set objFtp =
CreateObject("JustFTP.FTP")
Result = objFtp.Dir("ftp.ietf.org",
"/rfc", Dirinfo, "anonymous", "you@yourdomain.com")
Wscript.echo(Result)
Wscript.echo(Dirinfo)
Set objFtp =
Nothing
Wscript.echo("Done") |
Note: As directory listings can be
quite long,
run this script in a command prompt using cscript
(the Windows console scripting engine).
Thus: C:\>cscript ftpdirtest.vbs
The sample
below can be run using wscript (Windows GUI script engine) or
cscript (console Script engine), as the directory listing of
RFC's will fit on your screen in the message box.
| 'Sample VBScript code
to retrieve a directory listing from a remote server.
Option Explicit
Dim objFtp
Dim Dirinfo, Result
MsgBox("Start")
Set objFtp =
CreateObject("JustFTP.FTP")
Result = objFtp.Dir("ftp.ietf.org", "/", Dirinfo,
"anonymous", "you@yourdomain.com")
MsgBox(Result)
MsgBox(Dirinfo)
Set objFtp =
Nothing
MsgBox("Done") |
Download
the trial version 404 KB
|