public class SftpSession extends java.lang.Object implements FtpSupportIntf
Constructor and Description |
---|
SftpSession(LoggerIfc logger)
Creats an FtpSession object.
|
SftpSession(java.lang.String host,
int port,
java.lang.String login,
java.lang.String password,
java.lang.String hostsFile,
LoggerIfc logger)
Creates an FtpSession object with the given host, login and
password.
|
SftpSession(java.lang.String host,
java.lang.String login,
java.lang.String password,
LoggerIfc logger)
Creates an FtpSession object with the given host, login and
password.
|
Modifier and Type | Method and Description |
---|---|
boolean |
cd(java.lang.String remotePath)
Changes the current working directory.
|
boolean |
delete(java.lang.String fileName)
Remove a file from the remote host.
|
void |
disconnect()
Disconnects from the remote server
|
boolean |
get(java.lang.String localFile,
java.lang.String remoteFile)
Copy the remote file to the local file.
|
java.lang.String |
getHost()
Returns the remote host
|
java.lang.String |
getLogin()
Returns the login name
|
java.lang.String |
getPassword()
Returns the login password
|
int |
getPort() |
long |
getTimeout()
Returns the timeout for FTP operations
|
java.util.Date |
getTimestamp(java.lang.String remotePath)
Returns the timestamp of the given remote path.
|
java.lang.String[] |
listDirectories(java.lang.String remotePath)
Returns the list of directories in the given remote directory.
|
java.lang.String[] |
listFiles()
Returns the list of files in the current remote directory.
|
java.lang.String[] |
listFiles(java.lang.String remotePath)
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 |
login(java.lang.String ip,
java.lang.String login,
java.lang.String password)
Logs into the remote host, using the given ip address, login name
and password.
|
boolean |
logout()
Logs out from the remote server
|
boolean |
put(java.lang.String localFile,
java.lang.String remoteFile)
Copy the local file to the remote file.
|
java.lang.String |
pwd()
Returns the present working directory.
|
boolean |
rename(java.lang.String from,
java.lang.String to)
renames files on a remote server
|
void |
setAsciiFileType()
Sets the transfer file type to ASCII
|
void |
setBinaryFileType()
Sets the transfer file type to BINARY
|
void |
setHost(java.lang.String host)
Sets the remote host.
|
void |
setLogin(java.lang.String login)
Sets the login name.
|
void |
setPassword(java.lang.String pw)
Sets the login password
|
void |
setPort(int port) |
void |
setTimeout(long timeout)
Sets the timeout for FTP operations
|
public SftpSession(LoggerIfc logger)
logger
- event loggerpublic SftpSession(java.lang.String host, java.lang.String login, java.lang.String password, LoggerIfc logger)
host
- remote host (ip or hostname)login
- login namepassword
- login passwordlogger
- event loggerpublic SftpSession(java.lang.String host, int port, java.lang.String login, java.lang.String password, java.lang.String hostsFile, LoggerIfc logger)
host
- remote host (ip or hostname)port
- Ftp port number, default is 22 for SFTPlogin
- login namepassword
- login passwordhostsFile
- Hosts filelogger
- event loggerpublic void setBinaryFileType()
setBinaryFileType
in interface FtpSupportIntf
public void setAsciiFileType()
setAsciiFileType
in interface FtpSupportIntf
public void setHost(java.lang.String host)
host
- remote host, as an ip address or namepublic void setPort(int port)
public void setLogin(java.lang.String login)
login
- login namepublic void setPassword(java.lang.String pw)
pw
- login passwordpublic void setTimeout(long timeout)
timeout
- - timeout interval in millisecondspublic java.lang.String getHost()
getHost
in interface FtpSupportIntf
public int getPort()
public java.lang.String getLogin()
getLogin
in interface FtpSupportIntf
public long getTimeout()
public java.lang.String getPassword()
getPassword
in interface FtpSupportIntf
public boolean login() throws java.io.IOException
java.io.IOException
public boolean login(java.lang.String ip, java.lang.String login, java.lang.String password) throws java.io.IOException
login
in interface FtpSupportIntf
ip
- remote ip addresslogin
- login namepassword
- login password
java.io.IOException
public boolean logout() throws java.io.IOException
logout
in interface FtpSupportIntf
java.io.IOException
public void disconnect() throws java.io.IOException
disconnect
in interface FtpSupportIntf
java.io.IOException
public boolean get(java.lang.String localFile, java.lang.String remoteFile) throws java.io.IOException
get
in interface FtpSupportIntf
localFile
- Local file name.remoteFile
- Remote file name.
java.io.IOException
public boolean put(java.lang.String localFile, java.lang.String remoteFile) throws java.io.IOException
put
in interface FtpSupportIntf
localFile
- Local file name.remoteFile
- Remote file name.
java.io.IOException
public boolean delete(java.lang.String fileName) throws java.io.IOException
delete
in interface FtpSupportIntf
fileName
- remote file pathnamejava.io.IOException
public java.lang.String pwd() throws java.io.IOException
pwd
in interface FtpSupportIntf
java.io.IOException
public boolean cd(java.lang.String remotePath) throws java.io.IOException
cd
in interface FtpSupportIntf
remotePath
- new remote directoryjava.io.IOException
public java.lang.String[] listFiles(java.lang.String remotePath) throws java.io.IOException
listFiles
in interface FtpSupportIntf
remotePath
- remote directory to listjava.io.IOException
public java.lang.String[] listFiles() throws java.io.IOException
listFiles
in interface FtpSupportIntf
java.io.IOException
public java.lang.String[] listDirectories(java.lang.String remotePath) throws java.io.IOException
listDirectories
in interface FtpSupportIntf
remotePath
- remote directory to listjava.io.IOException
public java.util.Date getTimestamp(java.lang.String remotePath) throws java.io.IOException
getTimestamp
in interface FtpSupportIntf
remotePath
- remote path for which to get timestampjava.io.IOException
public boolean rename(java.lang.String from, java.lang.String to) throws java.io.IOException
rename
in interface FtpSupportIntf
java.io.IOException