Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

December 18, 2007

Using Chilkat FTP2 in Client-Side Javascript

Here’s an online example that demonstrates how to use the Chilkat FTP2 ActiveX in Javascript:
FTP Download in Javascript.

<script type="text/javascript"  language="javascript">
function ftpDownload()
	var ua = navigator.userAgent;
	if (ua.indexOf('Firefox') != -1) { alert("This only works in Internet Explorer"); return; }
	document.ftp2.UnlockComponent("Anything goes here.");
	document.ftp2.Hostname = document.form1.hostname.value;
	document.ftp2.Username = document.form1.username.value;
	document.ftp2.Password = document.form1.password.value;
	// Note: If this does not work, try using Passive mode instead
	// by uncommenting this line:
	//document.ftp2.Passive = 1;
	var d;
	d = document.getElementById("lastErr");
	var success;
	success = document.ftp2.Connect();
	if (success == 0) {
	    d.innerHTML = document.ftp2.LastErrorHtml;
	    alert("Connect Failed.");
	} else {
		success = document.ftp2.GetFile("hamlet.xml","c:/temp/hamlet.xml");
		if (success == 0) {
		    d.innerHTML = document.ftp2.LastErrorHtml;
		} else {
		    d.innerHTML = "Download successful!";

The pertinent part of the HTML:

<form name="form1" id="f1" action="javascript:ftpDownload()" method="post">
<p style="margin-bottom: 5px;">FTP Host:<br><input name="hostname" id="hostname" value="" size="60" type="text"></p>
<p style="margin-bottom: 5px;">Login:<br><input name="username" id="username" value="test" size="60" type="text"></p>
<p style="margin-bottom: 5px;">Password:<br><input name="password" id="password" value="test" size="60" type="text"></p>
<p style="margin-bottom: 5px;">
<input id="submit" name="submit" value="GetFile" type="submit">
<div id="lastErr"></div>
<object name="ftp2" width=0 height=0
standby="Loading Chilkat FTP2..."

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.