Jump to content

File Uploading (Asp & AutoIt)


Toady
 Share

Recommended Posts

This is a quick and fast way to upload files to another computer thats running IIS (Internet Information Services). I developed this tool for a project I am currently working on where I work. It works by doing these steps:

On computer your wanting to upload files to, you will need to have a website directory in your "\wwwroot" directory. For this example I am using my own computer so the path to this directory is:

c:\Inetpub\wwwroot\myWebsite\

I then place Upload.aspx in this directory, thereby making the URL to this page:

I then created a folder inside of "myWebsite" directory and named it "uploads", this is where I will be uploading my files.

c:\Inetpub\wwwroot\myWebsite\uploads\

After this I made sure that the security settings on the "uploads" folder are set appropriately so I can get write access.

I then run this AutoIt script to upload a file. It will allow the user to select a file to upload then upload the file.

#cs ----------------------- ASP.NET File Upload Example ------------------------
Author: Toady
Requirements: Upload.aspx on IIS web server
              Security permissions for Uploads folder need to be set accordingly
#ce ----------------------------------------------------------------------------

#include <IE.au3>

$IEo = _IECreate("http://localhost/myWebsite/Upload.aspx",0,0,1,0)

$FileInput_obj = _IEGetObjByName($IEo,"FileInput") ; File input tag
$uploadfileid_obj = _IEGetObjByName($IEo,"uploadfileid") ;Submit button
$status_obj = _IEGetObjById($IEo,"status") ;Asp:label

_IEAction ($FileInput_obj, "click") ;Click on Browse button
_IEAction ($uploadfileid_obj, "click") ;Click on upload button
; A "choose file" window will display, select a file, then click ok

SplashTextOn("Attempting to upload","Please wait...",200,30)
_IELoadWait($IEo) ;wait for file to upload
SplashOff()

$status_obj = _IEGetObjById($IEo,"status") ;read label for status

If _IEPropertyGet($status_obj,"innertext") = "Success" Then
    MsgBox(0,"","File Uploaded")
Else
    MsgBox(0,"Upload Failed",_IEPropertyGet($status_obj,"innertext"))
EndIf

_IEQuit ($IEo)

Exit

Below is the asp page I wrote to handle the requests. There is no real error handling, this is just a working example. Hopefully this comes in use. It did for me!

<%@ Page Language="VB" Strict="false" EnableViewState="false" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Web.UI" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<script runat="server">

Public Dim rootDir As String
'rooDir is the location inside of \wwwroot\ to upload files

Sub Page_Load()
    rootDir = Server.MapPath("\myWebsite\uploads\")
    Response.write(rootDir)
End Sub

' AutoIt clicks the Upload File button
Sub UploadFile(ByVal sender As System.Object,ByVal e As System.EventArgs)
    Dim UploadFileLocal = rootDir & Path.GetFileName(FileInput.PostedFile.FileName)
    Response.write(UploadFileLocal)
    Try
       FileInput.PostedFile.SaveAs(UploadFileLocal)
       status.Text = "Success"
    Catch Exc As Exception
       status.Text = Exc.Message
    End Try
End Sub

</script>

<html>
    <form id="myform" method="post" enctype="multipart/form-data" runat="server">
        <INPUT id=FileInput type=file runat="server">
        <asp:button id=uploadfileid onclick=UploadFile runat="server" Text="Upload File" type="submit">
        </asp:button>
        <asp:label id=status runat="server" Text="Ready">
        </asp:label>
    </form>
</html>
Edited by Toady

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

I've done something similar, but with an apache server.

The php part was just a basic upload form, the AU3 script call the URL, fills and submit that form.

Due to file size limit (2M in my case), the script splits the file into 1.5M packets and sends them all, they are gathered by another php script later.

Now I'm using apache/WebDav, file transfers are no more a probem :whistle:

Apzo.

Link to comment
Share on other sites

  • 2 weeks later...

It is good, but the same thing can be accomplished via Web-based Autoit :P

Maybe it will be my next project.

But this script is still very good :)

Thx for the comment, it may be accomplished in another way. Yet the title of this thread says "Asp & AutoIt".... catch my drift?

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...