|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jftp.net.FtpConnection
All control transactions are made here. See doc/FtpDownload.java for examples and note that this class is event-driven and not Exception-based! You might want to take a look at ConnectionListener, too.
Field Summary | |
static java.lang.String |
ABOR
Internal abort command constant |
static java.lang.String |
ASCII
|
static java.lang.String |
BINARY
|
static java.lang.String |
BLOCKED
|
static java.lang.String |
COMPRESSED
|
static java.lang.String |
DOWNLOAD
Internal download constant |
static java.lang.String |
EBCDIC
|
boolean |
hasUploaded
Used to determine the type of transfer. |
static java.lang.String |
L8
|
static java.lang.String |
LIST
|
static java.lang.String |
LIST_DEFAULT
|
static java.lang.String |
STREAM
|
static java.lang.String |
UPLOAD
Internal upload constant |
boolean |
work
|
Constructor Summary | |
FtpConnection(java.lang.String host)
Create an instance with a given host |
|
FtpConnection(java.lang.String host,
int port,
java.lang.String initCWD)
Create an instance with a given host, port and initial remote working directory |
Method Summary | |
void |
abort()
Try to abort the transfer. |
void |
abortTransfer()
Abort the last spawned transfer. |
void |
addConnectionListener(ConnectionListener l)
Add a ConnectionListener. |
void |
ascii()
Tell server we want ascii data connections. |
void |
binary()
Tell server we want binary data connections. |
boolean |
cdup()
Change to the parent of the current working directory. |
boolean |
chdir(java.lang.String p)
Parses directory and does a chdir(). |
boolean |
chdirNoRefresh(java.lang.String p)
Parses directory and does a chdir(), but does not send an update signal |
boolean |
chdirRaw(java.lang.String dirName)
Change directory unparsed. |
void |
disconnect()
Disconnect from the server. |
int |
download(java.lang.String file)
Download a file or directory, block until finished. |
int |
exists(java.lang.String file)
Checks wheter a file exists. |
void |
fireActionFinished(FtpConnection con)
Transfer is done |
void |
fireConnectionFailed(FtpConnection con,
java.lang.String why)
We are not logged in for some reason |
void |
fireConnectionInitialized(FtpConnection con)
Connection is there and user logged in |
void |
fireDirectoryUpdate(FtpConnection con)
Remote directory has changed. |
void |
fireProgressUpdate(java.lang.String file,
java.lang.String type,
int bytes)
Progress update. |
java.lang.String |
getCachedPWD()
Returns current remote directory (cached) |
ConnectionHandler |
getConnectionHandler()
Return the ConnectionHandler. |
DataConnection |
getDataConnection()
Return the DataConnection. |
java.io.InputStream |
getDownloadInputStream(java.lang.String file)
Get download InputStream. |
java.lang.String |
getHost()
Return the host used. |
FtpTransfer |
getLastInitiatedTransfer()
Get the last FtpTransfer object spawned. |
java.lang.String |
getLine(java.lang.String until)
Reads the response until line found or error. |
java.lang.String |
getLine(java.lang.String[] until)
Reads the response until line found or error. |
java.lang.String |
getLocalPath()
Return the local working directory |
java.lang.String |
getOsType()
Try to determine the os-type. |
java.lang.String |
getPassword()
Return the password. |
int[] |
getPermissions(java.lang.String file)
Sort the permissions an return an array. |
int |
getPort()
Get the port. |
java.lang.String |
getPWD()
Get the current remote directory. |
java.lang.String |
getTypeNow()
Returns the type used. |
java.lang.String |
getUsername()
Return the username. |
int |
handleDownload(java.lang.String file)
Download a file or directory. |
int |
handleUpload(java.lang.String file)
Upload a file or directory. |
int |
handleUpload(java.lang.String file,
java.lang.String realName)
Upload a file or directory. |
boolean |
isConnected()
Check if login() was successful. |
void |
list(java.lang.String outfile)
List remote directory. |
int |
login(java.lang.String username,
java.lang.String password)
Connect to the server an log in. |
boolean |
mkdir(java.lang.String dirName)
Create a directory with the given name. |
java.lang.String |
mode(java.lang.String code)
Set mode manually. |
void |
modeBlocked()
Unsupported at this time. |
void |
modeCompressed()
|
void |
modeStream()
Set mode to Stream. |
void |
noop()
Do nothing, but flush buffers |
void |
pause(int time)
Waits a specified amount of time |
int |
removeFileOrDir(java.lang.String file)
Remove a remote file or directory. |
boolean |
rename(java.lang.String from,
java.lang.String to)
Moves or renames remote file. |
void |
sendRawCommand(java.lang.String cmd)
Execute a remote command. |
void |
setConnectionHandler(ConnectionHandler h)
Set the ConnectionHandler. |
void |
setConnectionListeners(java.util.Vector l)
Add a Vector of ConnectionListeners. |
boolean |
setLocalPath(java.lang.String newPath)
Set the local working directory |
java.lang.String[] |
sortLs(java.lang.String file)
Sort the filenames of the current working dir an return an array. |
java.lang.String[] |
sortSize(java.lang.String file)
Sort the filesizes an return an array. |
java.lang.String |
system()
This command is used to find out the type of operating system at the server. |
boolean |
type(java.lang.String code)
Set type (L8,I,A for example). |
int |
upload(java.lang.String file)
Upload a file or directory, block until finished. |
int |
upload(java.lang.String file,
java.io.InputStream in)
Upload from an InputStream, block until finished. |
int |
upload(java.lang.String file,
java.lang.String realName)
Upload and a file or directory under a given name, block until finished. |
int |
upload(java.lang.String file,
java.lang.String realName,
java.io.InputStream in)
Upload and a file or directory under a given name, block until finished. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DOWNLOAD
public static final java.lang.String UPLOAD
public static final java.lang.String ABOR
public static java.lang.String LIST_DEFAULT
public static java.lang.String LIST
public boolean hasUploaded
public boolean work
public static final java.lang.String ASCII
public static final java.lang.String BINARY
public static final java.lang.String EBCDIC
public static final java.lang.String L8
public static final java.lang.String STREAM
public static final java.lang.String BLOCKED
public static final java.lang.String COMPRESSED
Constructor Detail |
public FtpConnection(java.lang.String host)
host
- The host to connect topublic FtpConnection(java.lang.String host, int port, java.lang.String initCWD)
host
- The host to connect toport
- The port used for the control connection, usually 21initCWD
- The initial remote working directoryMethod Detail |
public int login(java.lang.String username, java.lang.String password)
username
- The usernamepassword
- The password
public java.lang.String[] sortSize(java.lang.String file)
sortSize
in interface BasicConnection
file
- The file containing the raw server listing, usually Settings.ls_out
public int[] getPermissions(java.lang.String file)
getPermissions
in interface BasicConnection
file
- The file containing the raw server listing, usually Settings.ls_out
public java.lang.String[] sortLs(java.lang.String file)
sortLs
in interface BasicConnection
file
- The file containing the raw server listing, usually Settings.ls_out
public java.lang.String getOsType()
public int handleDownload(java.lang.String file)
handleDownload
in interface BasicConnection
file
- The file to download
public int download(java.lang.String file)
download
in interface BasicConnection
file
- The file to download
public java.io.InputStream getDownloadInputStream(java.lang.String file)
getDownloadInputStream
in interface BasicConnection
file
- The file to download
public int handleUpload(java.lang.String file)
handleUpload
in interface BasicConnection
file
- The file to upload
public int handleUpload(java.lang.String file, java.lang.String realName)
file
- The file to uploadrealName
- The file to rename the uploaded file to
public int upload(java.lang.String file)
upload
in interface BasicConnection
file
- The file to upload
public int upload(java.lang.String file, java.lang.String realName)
file
- The file to uploadrealName
- The file to rename the uploaded file to
public int upload(java.lang.String file, java.io.InputStream in)
upload
in interface BasicConnection
file
- The file to uploadin
- InputStream to read from
public int upload(java.lang.String file, java.lang.String realName, java.io.InputStream in)
file
- The file to uploadrealName
- The file to rename the uploaded file toin
- InputStream to read from
public int removeFileOrDir(java.lang.String file)
removeFileOrDir
in interface BasicConnection
file
- The file to remove
public void disconnect()
disconnect
in interface BasicConnection
public void sendRawCommand(java.lang.String cmd)
sendRawCommand
in interface BasicConnection
cmd
- The raw command that is to be sent to the serverpublic java.lang.String getLine(java.lang.String until)
until
- The String the response line hast to start with, 2 for succesful return codes for examplepublic java.lang.String getLine(java.lang.String[] until)
public boolean isConnected()
isConnected
in interface BasicConnection
public java.lang.String getPWD()
getPWD
in interface BasicConnection
public java.lang.String getCachedPWD()
public boolean chdirRaw(java.lang.String dirName)
dirName
- The raw directory name
public boolean cdup()
cdup
in interface BasicConnection
public boolean mkdir(java.lang.String dirName)
mkdir
in interface BasicConnection
dirName
- The name of the directory to create
public void list(java.lang.String outfile) throws java.io.IOException
list
in interface BasicConnection
outfile
- The file to save the output to, usually Settings.ls_out
java.io.IOException
public boolean chdir(java.lang.String p)
chdir
in interface BasicConnection
public boolean chdirNoRefresh(java.lang.String p)
chdirNoRefresh
in interface BasicConnection
public void pause(int time)
time
- The time to sleep in millisecondspublic java.lang.String getLocalPath()
getLocalPath
in interface BasicConnection
public boolean setLocalPath(java.lang.String newPath)
setLocalPath
in interface BasicConnection
newPath
- The new local CWD
public int exists(java.lang.String file)
file
- the name of the file
public boolean rename(java.lang.String from, java.lang.String to)
from
- remote file to move or rename.to
- new file name.
true
if completed successfully; false
otherwise.public int getPort()
public void binary()
public void ascii()
public boolean type(java.lang.String code)
public java.lang.String getTypeNow()
public void noop()
public void abort()
public java.lang.String system()
public void modeStream()
public void modeBlocked()
public void modeCompressed()
public java.lang.String mode(java.lang.String code)
code
- The mode code wanted, I, A, L8 for example
public java.lang.String getHost()
public java.lang.String getUsername()
public java.lang.String getPassword()
public DataConnection getDataConnection()
public void addConnectionListener(ConnectionListener l)
addConnectionListener
in interface BasicConnection
l
- A ConnectionListener objectpublic void setConnectionListeners(java.util.Vector l)
setConnectionListeners
in interface BasicConnection
l
- A Vector containig ConnectionListener objectspublic void fireDirectoryUpdate(FtpConnection con)
con
- The FtpConnection calling the eventpublic void fireProgressUpdate(java.lang.String file, java.lang.String type, int bytes)
file
- The file transferredtype
- the type of event, DataConnection.GETDIR for examplebytes
- The number of bytes transferred so farpublic void fireConnectionInitialized(FtpConnection con)
con
- The FtpConnection calling the eventpublic void fireConnectionFailed(FtpConnection con, java.lang.String why)
con
- The FtpConnection calling the eventwhy
- The login() response codepublic void fireActionFinished(FtpConnection con)
con
- The FtpConnection calling the eventpublic ConnectionHandler getConnectionHandler()
public void setConnectionHandler(ConnectionHandler h)
h
- The connection handler that is to be used by this connectionpublic FtpTransfer getLastInitiatedTransfer()
public void abortTransfer()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |