|
Class: FTPClient
Object
|
+--NVTClient
|
+--FTPClient
- Package:
- stx:goodies/communication
- Category:
- Net-Communication-FTP
- Version:
- rev:
1.66
date: 2017/06/12 10:41:32
- user: mawalch
- file: FTPClient.st directory: goodies/communication
- module: stx stc-classLibrary: communication
- Author:
- Claus Gittinger
Client interface to an ftp server.
[instance variables:]
partnersTransferMode mode of the connected-to partner
(nil initially - could be initialized by parsing some startup message)
transferMode wanted mode (can be changed before logging in)
passiveMode controls data connection setup - either I connect to the partners data port,
or he connects to my data port (req'd for firewalls / outgoing connection blockers)
passiveMode == false -> I am actively connecting to partners data port
passiveMode == true -> I am passively awaiting partner to connect to my data port
HTTPInterface
Socket
FTPTool
Signal constants
-
fileErrorSignal
-
return the signal raised if some file-get or chdir fails
-
fileNotFoundErrorSignal
-
return the signal raised if some file-get or chdir fails
-
filePutErrorSignal
-
return the signal raised if some file-put fails
-
ftpErrorSignal
-
return the parent of all ftp errors
-
transferInformationSignal
-
return the notification raised to transfer info information (such as speed etc.)
Currently never raised, but provided for later extension and compatibility with HTTPInterface.
-
transferProgressNotificationSignal
-
return the notification raised to provide progress (percentage) information.
Currently never raised, but provided for later extension and compatibility with HTTPInterface.
class initialization
-
initialize
-
self initialize.
Verbose := true
compatibility - squeak
-
changeDirectoryTo: dirName
-
-
getDirectory
-
-
getFileNamed: fileName
-
-
loginUser: user password: pw
-
login using userName and password. Squeak compatibility.
After successful login, set transfer mode
-
putFileStreamContents: aStream as: remoteFileName
-
defaults
-
defaultPassword
-
the anonymous's default password
-
defaultPort
-
Socket portOfService:'ftp'
-
defaultUser
-
error handling
-
fileNotFoundError
-
-
filePermissionError
-
-
noPort: errMsg
-
initialization
-
initialize
-
means: unknown
operations
-
ascii
-
send a 'type a' command (switch to text-mode transfer).
-
binary
-
send a 'type i' command (switch to binary-mode transfer)
-
cd: aDirectoryPath
-
send a changeDirectory command
-
cdUp
-
send a changeDirectory-up command
-
delete: aFilePath
-
send a delete file command
-
get: aFileNameString
-
send a get command; return the result as either a string
or a byteArray (depending on the transfer mode).
Raise connectFailedSignal if data connection cannot be established
-
getStreamFor: aFilenameString
-
send a get command; return a stream on the files contents.
Raise a signal if connection cannot be established
-
help
-
send a 'HELP' command to ask about the partners capabilities.
Return a collection of help lines.
-
list
-
send a list command; return the result as a collection of
strings (containing the listing)
-
list: aFileName
-
send a list command; return the result as a collection of
strings (containing the listing)
-
listStream
-
send a list command; return a stream on the listing
-
listStream: listCommand
-
send a list command; return a stream on the listing
-
listWithCommand: listCommand
-
send a list command; return the result as a collection of
strings (containing the listing)
-
mkdir: aDirectoryNameString
-
send a make Directory command
-
nlist
-
send an nlist command; return the result as a collection of
strings (containing the listing)
-
passiveMode: aBoolean
-
set passiveMode to aBoolean.
In passive mode, the server instead of the client creates an extra socket to transmit the data.
Answer the prevoius status of passiveMode
-
put: aStringOrByteArrayOrStream as: remoteFileName
-
send a put command;
send aStringOrbyteArray
-
putFile: localFileName as: remoteFileName
-
send a put command;
send a local file
-
putStreamFor: aFilenameString
-
send a put command; return a stream for writing the file
-
pwd
-
send an XPWD (print current dir) command; return the directory or nil
if the partner does not support the XPWD command
-
recursiveMkDir: aDirectoryNameString
-
recursively create all required directories and change to
-
rename: fromFilename to: toFilename
-
rename a file
-
rmdir: aDirectoryNameString
-
send a make Directory command
-
sizeOf: aFileName
-
send an SIZE (print size) command; return the size or nil
if the partner does not support the SIZE command
-
systemStatus
-
send a 'STAT' command to ask about the partner systems status.
Return a collection of status lines.
-
systemType
-
send a 'SYST' command to ask about the partner system
private - commands & responses
-
getResponseForPORTCommand
-
-
handleReplyCode: replyCode
-
-
handleReplyCodeOfPORTCommand: replyCode
-
private - connection setup
-
close
-
means: unknown
-
getInitialConnectResponse
-
-
login: userName password: passwordOrNil
-
login using userName and password.
After successful login, set transfer mode
-
openActiveDataConnection: mode for: command
-
open & retrieve a data connection.
Raise connectFailedSignal if data connection can't be established
-
openDataConnection: mode for: command
-
open & retrieve a data connection
-
openDataConnectionFor: command
-
open & retrieve a data connection
-
openPassiveDataConnection: mode for: command
-
open & retrieve a data connection.
Raise connectFailedSignal if data connection can't be established
-
performLoginSequence
-
login using userName and password iff userName is not nil.
This is invoked automatically by doConnect.
If userName is nil, manual login is required.
-
sendGoodByeCommand
-
-
setModeTo: mode
-
login/pwd/close:
|host ftpClient|
host := Dialog request:'host:' initialAnswer:'ftp.informatik.uni-stuttgart.de'.
ftpClient := FTPClient new.
ftpClient connectToHost:host.
ftpClient login:'anonymous' password:'foo@bar.com'.
Transcript showCR:(ftpClient pwd).
ftpClient close.
|
getting a list from some other machine:
|host ftp list|
host := Dialog request:'host:' initialAnswer:'ftp.informatik.uni-stuttgart.de'.
ftp := FTPClient new.
ftp connectTo:host user:'anonymous' password:'foo@bar.com'.
list := ftp list.
ftp close.
list do:[:line | Transcript showCR:line].
|
getting a list from some other machine (passive mode):
|host ftp list|
host := Dialog request:'host:' initialAnswer:'ftp.informatik.uni-stuttgart.de'.
ftp := FTPClient new.
ftp passiveMode:true.
ftp connectTo:host user:'anonymous' password:'foo@bar.com'.
list := ftp list.
ftp close.
list do:[:line | Transcript showCR:line].
|
getting list from some other machine:
|host user passwd fn ftp data|
host := Dialog request:'host:' initialAnswer:'localhost'.
user := Dialog request:'user:' initialAnswer:'anonymous'.
passwd := Dialog requestPassword:'password:'.
ftp := FTPClient new.
ftp connectTo:host user:user password:passwd.
data := ftp list.
ftp close.
data inspect.
|
on a special port:
|host port user passwd fn ftp data|
FTPClient verbose:true.
host := Dialog request:'host:' initialAnswer:'localhost'.
port := Dialog request:'port:' initialAnswer:(Socket portOfService:'ftp') printString.
port := Integer readFrom:port onError:nil.
user := Dialog request:'user:' initialAnswer:'anonymous'.
passwd := Dialog requestPassword:'password:'.
ftp := FTPClient new.
ftp connectTo:host port:port user:user password:passwd.
data := ftp list.
ftp close.
data inspect.
|
getting a (text) file from some other machine:
|host user passwd fn ftp data|
host := Dialog request:'host:' initialAnswer:'localhost'.
user := Dialog request:'user:' initialAnswer:'anonymous'.
passwd := Dialog requestPassword:'password:'.
fn := Dialog request:'file:'.
ftp := FTPClient new.
ftp connectTo:host user:user password:passwd.
data := ftp get:fn.
ftp close.
data asString inspect.
|
getting a (binary) file from some other machine:
|host user passwd fn ftp data|
host := Dialog request:'host:' initialAnswer:'localhost'.
user := Dialog request:'user:' initialAnswer:'anonymous'.
passwd := Dialog requestPassword:'password:'.
fn := Dialog request:'file:'.
ftp := FTPClient new.
ftp connectTo:host user:user password:passwd.
ftp binary.
data := ftp get:fn.
ftp close.
data inspect.
|
putting some data onto some other machine:
|host user passwd fn ftp data|
host := Dialog request:'host:' initialAnswer:'localhost'.
user := Dialog request:'user:' initialAnswer:'anonymous'.
passwd := Dialog requestPassword:'password:'.
fn := Dialog request:'local file:'.
ftp := FTPClient new.
ftp connectTo:host user:user password:passwd.
ftp binary.
data := ftp put:'hello world' as:'testfile'.
ftp close.
data inspect.
|
putting a (binary) file onto some other machine:
|host user passwd fn ftp data|
host := Dialog request:'host:' initialAnswer:'localhost'.
user := Dialog request:'user:' initialAnswer:'anonymous'.
passwd := Dialog requestPassword:'password:'.
fn := Dialog request:'local file:'.
ftp := FTPClient new.
ftp connectTo:host user:user password:passwd.
ftp binary.
data := ftp putFile:'Makefile' as:'testfile'.
ftp close.
data inspect.
|
handling errors:
|host ftp list|
host := Dialog request:'host:' initialAnswer:(OperatingSystem getHostName).
FTPClient ftpErrorSignal handle:[:ex |
self warn:('ftp error:\\' , ex signal errorString) withCRs
] do:[
ftp := FTPClient new.
ftp connectTo:host user:'anonymous'.
list := ftp list.
ftp close.
list do:[:line | Transcript showCR:line].
]
|
chdir & get a list from some other machine:
|ftp list|
FTPClient ftpErrorSignal handle:[:ex |
self warn:('ftp error:\\' , ex signal errorString) withCRs
] do:[
ftp := FTPClient new.
ftp connectTo:'aix' user:'anonymous'.
ftp cd:'/'.
list := ftp list.
ftp close.
list do:[:line | Transcript showCR:line].
]
|
dialog with user & password:
|ftp dlg hostHolder userHolder passHolder list|
hostHolder := OperatingSystem getHostName asValue.
userHolder := OperatingSystem getLoginName asValue.
passHolder := '' asValue.
dlg := DialogBox new.
dlg addTextLabel:'host:'.
dlg addInputFieldOn:hostHolder tabable:true.
dlg addTextLabel:'user:'.
dlg addInputFieldOn:userHolder tabable:true.
dlg addTextLabel:'password:'.
(dlg addInputFieldOn:passHolder tabable:true) passwordCharacter:$*.
dlg addAbortButton; addOkButton.
dlg open.
dlg accepted ifTrue:[
FTPClient ftpErrorSignal handle:[:ex |
self warn:('ftp error:\\' , ex signal errorString) withCRs
] do:[
ftp := FTPClient new.
ftp connectTo:hostHolder value
user:userHolder value
password:passHolder value.
ftp cd:'/'.
list := ftp list.
ftp close.
list do:[:line | Transcript showCR:line].
]
]
|
|host port user passwd fn ftp data|
FTPClient verbose:true.
host := 'data'.
port := 12345.
user := 'anonymous'.
passwd := nil.
ftp := FTPClient new.
ftp connectTo:host port:port user:user password:passwd.
ftp ascii.
data := ftp list.
ftp close.
data inspect.
|
|host port user passwd fn ftp data|
FTPClient verbose:true.
host := 'data'.
port := 12345.
user := 'anonymous'.
passwd := nil.
ftp := FTPClient new.
ftp connectTo:host port:port user:user password:passwd.
ftp ascii.
data := ftp list.
ftp close.
data inspect.
|
|