public class SCPClient
extends java.lang.Object
SCPClient
that can be used to copy files from/to
the SSH-2 server. On the server side, the "scp" program must be in the PATH.
This scp client is thread safe - you can download (and upload) different sets
of files concurrently without any troubles. The SCPClient
is
actually mapping every request to a distinct Session
.
Modifier and Type | Class and Description |
---|---|
(package private) class |
SCPClient.LenNamePair |
Modifier and Type | Field and Description |
---|---|
(package private) Connection |
conn |
Constructor and Description |
---|
SCPClient(Connection conn) |
Modifier and Type | Method and Description |
---|---|
private void |
get(java.lang.String[] remoteFiles,
java.io.OutputStream[] targets) |
void |
get(java.lang.String[] remoteFiles,
java.lang.String localTargetDirectory)
Download a set of files from the remote server to a local directory.
|
void |
get(java.lang.String remoteFile,
java.io.OutputStream target)
Download a file from the remote server and pipe its contents into an
OutputStream . |
void |
get(java.lang.String remoteFile,
java.lang.String localTargetDirectory)
Download a file from the remote server to a local directory.
|
private SCPClient.LenNamePair |
parseCLine(java.lang.String line) |
void |
put(byte[] data,
java.lang.String remoteFileName,
java.lang.String remoteTargetDirectory)
Create a remote file and copy the contents of the passed byte array into
it.
|
void |
put(byte[] data,
java.lang.String remoteFileName,
java.lang.String remoteTargetDirectory,
java.lang.String mode)
Create a remote file and copy the contents of the passed byte array into
it.
|
void |
put(java.lang.String[] localFiles,
java.lang.String remoteTargetDirectory)
Copy a set of local files to a remote directory, uses mode 0600 when
creating files on the remote side.
|
void |
put(java.lang.String[] localFiles,
java.lang.String[] remoteFiles,
java.lang.String remoteTargetDirectory,
java.lang.String mode) |
void |
put(java.lang.String[] localFiles,
java.lang.String remoteTargetDirectory,
java.lang.String mode)
Copy a set of local files to a remote directory, uses the specified mode
when creating the files on the remote side.
|
void |
put(java.lang.String localFile,
java.lang.String remoteTargetDirectory)
Copy a local file to a remote directory, uses mode 0600 when creating the
file on the remote side.
|
void |
put(java.lang.String localFile,
java.lang.String remoteTargetDirectory,
java.lang.String mode)
Copy a local file to a remote directory, uses the specified mode when
creating the file on the remote side.
|
void |
put(java.lang.String localFile,
java.lang.String remoteFileName,
java.lang.String remoteTargetDirectory,
java.lang.String mode)
Copy a local file to a remote directory, uses the specified mode and
remote filename when creating the file on the remote side.
|
private void |
readResponse(java.io.InputStream is) |
private void |
receiveFiles(Session sess,
java.io.OutputStream[] targets) |
private void |
receiveFiles(Session sess,
java.lang.String[] files,
java.lang.String target) |
private java.lang.String |
receiveLine(java.io.InputStream is) |
private void |
sendBytes(Session sess,
byte[] data,
java.lang.String fileName,
java.lang.String mode) |
private void |
sendFiles(Session sess,
java.lang.String[] files,
java.lang.String[] remoteFiles,
java.lang.String mode) |
Connection conn
public SCPClient(Connection conn)
private void readResponse(java.io.InputStream is) throws java.io.IOException
java.io.IOException
private java.lang.String receiveLine(java.io.InputStream is) throws java.io.IOException
java.io.IOException
private SCPClient.LenNamePair parseCLine(java.lang.String line) throws java.io.IOException
java.io.IOException
private void sendBytes(Session sess, byte[] data, java.lang.String fileName, java.lang.String mode) throws java.io.IOException
java.io.IOException
private void sendFiles(Session sess, java.lang.String[] files, java.lang.String[] remoteFiles, java.lang.String mode) throws java.io.IOException
java.io.IOException
private void receiveFiles(Session sess, java.io.OutputStream[] targets) throws java.io.IOException
java.io.IOException
private void receiveFiles(Session sess, java.lang.String[] files, java.lang.String target) throws java.io.IOException
java.io.IOException
public void put(java.lang.String localFile, java.lang.String remoteTargetDirectory) throws java.io.IOException
localFile
- Path and name of local file.remoteTargetDirectory
- Remote target directory. Use an empty string to specify the
default directory.java.io.IOException
public void put(java.lang.String[] localFiles, java.lang.String remoteTargetDirectory) throws java.io.IOException
localFiles
- Paths and names of local file names.remoteTargetDirectory
- Remote target directory. Use an empty string to specify the
default directory.java.io.IOException
public void put(java.lang.String localFile, java.lang.String remoteTargetDirectory, java.lang.String mode) throws java.io.IOException
localFile
- Path and name of local file.remoteTargetDirectory
- Remote target directory. Use an empty string to specify the
default directory.mode
- a four digit string (e.g., 0644, see "man chmod", "man open")java.io.IOException
public void put(java.lang.String localFile, java.lang.String remoteFileName, java.lang.String remoteTargetDirectory, java.lang.String mode) throws java.io.IOException
localFile
- Path and name of local file.remoteFileName
- The name of the file which will be created in the remote
target directory.remoteTargetDirectory
- Remote target directory. Use an empty string to specify the
default directory.mode
- a four digit string (e.g., 0644, see "man chmod", "man open")java.io.IOException
public void put(byte[] data, java.lang.String remoteFileName, java.lang.String remoteTargetDirectory) throws java.io.IOException
data
- the data to be copied into the remote file.remoteFileName
- The name of the file which will be created in the remote
target directory.remoteTargetDirectory
- Remote target directory. Use an empty string to specify the
default directory.java.io.IOException
public void put(byte[] data, java.lang.String remoteFileName, java.lang.String remoteTargetDirectory, java.lang.String mode) throws java.io.IOException
data
- the data to be copied into the remote file.remoteFileName
- The name of the file which will be created in the remote
target directory.remoteTargetDirectory
- Remote target directory. Use an empty string to specify the
default directory.mode
- a four digit string (e.g., 0644, see "man chmod", "man open")java.io.IOException
public void put(java.lang.String[] localFiles, java.lang.String remoteTargetDirectory, java.lang.String mode) throws java.io.IOException
localFiles
- Paths and names of the local files.remoteTargetDirectory
- Remote target directory. Use an empty string to specify the
default directory.mode
- a four digit string (e.g., 0644, see "man chmod", "man open")java.io.IOException
public void put(java.lang.String[] localFiles, java.lang.String[] remoteFiles, java.lang.String remoteTargetDirectory, java.lang.String mode) throws java.io.IOException
java.io.IOException
public void get(java.lang.String remoteFile, java.lang.String localTargetDirectory) throws java.io.IOException
remoteFile
- Path and name of the remote file.localTargetDirectory
- Local directory to put the downloaded file.java.io.IOException
public void get(java.lang.String remoteFile, java.io.OutputStream target) throws java.io.IOException
OutputStream
. Please note that, to enable flexible usage
of this method, the OutputStream
will not be closed nor
flushed.remoteFile
- Path and name of the remote file.target
- OutputStream where the contents of the file will be sent to.java.io.IOException
private void get(java.lang.String[] remoteFiles, java.io.OutputStream[] targets) throws java.io.IOException
java.io.IOException
public void get(java.lang.String[] remoteFiles, java.lang.String localTargetDirectory) throws java.io.IOException
remoteFiles
- Paths and names of the remote files.localTargetDirectory
- Local directory to put the downloaded files.java.io.IOException