|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sshtools.j2ssh.SftpClient
public class SftpClient
Implements a Secure File Transfer (SFTP) client.
Method Summary | |
---|---|
void |
addEventListener(ChannelEventListener eventListener)
|
void |
cd(java.lang.String dir)
Changes the working directory on the remote server. |
void |
chgrp(int gid,
java.lang.String path)
Sets the group ID for the file or directory. |
void |
chmod(int permissions,
java.lang.String path)
Changes the access permissions or modes of the specified file or directory. |
void |
chown(int uid,
java.lang.String path)
Sets the user ID to owner for the file or directory. |
DirectoryOperation |
copyLocalDirectory(java.lang.String localdir,
java.lang.String remotedir,
boolean recurse,
boolean sync,
boolean commit,
FileTransferProgress progress)
|
DirectoryOperation |
copyRemoteDirectory(java.lang.String remotedir,
java.lang.String localdir,
boolean recurse,
boolean sync,
boolean commit,
FileTransferProgress progress)
|
FileAttributes |
get(java.lang.String path)
|
FileAttributes |
get(java.lang.String path,
FileTransferProgress progress)
Download the remote file to the local computer. |
FileAttributes |
get(java.lang.String remote,
java.io.OutputStream local)
|
FileAttributes |
get(java.lang.String remote,
java.io.OutputStream local,
FileTransferProgress progress)
Download the remote file writing it to the specified OutputStream . |
FileAttributes |
get(java.lang.String remote,
java.lang.String local)
|
FileAttributes |
get(java.lang.String remote,
java.lang.String local,
FileTransferProgress progress)
Download the remote file to the local computer. |
java.lang.String |
getAbsolutePath(java.lang.String path)
|
boolean |
isClosed()
Returns the state of the SFTP client. |
void |
lcd(java.lang.String path)
Changes the local working directory. |
java.lang.String |
lpwd()
Returns the absolute path to the local working directory. |
java.util.List |
ls()
List the contents of the current remote working directory. |
java.util.List |
ls(java.lang.String path)
List the contents remote directory. |
void |
mkdir(java.lang.String dir)
Creates a new directory on the remote server. |
void |
mkdirs(java.lang.String dir)
Create a directory or set of directories. |
void |
put(java.io.InputStream in,
java.lang.String remote)
|
void |
put(java.io.InputStream in,
java.lang.String remote,
FileTransferProgress progress)
Upload a file to the remote computer reading from the specified
InputStream . |
void |
put(java.lang.String local)
|
void |
put(java.lang.String local,
FileTransferProgress progress)
Upload a file to the remote computer. |
void |
put(java.lang.String local,
java.lang.String remote)
|
void |
put(java.lang.String local,
java.lang.String remote,
FileTransferProgress progress)
Upload a file to the remote computer. |
java.lang.String |
pwd()
Returns the absolute path name of the current remote working directory. |
void |
quit()
Close the SFTP client. |
void |
rename(java.lang.String oldpath,
java.lang.String newpath)
Rename a file on the remote computer. |
void |
rm(java.lang.String path)
Remove a file or directory from the remote computer. |
void |
rm(java.lang.String path,
boolean force,
boolean recurse)
|
FileAttributes |
stat(java.lang.String path)
Returns the attributes of the file from the remote computer. |
void |
symlink(java.lang.String path,
java.lang.String link)
Create a symbolic link on the remote computer. |
int |
umask(int umask)
Sets the umask used by this client. |
void |
umask(java.lang.String umask)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public int umask(int umask)
umask
-
public void cd(java.lang.String dir) throws java.io.IOException
Changes the working directory on the remote server.
dir
- the new working directory
java.io.IOException
- if an IO error occurs or the file does not exist
java.io.FileNotFoundException
public void mkdir(java.lang.String dir) throws java.io.IOException
Creates a new directory on the remote server. This method will throw an
exception if the directory already exists. To create directories and
disregard any errors use the mkdirs
method.
dir
- the name of the new directory
java.io.IOException
- if an IO error occurs or if the directory already
existspublic void mkdirs(java.lang.String dir)
Create a directory or set of directories. This method will not fail even
if the directories exist. It is advisable to test whether the directory
exists before attempting an operation by using the stat
method to return the directories attributes.
dir
- the path of directories to create.public java.lang.String pwd()
Returns the absolute path name of the current remote working directory.
public java.util.List ls() throws java.io.IOException
List the contents of the current remote working directory.
Returns a list of SftpFile
instances for the current
working directory.
java.io.IOException
- if an IO error occursSftpFile
public java.util.List ls(java.lang.String path) throws java.io.IOException
List the contents remote directory.
Returns a list of SftpFile
instances for the remote
directory.
path
- the path on the remote server to list
java.io.IOException
- if an IO error occursSftpFile
public void lcd(java.lang.String path) throws java.io.IOException
Changes the local working directory.
path
- the path to the new working directory
java.io.IOException
- if an IO error occurspublic java.lang.String lpwd()
Returns the absolute path to the local working directory.
public FileAttributes get(java.lang.String path, FileTransferProgress progress) throws java.io.IOException, TransferCancelledException
Download the remote file to the local computer.
path
- the path to the remote fileprogress
-
java.io.IOException
- if an IO error occurs of the file does not exist
TransferCancelledException
public FileAttributes get(java.lang.String path) throws java.io.IOException
path
-
java.io.IOException
public FileAttributes get(java.lang.String remote, java.lang.String local, FileTransferProgress progress) throws java.io.IOException, TransferCancelledException
Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.
remote
- the path/name of the remote filelocal
- the path/name to place the file on the local computerprogress
-
java.io.IOException
- if an IO error occurs or the file does not exist
TransferCancelledException
public FileAttributes get(java.lang.String remote, java.lang.String local) throws java.io.IOException
remote
- local
-
java.io.IOException
public FileAttributes get(java.lang.String remote, java.io.OutputStream local, FileTransferProgress progress) throws java.io.IOException, TransferCancelledException
Download the remote file writing it to the specified
OutputStream
. The OutputStream is closed by this mehtod
even if the operation fails.
remote
- the path/name of the remote filelocal
- the OutputStream to writeprogress
-
java.io.IOException
- if an IO error occurs or the file does not exist
TransferCancelledException
public FileAttributes get(java.lang.String remote, java.io.OutputStream local) throws java.io.IOException
remote
- local
-
java.io.IOException
public boolean isClosed()
Returns the state of the SFTP client. The client is closed if the
underlying session channel is closed. Invoking the quit
method of this object will close the underlying session channel.
public void put(java.lang.String local, FileTransferProgress progress) throws java.io.IOException, TransferCancelledException
Upload a file to the remote computer.
local
- the path/name of the local fileprogress
-
java.io.IOException
- if an IO error occurs or the file does not exist
TransferCancelledException
public void put(java.lang.String local) throws java.io.IOException
local
-
java.io.IOException
public void put(java.lang.String local, java.lang.String remote, FileTransferProgress progress) throws java.io.IOException, TransferCancelledException
Upload a file to the remote computer. If the paths provided are not absolute the current working directory is used.
local
- the path/name of the local fileremote
- the path/name of the destination fileprogress
-
java.io.IOException
- if an IO error occurs or the file does not exist
TransferCancelledException
public void put(java.lang.String local, java.lang.String remote) throws java.io.IOException
local
- remote
-
java.io.IOException
public void put(java.io.InputStream in, java.lang.String remote, FileTransferProgress progress) throws java.io.IOException, TransferCancelledException
Upload a file to the remote computer reading from the specified
InputStream
. The InputStream is closed, even if the operation
fails.
in
- the InputStream being readremote
- the path/name of the destination fileprogress
-
java.io.IOException
- if an IO error occurs
TransferCancelledException
public void put(java.io.InputStream in, java.lang.String remote) throws java.io.IOException
in
- remote
-
java.io.IOException
public void chown(int uid, java.lang.String path) throws java.io.IOException
Sets the user ID to owner for the file or directory.
uid
- numeric user id of the new ownerpath
- the path to the remote file/directory
java.io.IOException
- if an IO error occurs or the file does not existpublic void chgrp(int gid, java.lang.String path) throws java.io.IOException
Sets the group ID for the file or directory.
gid
- the numeric group id for the new grouppath
- the path to the remote file/directory
java.io.IOException
- if an IO error occurs or the file does not existpublic void chmod(int permissions, java.lang.String path) throws java.io.IOException
Changes the access permissions or modes of the specified file or directory.
Modes determine who can read, change or execute a file.
Absolute modes are octal numbers specifying the complete list of attributes for the files; you specify attributes by OR'ing together these bits. 0400 Individual read 0200 Individual write 0100 Individual execute (or list directory) 0040 Group read 0020 Group write 0010 Group execute 0004 Other read 0002 Other write 0001 Other execute
permissions
- the absolute mode of the file/directorypath
- the path to the file/directory on the remote server
java.io.IOException
- if an IO error occurs or the file if not foundpublic void umask(java.lang.String umask) throws java.io.IOException
java.io.IOException
public void rename(java.lang.String oldpath, java.lang.String newpath) throws java.io.IOException
Rename a file on the remote computer.
oldpath
- the old pathnewpath
- the new path
java.io.IOException
- if an IO error occurspublic void rm(java.lang.String path) throws java.io.IOException
Remove a file or directory from the remote computer.
path
- the path of the remote file/directory
java.io.IOException
- if an IO error occurspublic void rm(java.lang.String path, boolean force, boolean recurse) throws java.io.IOException
path
- force
- recurse
-
java.io.IOException
public void symlink(java.lang.String path, java.lang.String link) throws java.io.IOException
Create a symbolic link on the remote computer.
path
- the path to the existing filelink
- the new link
java.io.IOException
- if an IO error occurs or the operation is not
supported on the remote platformpublic FileAttributes stat(java.lang.String path) throws java.io.IOException
Returns the attributes of the file from the remote computer.
path
- the path of the file on the remote computer
java.io.IOException
- if an IO error occurs or the file does not existFileAttributes
public java.lang.String getAbsolutePath(java.lang.String path) throws java.io.IOException
path
-
java.io.IOException
public void quit() throws java.io.IOException
Close the SFTP client.
java.io.IOException
public DirectoryOperation copyLocalDirectory(java.lang.String localdir, java.lang.String remotedir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) throws java.io.IOException
localdir
- remotedir
- recurse
- sync
- commit
- progress
-
java.io.IOException
public void addEventListener(ChannelEventListener eventListener)
eventListener
- public DirectoryOperation copyRemoteDirectory(java.lang.String remotedir, java.lang.String localdir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) throws java.io.IOException
remotedir
- localdir
- recurse
- sync
- commit
- progress
-
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |