FTP’ing Files with ASP
(Page 1 of 4 )
Would you like the ability to transfer files from your ASP app with the greatest of ease? Forget downloading and installing server-side components, forget spending money. Forget inefficient and/or cryptic coding! This article demonstrates how easy it is to embed file transfer functionality into your application. Just for the record, This concoction more or less saved my life at one point, and I presume it will do no less than the same for you.
A general rule to programming is that virtually no problem is unique. To illustrate: some time ago, I was building a content management system in ASP, and came up against what seemed to be a major barrier. I had all my templates working wonderfully on the content staging server, pulling their content from a MySQL database. But the pages could only be served to the World Wide Web in static HTML format, from a UNIX server somewhere in the States. How on Earth could I publish the content statically, and then get them to their host? Quite the conundrum!
I worked out a method to publish the pages, directory structure and all. Who knows, maybe that will be the subject of a future article. This one however, is written for the sole purpose of explaining how the heck I got those HTML files to move.
It was quickly discerned that I’d best use FTP as the protocol by which to transfer the files (wink wink). A quick search on Google informed me that thousands of other developers were discerning the very same thing, and like me, were looking for the way to do it. Most, like me again, do not want to put out money, or install components, for something they believe they should be able to efficiently code by themselves.
So I’m going to show you how I did it!
Goals
It seems that most people have similar goals as me in the FTP via ASP issue (though that’s where the similarities seem to end!). We all have one or more files, sitting in one or more directories, that we need to transfer to one or more hosts, one or more times. Ok, perhaps a confusingly vague sentence. All I’m saying is that we need to transfer a file (one or more…) and that’s all. We don’t need a GUI, a progress bar, a KB/second indicator, a queue, or anything to resume broken downloads. We just want to take a group of 0’s and 1’s at point A, and get them to point B.
So that’s all I’ve built, a plain-vanilla FTP function. You may prefer chocolate, or even strawberry, but I assure you it works perfectly!
Prerequisites
This article assumes a solid grasp on copying & pasting text, a Microsoft Windows environment in which you’re hosting your ASP files, and some good strong coffee (optional).
The reason for the Windows requirement is that we’ll be using the inbuilt ftp.exe, and some Windows shell scripting in your ASP page.
Next: Variable: Having No Fixed Quantitative Value >>
More ASP Articles
More By Justin Cook