GFFtp Class Documentation
Written in December 2003 by Gerd Feldkirch (mailto: gerd.feldkirch@t-online.de)
This class supplies methods for an FTP-Client.
If a method fails the return value is -1, otherwise it is 0.
The servers response code is alwaly stored in the member variable 'm_iResponse' as an integer.
The complete response string is stored in the meber variable 'm_saResponse' as a StringArray. An FTP-Server response can consist out of multiple lines.
Members
IPAddress m_IpCommand
Stores the ip-address and the port-number of the command socket.
TCPSocket m_TcpCommand
The command socket object.
IPAddress m_IpData
Stores the ip-address and the port-number of the data socket.
TCPSocket m_TcpData
int m_iEcho
If enabled all responses will be sent to stdout.
int m_iResponse
Stores the last response code.
StringArray m_saResponse
Stores the entire response.
Constructor
GFFtp()
Constructs a GFFtp object.
Connection methods
connect( String _HostName, int _Port, String _Username, String _Password )
This method connects to a server.
quit()
This command terminates a USER and if file transfer is not
in progress, the server closes the control connection. If
file transfer is in progress, the connection will remain
open for result response and the server will then close it.
Directory methods
cwd( String _Directory )
This command allows the user to work with a different
directory or dataset for file storage or retrieval without
altering his login or accounting information. Transfer
parameters are similarly unchanged. The argument is a
pathname specifying a directory or other system dependent
file group designator.
pwd()
This command causes the name of the current working
directory to be returned in the reply.
cdup()
This command is a special case of CWD, and is included to
simplify the implementation of programs for transferring
directory trees between operating systems having different
syntaxes for naming the parent directory.
mkd( String _Directory )
This command causes the directory specified in the pathname
to be created as a directory (if the pathname is absolute)
or as a subdirectory of the current working directory (if
the pathname is relative).
rmd( String _Directory
This command causes the directory specified in the pathname
to be removed as a directory (if the pathname is absolute)
or as a subdirectory of the current working directory (if
the pathname is relative).
list( String _Directory )
This command causes a list to be sent from the server to the
passive DTP. If the pathname specifies a directory or other
group of files, the server should transfer a list of files
in the specified directory. If the pathname specifies a
file then the server should send current information on the
file. A null argument implies the user's current working or
default directory.
nlst( String _Directory )
This command causes a directory listing to be sent from
server to user site. The pathname should specify a
directory or other system-specific file group descriptor; a
null argument implies the current directory. The server
will return a stream of names of files and no other
information. This command is intended to return information
that can be used by a program to further process the files
automatically. For example, in the implementation of a
"multiple get" function.
Transfer parameter methods
pasv()
This command requests the server-DTP to "listen" on a data
port (which is not its default data port) and to wait for a
connection rather than initiate one upon receipt of a
transfer command. The response to this command includes the
host and port address this server is listening on.
ascii()
Selects ASCII transfer mode.
binary()
Selects binary transfer mode.
File action methods
getFile( String _LocalFilename, String _RemoteFilename, int _iMode )
Gets a file from the server.
The '_iMode' argument specifies, weather the file should be resumed (F_RESUME) or overwitten (F_OVERWRITE) if it already exists.
getStream( Stream _Stream, String _RemoteFilename, int _iResumeOffset )
Gets a file from the server and writes it to a stream.
The '_iMode' argument specifies, weather the file should be resumed (F_RESUME) or completely transmitted (F_OVERWRITE).
putFile( String _RemoteFilename, String _LocalFilename )
Places a file on the server.
putStream( String _RemoteFilename, Stream _Stream )
Writes a stream into a file on the server.
putPakFile( String _RemoteFilename, String _LocalFilename )
Places a file out of a TKS-PakFile on the server.
move( String _SourceFilename, String _DestinationFilename )
Moves a file/directory on the server.
appendFile( String _RemoteFilename, String _LocalFilename )
Writes a file at the end of a file on the server.
appendStream( String _RemoteFilename, Stream _Stream )
Writes a stream at the end of a file on the server.
appendPakFile( String _RemoteFilename, String _PakFilename )
Writes a file in a TKS-PakFile at the end of a file on the server.
dele( String _Filename )
This command causes the file specified in the pathname to be
deleted at the server site.
abor()
This command tells the server to abort the previous FTP
service command and any associated transfer of data.
Informational methods
site()
This command is used by the server to provide services
specific to his system that are essential to file transfer
but not sufficiently universal to be included as commands in
the protocol.
stat()
This command shall cause a status response to be sent over
the control connection in the form of a reply.
syst()
This command is used to find out the type of operating
system at the server.
feat()
This command shall cause the server to send implemented features.
help( String _Command )
This command shall cause the server to send helpful
information regarding its implementation status over the
control connection to the user. The command may take an
argument (e.g., any command name) and return more specific
information as a response.
Miscellaneous methods
noop()
This command does not affect any parameters or previously
entered commands. It specifies no action other than that the
server send an OK reply.
Utility methods
print( String _String )
Send a string to the server.
readResponse()
Reads the complete server's response.
printResponse()
command( String _String )
Sends a command to the Server and reads the complete server's response.
Sample Application
module Main;
function main() {
GFFtp gfFtp; // create GFFtp object
if( gfFtp.connect( "127.0.0.1", 21, "username", "password" ) < 0 ) return; // connect to server
if( gfFtp.binary() ) < 0 ) return; // select binary transfer mode
if( gfFtp.putFile( "/Incoming/serverfile.zip", "localfile.zip" ) < 0 ) return; // upload file
if( gfFtp.cwd( "/Incoming" ) < 0 ) return; // change working directory
if( gfFtp.mkd( "Moved_Files" ) < 0 ) return; // create directory
if( gfFtp.move( "/Incoming/serverfile.zip", "/Incoming/Moved_Files/serverfile.zip" ) < 0 ) return; // move file
if( gfFtp.getFile( "localfile2.zip", "/Incoming/Moved_Files/serverfile.zip", F_RESUME ) < 0 ) return; // download file
gfFtp.quit(); // quit session
}