public class SFTPClientImpl extends AFTPClient
FILE_TYPE_BINARY, FILE_TYPE_TEXT
Modifier and Type | Method and Description |
---|---|
boolean |
changeWorkingDirectory(String pathname)
Change the current working directory of the FTP session.
|
void |
connect()
Opens a Socket connected to a remote host at the specified port and
originating from the current host at a system assigned port.
|
boolean |
deleteFile(String pathname)
Deletes a file on the FTP server.
|
boolean |
directoryExists(String pathname) |
void |
disconnect()
Closes the connection to the FTP server and restores
connection parameters to the default values.
|
void |
enterLocalActiveMode()
Set the current data connection mode to
ACTIVE_LOCAL_DATA_CONNECTION_MODE . |
void |
enterLocalPassiveMode()
Set the current data connection mode to
PASSIVE_LOCAL_DATA_CONNECTION_MODE . |
int |
getDataConnectionMode()
Returns the current data connection mode (one of the
_DATA_CONNECTION_MODE constants. |
String |
getPrefix() |
InetAddress |
getRemoteAddress() |
int |
getReplyCode()
Returns the integer value of the reply code of the last FTP reply.
|
String |
getReplyString()
Returns the entire text of the last FTP server response exactly
as it was received, including all end of line markers in NETASCII
format.
|
void |
init(InetAddress host,
int port,
String username,
String password,
String fingerprint,
boolean stopOnError) |
boolean |
isConnected()
Returns true if the client is currently connected to a server.
|
boolean |
isPositiveCompletion()
Determine if a reply code is a positive completion response.
|
org.apache.commons.net.ftp.FTPFile[] |
listFiles(String pathname)
Using the default system autodetect mechanism, obtain a
list of file information for the current working directory
or for just a single file.
|
static void |
main(String[] args) |
boolean |
makeDirectory(String pathname)
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).
|
String |
printWorkingDirectory()
Returns the pathname of the current working directory.
|
int |
quit()
A convenience method to send the FTP QUIT command to the server,
receive the reply, and return the reply code.
|
boolean |
removeDirectory(String pathname)
Removes a directory on the FTP server (if empty).
|
boolean |
rename(String from,
String to)
Renames a remote file.
|
boolean |
retrieveFile(String remote,
OutputStream local)
Retrieves a named file from the server and writes it to the given
OutputStream.
|
boolean |
setFileType(int fileType)
Sets the file type to be transferred.
|
void |
setTimeout(int timeout)
timeout in milli seconds
|
boolean |
storeFile(String remote,
InputStream local)
Stores a file on the server using the given name and taking input
from the given InputStream.
|
getInstance
public void init(InetAddress host, int port, String username, String password, String fingerprint, boolean stopOnError) throws SocketException, IOException
init
in class AFTPClient
SocketException
IOException
public void connect() throws SocketException, IOException
AFTPClient
_connectAction_()
is called to perform connection initialization actions.
connect
in class AFTPClient
SocketException
- If the socket timeout could not be set.IOException
- If the socket could not be opened. In most
cases you will only want to catch IOException since SocketException is
derived from it.public static void main(String[] args) throws SocketException, IOException
SocketException
IOException
public boolean rename(String from, String to) throws IOException
AFTPClient
rename
in class AFTPClient
from
- The name of the remote file to rename.to
- The new name of the remote file.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean removeDirectory(String pathname) throws IOException
AFTPClient
removeDirectory
in class AFTPClient
pathname
- The pathname of the directory to remove.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean makeDirectory(String pathname) throws IOException
AFTPClient
makeDirectory
in class AFTPClient
pathname
- The pathname of the directory to create.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean directoryExists(String pathname) throws IOException
directoryExists
in class AFTPClient
IOException
public boolean changeWorkingDirectory(String pathname) throws IOException
AFTPClient
changeWorkingDirectory
in class AFTPClient
pathname
- The new current working directory.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public String printWorkingDirectory() throws IOException
AFTPClient
printWorkingDirectory
in class AFTPClient
IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean deleteFile(String pathname) throws IOException
AFTPClient
deleteFile
in class AFTPClient
pathname
- The pathname of the file to be deleted.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean retrieveFile(String remote, OutputStream local) throws IOException
AFTPClient
Note: if you have used #setRestartOffset(long)
,
the file data will start from the selected offset.
retrieveFile
in class AFTPClient
remote
- The name of the remote file.local
- The local OutputStream to which to write the file.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean storeFile(String remote, InputStream local) throws IOException
AFTPClient
storeFile
in class AFTPClient
remote
- The name to give the remote file.local
- The local InputStream from which to read the file.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public int getReplyCode()
AFTPClient
connect
is of type void.
getReplyCode
in class AFTPClient
public String getReplyString()
AFTPClient
getReplyString
in class AFTPClient
public org.apache.commons.net.ftp.FTPFile[] listFiles(String pathname) throws IOException
AFTPClient
This information is obtained through the LIST command. The contents of
the returned array is determined by the FTPFileEntryParser
used.
listFiles
in class AFTPClient
pathname
- The file or directory to list. Since the server may
or may not expand glob expressions, using them here
is not recommended and may well cause this method to
fail.
Also, some servers treat a leading '-' as being an option.
To avoid this interpretation, use an absolute pathname
or prefix the pathname with ./ (unix style servers).
Some servers may support "--" as meaning end of options,
in which case "-- -xyz" should work.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply
from the server.public boolean setFileType(int fileType) throws IOException
AFTPClient
FTP.ASCII_FILE_TYPE
, FTP.BINARY_FILE_TYPE
,
etc. The file type only needs to be set when you want to change the
type. After changing it, the new type stays in effect until you change
it again. The default file type is FTP.ASCII_FILE_TYPE
if this method is never called.
N.B. currently calling any connect method will reset the type to FTP.ASCII_FILE_TYPE.
setFileType
in class AFTPClient
fileType
- The _FILE_TYPE
constant indcating the
type of file.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public String getPrefix()
getPrefix
in class AFTPClient
public InetAddress getRemoteAddress()
getRemoteAddress
in class AFTPClient
Socket.getInetAddress()
public boolean isConnected()
AFTPClient
Delegates to Socket.isConnected()
isConnected
in class AFTPClient
public int quit() throws IOException
AFTPClient
quit
in class AFTPClient
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public void disconnect() throws IOException
AFTPClient
disconnect
in class AFTPClient
IOException
- If an error occurs while disconnecting.public void setTimeout(int timeout)
AFTPClient
setTimeout
in class AFTPClient
public int getDataConnectionMode()
AFTPClient
_DATA_CONNECTION_MODE
constants.
getDataConnectionMode
in class AFTPClient
_DATA_CONNECTION_MODE
constants.public void enterLocalPassiveMode()
AFTPClient
PASSIVE_LOCAL_DATA_CONNECTION_MODE
. Use this
method only for data transfers between the client and server.
This method causes a PASV (or EPSV) command to be issued to the server
before the opening of every data connection, telling the server to
open a data port to which the client will connect to conduct
data transfers. The FTPClient will stay in
PASSIVE_LOCAL_DATA_CONNECTION_MODE
until the
mode is changed by calling some other method such as
enterLocalActiveMode()
N.B. currently calling any connect method will reset the mode to ACTIVE_LOCAL_DATA_CONNECTION_MODE.
enterLocalPassiveMode
in class AFTPClient
public void enterLocalActiveMode()
AFTPClient
ACTIVE_LOCAL_DATA_CONNECTION_MODE
. No communication
with the FTP server is conducted, but this causes all future data
transfers to require the FTP server to connect to the client's
data port. Additionally, to accommodate differences between socket
implementations on different platforms, this method causes the
client to issue a PORT command before every data transfer.enterLocalActiveMode
in class AFTPClient
public boolean isPositiveCompletion()
AFTPClient
isPositiveCompletion
in class AFTPClient
Copyright © 2015 Lucee