mn8 Language Reference | Index    

FTPClient

SUMMARY: ATTRIBUTES SUMMARY  NO ELEMENTS  NO CONSTRUCTORS  NO OPERATORS  METHODS SUMMARYDETAIL: ATTRIBUTE DETAILS  NO ELEMENTS  NO CONSTRUCTORS  NO OPERATORS  METHOD DETAILS

Description

This concept can be used to execute FTP commands on specified FTP server. This concept is able to login into a FTP server, view and change the working directory, create, remove and list files and directories on the FTP server and change transefer mode to ASCII and to BINARY mode.

Usage

            $ftpCl typeof FTPClient
            #open FTP conncetion to host in dir named directory
            if ( $ftpCl.openConnection("ftp://hostName/dirName") ) then [
                #login into FTP server using specified username and password
                if ( $ftpCl.login("userName","passwd") ) then [
                   #rename oldDir directory to newDir
                   if $ftpcl.rename("/oldDirName", "/newDirName") then [
                       print "OK"]
                   #show working directory
                   print $ftpcl.getWorkingDirectory]]

Version: 0.1
Authors:Szabo Csaba ()
Location:
Inherits: Concept

Attribute List

 @errorCode TYPEOF Integer LABEL "errorCode"
 @errorMessage TYPEOF String LABEL "errorMessage"
top

Method List

LogicalchangeWorkingDirectory (String $path)
closeConnection
Logicaldelete (String $path)
ConceptgetFile (String $file)
SeriesgetLinks
SeriesgetLinks (String $path)
StringgetWorkingDirectory
LogicalisPositiveCompletion
Logicallogin (String $userName, String $password)
Logicallogout
Logicalmkdir (String $path)
LogicalopenConnection (String $url)
LogicalputFile (String $fileName, Concept $content)
Logicalrename (String $oldName, String $newName)
LogicalsetBinaryMode (Logical $isBinary)
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Attribute Info

@errorCode

Label:errorCode
Type:Integer
Is Static:false
Is Hidden:false
Show Empty:true

Stores that error code with which the last executed command returned.

top

@errorMessage

Label:errorMessage
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

Stores that error message with which the last executed command returned.

top

Detailed Method Info

changeWorkingDirectory (String $path)
Parameters:
$path :The new directory path.
Returns: Logical
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..
FTPOperationException :
(Warning)
If can not change the working directory that is not exists.

Returns true if the changing of the current working directory to the directory specified in $path was successfull, false otherwise.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                print $ftp.getWorkingDirectory
                $ftp.changeWorkingDirectory("..")
                print $ftp.getWorkingDirectory
                $ftp.changeWorkingDirectory("mydir")
                print $ftp.getWorkingDirectory
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            /mydir
            /
            /mydir
            

top
closeConnection
Returns:
Exceptions:
connectionException :
(Error)
If an error occured when the FTPClient try to close the FTP connection..

Close the current connection.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                print $ftp.getWorkingDirectory
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            /mydir
            

top
delete (String $path)
Parameters:
$path :The path to the file or directory you want to delete.
Returns: Logical
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..
FTPOperationException :
(Warning)
If the directory is not exists.

Deletes the file or directory specified by the $path.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                if ($ftp.putFile("test.txt", "This is a test.")) then [
                  $ftp.getLinks
                  $ftp.delete("test.txt")
                  $ftp.getLinks
                ]
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            -rw-r--r--   1 guest    guest      165392 Apr 22 12:38 car.jpg
            -rw-r--r--   1 guest    guest       38472 Jul 31 17:51 report.doc
            -rw-r--r--   1 guest    guest          15 Aug 15 21:43 test.txt

            -rw-r--r--   1 guest    guest      165392 Apr 22 12:38 car.jpg
            -rw-r--r--   1 guest    guest       38472 Jul 31 17:51 report.doc
            

top
getFile (String $file)
Parameters:
$file :The file name.
Returns: Concept
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..

Returns the specified $file's content. If the file content is text this concept return a String concept otherwise return ByteArray concept.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                if ($ftp.putFile("test.txt", "This is a test.")) then [
                  print $ftp.getFile("test.txt")
                ]
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            This is a test.
            

top
getLinks
Returns: Series
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..

Returns a series which contains all directories in the current working directory.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                $ftp.getLinks
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            -rw-r--r--   1 guest    guest      165392 Apr 22 12:38 car.jpg
            drwxrwsr-x   2 guest    guest          96 Jul 10 13:08 docs
            -rw-r--r--   1 guest    guest       38472 Jul 31 17:51 report.doc
            -rw-r--r--   1 guest    guest          15 Aug 15 21:43 test.txt
            

top
getLinks (String $path)
Parameters:
$path :The path to the directory.
Returns: Series
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..

Returns a series which contains all directories in the specified $path.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                $ftp.getLinks("docs")
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            -rw-r--r--   1 guest    guest          21 Jul 18 10:58 notes.txt
            -rw-r--r--   1 guest    guest          82 Jul 15 17:02 log.txt
            

top
getWorkingDirectory
Returns: String
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..

