name.gries
Class Ftp

java.lang.Object
  extended by name.gries.Ftp

public class Ftp
extends java.lang.Object


Field Summary
private static int CNTRL_PORT
           
private  javax.microedition.io.StreamConnection csock
           
private  java.io.InputStreamReader dcis
           
private  boolean DEBUG
           
private  javax.microedition.io.StreamConnection dsock
           
private  boolean pauser
           
private  java.io.PrintStream pos
           
 
Constructor Summary
Ftp(java.lang.String server, java.lang.String user, java.lang.String pass)
          ftp - default constructor
 
Method Summary
private  java.lang.String bufferReader()
          bufferReader() Method read the response of ftp commands until a \r \n.
 void download(java.lang.String dir, java.lang.String file, boolean asc)
          download() Method send a command to the ftp server
private  void ftpConnect(java.lang.String server)
          ftpConnect() Methode open a Connection to the specified server on standard ftp port 21
private  javax.microedition.io.StreamConnection ftpGetDataSock()
          ftpGetDataSock() Methode to create a data connection to the ftp server
private  void ftpLogin(java.lang.String user, java.lang.String pass)
          ftpLogin() Methode for login
private  void ftpLogout()
          ftpLogout() Method lgout from the ftp server and close all streams and sockets
private  java.lang.String ftpSendCmd(java.lang.String cmd)
          ftpSendCmd() Method send a command to the ftp server
private  void ftpSetDir(java.lang.String dir)
          ftpSetDir() Methode for changing directories
private  void ftpSetTransferType(boolean asc)
          ftpSetTransferType() Methode to set the transfer type
private  void getAsByte(java.io.InputStream is, java.lang.String file)
          getAsByte() Methode receive a file and stores the file in the flash file system
private  void readFileAndUpload(java.io.DataOutputStream dos, java.lang.String file)
          readFileAndUpload() Methode read a file and write it to the DataOutputStream.
private  java.lang.String responseHandler(java.lang.String cmd)
          responseHandler() Method handle the multi-line replies, if more than one line returned
private  java.lang.String responseParser(java.lang.String resp)
          responseParser() Method check first digit of first line of response and take action based on it set up to read an extra line if the response starts with "1"
 void upload(java.lang.String dir, java.lang.String file, boolean asc)
          upload() Method send a command to the ftp server
 void uploadAppend(java.lang.String dir, java.lang.String file, boolean asc)
          upload() Method send a command to the ftp server
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CNTRL_PORT

private static final int CNTRL_PORT
See Also:
Constant Field Values

csock

private javax.microedition.io.StreamConnection csock

dsock

private javax.microedition.io.StreamConnection dsock

dcis

private java.io.InputStreamReader dcis

pos

private java.io.PrintStream pos

DEBUG

private boolean DEBUG

pauser

private boolean pauser
Constructor Detail

Ftp

public Ftp(java.lang.String server,
           java.lang.String user,
           java.lang.String pass)
ftp - default constructor

Parameters:
server - servername
user - username
pass - password
Method Detail

download

public void download(java.lang.String dir,
                     java.lang.String file,
                     boolean asc)
              throws java.io.IOException
download() Method send a command to the ftp server

Parameters:
dir - directory on the ftp server
file - filename of the destination file
asc - transfer type true is Asccii and false is Binary
Throws:
java.io.IOException

upload

public void upload(java.lang.String dir,
                   java.lang.String file,
                   boolean asc)
            throws java.io.IOException
upload() Method send a command to the ftp server

Parameters:
dir - directory on the ftp server
file - filename of the destination file
asc - transfer type true is Asccii and false is Binary
Throws:
java.io.IOException

uploadAppend

public void uploadAppend(java.lang.String dir,
                         java.lang.String file,
                         boolean asc)
                  throws java.io.IOException
upload() Method send a command to the ftp server

Parameters:
dir - directory on the ftp server
file - filename of the destination file
asc - transfer type true is Ascci and false is Binary
Throws:
java.io.IOException

readFileAndUpload

private void readFileAndUpload(java.io.DataOutputStream dos,
                               java.lang.String file)
                        throws java.io.IOException
readFileAndUpload() Methode read a file and write it to the DataOutputStream.

Parameters:
dos - DataOutputStream for sending the file to the server
file - file name for upload
Throws:
java.io.IOException

getAsByte

private void getAsByte(java.io.InputStream is,
                       java.lang.String file)
                throws java.io.IOException
getAsByte() Methode receive a file and stores the file in the flash file system

Parameters:
is - InputStream to get the file from the server
file - stores the data of the InputStream in the Flash under this file name
Throws:
java.io.IOException

ftpConnect

private void ftpConnect(java.lang.String server)
                 throws java.lang.InterruptedException,
                        java.io.IOException
ftpConnect() Methode open a Connection to the specified server on standard ftp port 21

Parameters:
server - server address
Throws:
java.lang.InterruptedException
java.io.IOException

ftpLogin

private void ftpLogin(java.lang.String user,
                      java.lang.String pass)
               throws java.lang.InterruptedException,
                      java.io.IOException
ftpLogin() Methode for login

Parameters:
user - user name of the ftp server
pass - password of the ftp server
Throws:
java.lang.InterruptedException
java.io.IOException

ftpSetDir

private void ftpSetDir(java.lang.String dir)
                throws java.io.IOException
ftpSetDir() Methode for changing directories

Parameters:
dir - destination path
Throws:
java.io.IOException

ftpSetTransferType

private void ftpSetTransferType(boolean asc)
                         throws java.io.IOException
ftpSetTransferType() Methode to set the transfer type

Parameters:
asc - Asccii (true) or Binarie Mode (false)
Throws:
java.io.IOException

ftpGetDataSock

private javax.microedition.io.StreamConnection ftpGetDataSock()
                                                       throws java.io.IOException
ftpGetDataSock() Methode to create a data connection to the ftp server

Returns:
The data connection to the ftp server
Throws:
java.io.IOException

ftpSendCmd

private java.lang.String ftpSendCmd(java.lang.String cmd)
                             throws java.io.IOException
ftpSendCmd() Method send a command to the ftp server

Parameters:
cmd - Ftp command
Returns:
The response of the ftp command
Throws:
java.io.IOException

responseHandler

private java.lang.String responseHandler(java.lang.String cmd)
                                  throws java.io.IOException
responseHandler() Method handle the multi-line replies, if more than one line returned

Parameters:
cmd - is a String command or null
Returns:
returns just the last line of a possibly multi-line response
Throws:
java.io.IOException

responseParser

private java.lang.String responseParser(java.lang.String resp)
                                 throws java.io.IOException
responseParser() Method check first digit of first line of response and take action based on it set up to read an extra line if the response starts with "1"

Parameters:
resp - is the respose of the ftp command
Returns:
the command if it ok
Throws:
java.io.IOException

ftpLogout

private void ftpLogout()
ftpLogout() Method lgout from the ftp server and close all streams and sockets


bufferReader

private java.lang.String bufferReader()
                               throws java.io.IOException
bufferReader() Method read the response of ftp commands until a \r \n.

Returns:
the response without CF CR.
Throws:
java.io.IOException