next up previous contents
Next: Sending and receiving emails Up: Tutorials Previous: Programming the tray icons   Contents

Downloading and uploading files

SWFKit provides the Inet object and the Inet.Ftp object to download and upload files. Downloading a HTTP file is very simple, the following code shows how to do this in action script
import SWFKit.*;

function on_geturl(type, msg)
{
    _root.strace(msg);
    if (!SWFKit.Global.processMsg()) return false;
    return type;
}
var inet = new Inet;
inet.setEventHandler("onGetUrl", on_geturl);
inet.getUrl('http://www.swfkit.com', 'c:\\1.html');

To download or upload a ftp file, you would have to use the Inet.Ftp object. The following code shows how to do this in action script

    import SWFKit.*;
    import SWFKit.inet.Ftp;

    //1. Open an Inet.Ftp object
    //The Inet.Ftp object is created by the Inet.openFtp method.
    var ftp = Inet.openFtp("ftp://192.168.1.3");

    //2. Connect to the ftp server
    ftp.connect();

    //3. Change the current directory
    _root.strace(ftp.currentDir);
    ftp.currentDir = "songs";

    //4. List the files and folders
    var i;
    var list = ftp.list();
    for (i = 0; i < list.files.length; i++)
        _root.strace(list.files[i]);
    for (i = 0; i < list.folders.length; i++)
        _root.strace(list.folders[i]);

    //5. Get the file size
    var info = ftp.getFileInfo("test.rar");
    _root.strace(info.size);

    //6. Download or upload files
    function onDownload(percent)
    {
        _root.strace(percent);
        return true;
    }
    ftp.setEventHandler("onDownload", onDownload);
    ftp.download("test.rar", "c:\\sample\\test.rar");


    function onUpload(percent)
    {
        _root.strace(percent);
        return true;
    }
    ftp.setEventHandler("onUpload", onUpload);
    ftp.upload("test.rar", "c:\\sample\\test_new.rar");



Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.