Returns the current working directory.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                print $ftp.getWorkingDirectory
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            /mydir
            

top
isPositiveCompletion
Returns: Logical

Returnes true if the error code is a positive complection response, false otherwise.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                print $ftp.isPositiveCompletion
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            true
            

top
login (String $userName, String $password)
Parameters:
$userName :The user's name with which to connect.
$password :The user's password with which to connect.
Returns: Logical
Exceptions:
connectionException :
(Warning)
If you are not connected to FTP server..
connectionException :
(Error)
If unable to login to FTP server, the FTP connection is closed.

Returns true if the logging in with the specified $userName and $password was successfull, false otherwise.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              print $ftp.login("guest", "guest")
            ]
            -- the result is --
            true
            

top
logout
Returns: Logical
Exceptions:
connectionException :
(Error)
If an error occured when you try to logout from the FTP server..

Returns true if the logging out was successfull, false otherwise.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                print $ftp.logout
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            true
            

top
mkdir (String $path)
Parameters:
$path :The path to the directory which will be created.
Returns: Logical
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..
FTPOperationException :
(Warning)
If the directory is already exists.

Creates a new subdirectory on the FTP server in the current directory (if a relative pathname is given) or where specified (if an absolute pathname is given) and returns true if the directory creation was successfull, false otherwise.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                $ftp.getLinks
                $ftp.mkdir("tmp")
                $ftp.getLinks
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            -rw-r--r--   1 guest    guest      165392 Apr 22 12:38 car.jpg
            drwxrwsr-x   2 guest    guest          96 Jul 10 13:08 docs
            -rw-r--r--   1 guest    guest       38472 Jul 31 17:51 report.doc
            -rw-r--r--   1 guest    guest          15 Aug 15 21:43 test.txt

            -rw-r--r--   1 guest    guest      165392 Apr 22 12:38 car.jpg
            drwxrwsr-x   2 guest    guest          96 Jul 10 13:08 docs
            -rw-r--r--   1 guest    guest       38472 Jul 31 17:51 report.doc
            -rw-r--r--   1 guest    guest          15 Aug 15 21:43 test.txt
            drwxrwsr-x   2 guest    guest          48 Aug 02 13:08 tmp
            

top
openConnection (String $url)
Parameters:
$url :The url to the remote host.
Returns: Logical
Exceptions:
unknownHostException :
(Error)
If missing a host name form URL.
connectionException :
(Error)
If the FTP server refuzed connection.
unsupportedProtocolException :
(Error)
If the protocol is unsupported by the FTPClient..
badURLException :
(Error)
If the URL isn't valid.
IOException :
(Error)
If the socket could not be opened.

Returns true if the connection to the remote host with the specified $url was successfull, false otherwise.

            $ftp typeof FTPClient
            print $ftp.openConnection("ftp://hostName/mydir")
            -- the result is --
            true
            

top
putFile (String $fileName, Concept $content)
Parameters:
$fileName :The file name which will be stored.
$content : The content of the stored file. The content must be a String or a ByteArray concept.
Returns: Logical
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server.
unsupportedContentException :
(Error)
If $content parameter isn't a String or a ByteArray concept.

Returns true if the store of the file was successfull, false otherwise.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                if ($ftp.putFile("test.txt", "This is a test.")) then [
                  print $ftp.getFile("test.txt")
                ]
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            This is a test.
            

top
rename (String $oldName, String $newName)
Parameters:
$oldName :The name of the remote file to rename.
$newName :The new name of the remote file.
Returns: Logical
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..
FTPOperationException :
(Warning)
If can not rename the directory.

Returns true if the renaming of the remote file was successfull, false otherwise.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                if ($ftp.putFile("test.txt", "This is a test.")) then [
                  $ftp.getLinks
                  $ftp.rename("test.txt", "text.tst")
                  $ftp.getLinks
                ]
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            -rw-r--r--   1 guest    guest      165392 Apr 22 12:38 car.jpg
            -rw-r--r--   1 guest    guest       38472 Jul 31 17:51 report.doc
            -rw-r--r--   1 guest    guest          15 Aug 15 21:43 test.txt

            -rw-r--r--   1 guest    guest      165392 Apr 22 12:38 car.jpg
            -rw-r--r--   1 guest    guest       38472 Jul 31 17:51 report.doc
            -rw-r--r--   1 guest    guest          15 Aug 15 21:43 text.tst
            

top
setBinaryMode (Logical $isBinary)
Parameters:
$isBinary :

The logical value to set. If true the file type will be set to binary, if false the file type will be ascii.

Returns: Logical
Exceptions:
FTPOperationException :
(Error)
If unable to execute FTP command on FTP server..
FTPOperationException :
(Warning)
If can not change transfer mode to binary.

Sets the file type.

            $ftp typeof FTPClient
            if ($ftp.openConnection("ftp://hostName/mydir")) then [
              if ($ftp.login("guest", "guest")) then [
                print $ftp.setBinaryMode(TRUE)
              ]
              $ftp.closeConnection
            ]
            -- the result is --
            true
            

top