Question:
We are trying out the FTP2 ActiveX component for ASP. What we need to do is
have people be able to upload files to the web server over the Internet. Is
this component able to do this - or can it only FTP files that are already on the
web server?
Answer:
This is a common question. The need is to upload files from the user’s computer (i.e. the computer where the browser is running) to the web server. You should remember that your ASP code is running on the server (not on the computer where the browser is running). Therefore, any code within your ASP will only have access to the files on the web server. What you really want is to do a simple HTTP file upload from the browser. You’ll need to provide both client-side and server-side code to implement the HTTP upload. The client-side is extremely easy — you simply create a form with “file” type input tags:
<html>
<body>
<form method="POST" enctype="multipart/form-data" action = "http://www.mywebserver.com/ReceiveUpload.aspx" >
<input name=attach1 type=file size=20><br>
<input name=attach2 type=file size=20><br>
<input type=submit value="Upload">
</form>
</body>
</html>
The above form uploads two files, and also sends a few extra (non-file) form fields. To upload a single file, simply remove one of the “input” HTML tags.
Receiving the upload on the server-side requires programming. It can be done in classic ASP, ASP.NET, Perl, a C++ CGI, etc.
Here are examples for classic ASP and ASP.NET:
Receive HTTP Upload Files in Classic ASP
Receive HTTP Uploads directly into memory in Classic ASP
Receive Upload + additional form fields in Classic ASP
Complete ASP.NET (C#) HTTP Upload Example
HTTP upload requires code both client-side and server-side code to be functioning correctly. Imagine you are trying to do an HTTP upload from your application (using the Chilkat Upload component) and something is not working. How do you debug? Is the client-side application at fault? Is the Chilkat Upload component not working correctly? Is the server-side code that receives the upload not functioning correctly? (Remember, w/ HTTP upload you must write the server-side code to receive the upload.)
A good way to debug is to substitute a web browser (FireFox or Internet Explorer) for the client-side. You can be assured that the browser will perform the client-side of the upload correctly. If the upload fails using a browser, then the problem must be on the server-side. (Or it’s possible there are problems in your client-side application AND the server-side, but by using the web browser you can test your server-side independently of your client-side.)
To upload from a browser, simply create an HTML page with a form like this:
<html>
<body>
<form method="POST" enctype="multipart/form-data" action = "http://www.mywebserver.com/ReceiveUpload.aspx" >
<input name=hid1 type=hidden value="test123">
<input name=hid2 type=hidden value="abcdef">
<input name=attach1 type=file size=20><br>
<input name=attach2 type=file size=20><br>
<input type=submit value="Upload">
</form>
</body>
</html>
The above form uploads two files, and also sends a few extra (non-file) form fields. To upload a single file, simply remove one of the “input” HTML tags.
In summary: If the upload using a browser fails, you should focus on getting your server-side code working correctly. Once uploading with a browser is successful, you should then test your client-side code. It is now known that your server-side code is receiving the upload properly, so if your client-side code fails, there must be a problem with it.
The AspMaxRequestEntityAllowed Metabase Property (IIS 6.0) specifies the maximum number of bytes allowed in the entity body of an ASP request. The default value is 2MB. To upload files greater than this size, this IIS metabase property must be changed on the server.
A web application running in IIS7 on Windows Server 2008 will reject any upload that is larger than 30MB. This is the default size limit for IIS7. To increase the maximum file size, add the following code to <system.webServer> in the web.config file:
(This example sets the limit to 500MB)
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength=”500000000″ />
</requestFiltering>
</security>
You must restart IIS for the setting to take effect.