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

FTP from Client to Server and ASP/ASP.NET Architecture

This is a very common question:
When I open upload in an ASP page from my client machine, I always
get a "File not Found" error. I know D:\temp\test.pdf exists on my
client machine. It seems that the FTP component always looks for this file on Web
server.

How can I upload D:\temp\test.pdf from the ASP page on my client
machine to my FTP server?

Here is my code:

dim filename
filename="D:\Temp\Test.PDF"
localFilename = filename
Dim remoteFilename
remoteFilename = "TEST.pdf"
success = ftp.AsyncPutFileStart(localFilename, remoteFilename)
If (success <> 1) Then
    response.write "Send File: " & ftp.AsyncLog
End If

Answer:
Code within an ASP or ASP.NET page runs on the web server. Therefore, it’s not possible to access client files from within the ASP or ASP.NET code. The web browser (Internet Explorer, Firefox, Opera, etc.) runs on the client. The only way to run code on the client-side is within Javascript or VBScript, embedded in the HTML like this:

<html>
<head>
</head>
	
<body>
	
<script type="text/javascript">
document.write("This message is written by JavaScript");
</script>
	
</body>
</html>

It is possible to run ActiveX components from Javascript in Internet Explorer (but not Firefox; I don’t know about Opera without researching it…). You may write Javascript to use the Chilkat FTP2 component in HTML (run client-side within Internet Explorer). There are two issues:

1) Internet Explorer will not automatically load and run the ActiveX. The browser will require that the user give permission to download, install, and run the ActiveX on the client computer. Once installed, the ActiveX may be used without further prompting.

2) If you’re going to do FTP, it means you might be needing to log onto an FTP server. Your login/password will probably be clearly visible in the Javascript. If you’re uploading to an FTP anonymous account — no big deal. If not, then perhaps the solution is that HTML page itself is protected, and the only way to access it is to provide login/password credentials. In that case, the only person capable of downloading the HTML w/ FTP username & password is the authorized person, and it doesn’t matter that the FTP login credentials are visible.

How to use the FTP2 component in client-side Javascript?

This page shows how to instantiate the FTP ActiveX in Javascript.

You’ll add this tag in your HTML section:

<object name="ftp2" width=0 height=0
classid="clsid:302124C4-30A0-484A-9C7A-B51D5BA5306B"
standby="Loading Chilkat FTP2..."
type="application/x-oleobject"
codebase="http://www.chilkatsoft.com/download/ChilkatFtp2.cab">
</object>
	

An example of using FTP2 in Javascript


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

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