Package com.nt.udc.ndk.util
Class FtpSession
java.lang.Object
com.nt.udc.ndk.util.FtpSession
- All Implemented Interfaces:
FtpSupportIntf
Handles some common methods and variables that are used in a
single Ftp session.
-
Constructor Summary
ConstructorsConstructorDescriptionCreats an FtpSession object.FtpSession
(String host, int port, String login, String password, LoggerIfc l) Creates an FtpSession object with the given host, login and password.FtpSession
(String host, int port, String login, String password, LoggerIfc l, int timerDelay) Creates an FtpSession object with the given host, login and password and timer delay..FtpSession
(String host, String login, String password, LoggerIfc l) Creates an FtpSession object with the given host, login and password.FtpSession
(String host, String login, String password, LoggerIfc l, int timerDelay) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Changes the current working directory.boolean
Remove a file from the remote host.void
Disconnects from the remote servervoid
Enables local active mode for transfersvoid
Enables local passive mode for transfersboolean
Copy the remote file to the local file.getHost()
Returns the remote hostgetLogin()
Returns the login nameReturns the login passwordint
getPort()
long
Returns the timeout for FTP operationsgetTimestamp
(String remoteFile) gets the timestamp of the remote fileString[]
lists the directories in the current working directoryString[]
listDirectories
(String remotePath) lists the directories of the remote pathString[]
Returns the list of files in the current remote directory.String[]
Returns the list of files in the given remote directory.FtpItem[]
Returns the list of files in the current remote directory.FtpItem[]
Returns the list of files in the given remote directory.boolean
login()
Logs into the remote host, using the internally set ip address, login name and password.boolean
Logs into the remote host, using the given ip address, login name and password.boolean
logout()
Logs out from the remote serverboolean
Copy the local file to the remote file.pwd()
Returns the present working directory.boolean
renames files on a remote servervoid
Sets the transfer file type to ASCIIvoid
Sets the transfer file type to BINARYvoid
Sets the remote host.void
Sets the login name.void
setPassword
(String pw) Sets the login passwordvoid
setPort
(int port) void
setTimeout
(int timeout) Sets the timeout for FTP operations
-
Constructor Details
-
FtpSession
Creats an FtpSession object.- Parameters:
logger
- event logger
-
FtpSession
Creates an FtpSession object with the given host, login and password.- Parameters:
host
- remote host (ip or hostname)login
- login namepassword
- login passwordlogger
- event logger
-
FtpSession
-
FtpSession
Creates an FtpSession object with the given host, login and password.- Parameters:
host
- remote host (ip or hostname)port
- Ftp port number, default is 21login
- login namepassword
- login passwordlogger
- event logger
-
FtpSession
public FtpSession(String host, int port, String login, String password, LoggerIfc l, int timerDelay) Creates an FtpSession object with the given host, login and password and timer delay..- Parameters:
host
- remote host (ip or hostname)port
- Ftp port number, default is 21login
- login namepassword
- login passwordl
- logger interface of the nodetimerDelay
- the timeout value for ftp connection,transfer.
-
-
Method Details
-
setHost
Sets the remote host.- Parameters:
host
- remote host, as an ip address or name
-
setPort
public void setPort(int port) -
setLogin
Sets the login name.- Parameters:
login
- login name
-
setPassword
Sets the login password- Parameters:
pw
- login password
-
setBinaryFileType
public void setBinaryFileType()Sets the transfer file type to BINARY- Specified by:
setBinaryFileType
in interfaceFtpSupportIntf
-
setAsciiFileType
public void setAsciiFileType()Sets the transfer file type to ASCII- Specified by:
setAsciiFileType
in interfaceFtpSupportIntf
-
enableLocalActiveMode
public void enableLocalActiveMode()Enables local active mode for transfers -
enableLocalPassiveMode
public void enableLocalPassiveMode()Enables local passive mode for transfers -
setTimeout
public void setTimeout(int timeout) Sets the timeout for FTP operations- Parameters:
timeout
- - timeout interval in milliseconds
-
getHost
Returns the remote host- Specified by:
getHost
in interfaceFtpSupportIntf
- Returns:
- remote host name
-
getPort
public int getPort() -
getLogin
Returns the login name- Specified by:
getLogin
in interfaceFtpSupportIntf
- Returns:
- login name
-
getTimeout
public long getTimeout()Returns the timeout for FTP operations- Returns:
- timeout interval in milliseconds
-
getPassword
Returns the login password- Specified by:
getPassword
in interfaceFtpSupportIntf
- Returns:
- login password
-
login
Logs into the remote host, using the internally set ip address, login name and password.- Returns:
- true, if login is successful. false, otherwise.
- Throws:
IOException
-
login
Logs into the remote host, using the given ip address, login name and password.- Specified by:
login
in interfaceFtpSupportIntf
- Parameters:
ip
- remote ip addresslogin
- login namepassword
- login password- Returns:
- true, if login is successful. false, otherwise.
- Throws:
IOException
-
logout
Logs out from the remote server- Specified by:
logout
in interfaceFtpSupportIntf
- Throws:
IOException
-
disconnect
Disconnects from the remote server- Specified by:
disconnect
in interfaceFtpSupportIntf
- Throws:
IOException
-
get
Copy the remote file to the local file. One must set the appropriate file type before the get; the default is binary mode.- Specified by:
get
in interfaceFtpSupportIntf
- Parameters:
localFile
- Local file name.remoteFile
- Remote file name.- Returns:
- true, if get was successful.
- Throws:
IOException
-
put
Copy the local file to the remote file. One must set the appropriate file type before the get; the default is binary mode.- Specified by:
put
in interfaceFtpSupportIntf
- Parameters:
localFile
- Local file name.remoteFile
- Remote file name.- Returns:
- true, if get was successful.
- Throws:
IOException
-
delete
Remove a file from the remote host.- Specified by:
delete
in interfaceFtpSupportIntf
- Parameters:
fileName
- remote file pathname- Returns:
- true, if delete was successful
- Throws:
IOException
-
pwd
Returns the present working directory.- Specified by:
pwd
in interfaceFtpSupportIntf
- Returns:
- present working directory
- Throws:
IOException
-
cd
Changes the current working directory.- Specified by:
cd
in interfaceFtpSupportIntf
- Parameters:
remotePath
- new remote directory- Returns:
- present working directory
- Throws:
IOException
-
listFiles
Returns the list of files in the given remote directory.- Specified by:
listFiles
in interfaceFtpSupportIntf
- Parameters:
remotePath
- remote directory to list- Returns:
- list of files (null if no files found)
- Throws:
IOException
-
listFiles
Returns the list of files in the current remote directory.- Specified by:
listFiles
in interfaceFtpSupportIntf
- Returns:
- list of files (null if no files found)
- Throws:
IOException
-
listItems
Returns the list of files in the given remote directory.- Parameters:
remotePath
- remote directory to list- Returns:
- list of files (null if no files found)
- Throws:
IOException
-
listItems
Returns the list of files in the current remote directory.- Returns:
- list of files (null if no files found)
- Throws:
IOException
-
listDirectories
lists the directories in the current working directory- Returns:
- array of the directory names
- Throws:
IOException
-
listDirectories
lists the directories of the remote path- Specified by:
listDirectories
in interfaceFtpSupportIntf
- Parameters:
remotePath
- remote directory to list- Returns:
- array of the directory names
- Throws:
IOException
-
getTimestamp
gets the timestamp of the remote file- Specified by:
getTimestamp
in interfaceFtpSupportIntf
- Parameters:
remoteFile
- remote path for which to get timestamp- Returns:
- timestamp of the remote path
- Throws:
IOException
-
rename
renames files on a remote server- Specified by:
rename
in interfaceFtpSupportIntf
- Throws:
IOException
-