Hamburger button Graphics & animation Programming/web dev Laboratory Contact
Laboratory
Laboratory Tool
Smart FTP Client v.1.0
i
Status: Available
Type: Script, Class
Environment: AIR - Flex/Flash/Animate
Technology: ActionScript 3
Extension: .as
Dependency: None
Size: 4 KB
License: Freeware
Smart FTP Client v.1.0 DOWNLOAD
(Downloads: 2439)
This class provides the ability to download and upload files via an FTP connection and retrieve a directory list from a specified path.
The best feature is its support for performing multiple tasks in a queue. For instance, it enables you to effortlessly upload multiple files.

Class use

Constructor provides ability to establish an immediate connection.
var mySmartFTP = new SmartFTP(host:String = null, username:String = null, password:String = null, port:int = 21):void
You can also create instance without making connection
var mySmartFTP = new SmartFTP();
And later open connection at any moment
mySmartFTP.open(host:String = null, username:String = null, password:String = null, port:int = 21):void

How to use paths

localPath example - "C:/test1.txt"
ftpPath example - "/public_html/test2.txt"

Methods

upload(localPath:String, ftpPath:String = ''):void
Upload a file from "localPath" to "ftpPath". This method will not work if there is no active connection or if the socket is busy.

uploadTask(localPath:String, ftpPath:String = ''):void
Create a new upload task. Tasks are triggered as soon as possible when the connection is active and not busy, one after another.

download(localPath:String, ftpPath:String):void
Download a file from "ftpPath" to "localPath". This method will not work if there is no active connection or if the socket is busy.

downloadTask(localPath:String, ftpPath:String):void
Create a new download task. Tasks are triggered as soon as possible when the connection is active and not busy, one after another.

dirListMsg(ftpPath:String):void
Read the directory list from "ftpPath". You can retrieve the result (directory list message) from the "msg" property of the event listener or the stored message list.

dirListMsgTask(ftpPath:String):void
Create a new "read directory list" task. Tasks are triggered as soon as possible when the connection is active and not busy, one after another.

open(host:String = null, username:String = null, password:String = null, port:int = 21):void
Open the connection.

close():void
Close the connection.

closeTask():void
Close the connection task. Tasks are triggered as soon as possible when the connection is active and not busy, one after another.

closeStream():void
Close any read/write stream for upload or download. Be aware that it is not recommended to use this method because it will not stop processes associated with upload/download. For safety, it is better to use the "close()" or "closeData()" methods.

closeData(closeDataTasks:Boolean = true):void
Close everything except the connection and tasks if "closeDataTasks" is set to "false".

clearMessage():void
Clear all stored messages.

clearError():void
Clear all stored error messages.

Properties

listener:Function
This function is used to detect events. It receives an event object with several attributes:
  • target (current SmartFTP instance)
  • code (response code number)
  • type (event type)
  • task (name of the task, the source of the event)
  • msg (last original message received from the server)
To recognize events you need to use event types:
LOGIN_SUCCESS, DOWNLOAD_SUCCESS, UPLOAD_SUCCESS, CONNECTION_CLOSED, CONNECTION_TIMEOUT,LOGIN_FAILD, DIRECTORY_FAILD, UPLOAD_STREAM_SUCCESS, STREAM_CLOSED, ERROR, DIR_LIST_RECEIVED
Example:
var mySmartFTP = new SmartFTP();
function myListenerFunction(e):void {//e:Object
    if (e.type == SmartFTP.LOGIN_SUCCESS) {
        trace('You are logged in!');
    }
}
mySmartFTP.listener = myListenerFunction;


message:String
Read only. Returns all messages as a single string.

messageVec:Vector.<String>
Read only. Returns all messages as a vector array.

error:String
Read only. Returns all errors as a single string.

errorVec:Vector.<String>
Read only. Returns all errors as a vector array.

taskList:Vector.<Object>
Read only. Returns the original task list.

fileData:ByteArray
Read only. Returns the last used ByteArray data.

connected:Boolean
Read only. Returns true if the connection is active.

connectedData:Boolean
Read only. Returns true if the socket for data transfer is active.

busy:Boolean
Read only. Returns true if the connection is busy and a new action cannot be taken until the connection is no longer busy.

host:String
Read only. Returns the current host.

username:String
Read only. Returns the current username.

password:String
Read only. Returns the current password.

port:int
Read only. Returns the current port.

path:String
Read only. Returns the current task name.