public class Scp
extends java.lang.Object
implements java.lang.AutoCloseable
Example Usage:
// create new SshParamters instance
SshParameters params = new SshParameters(hostname, username, password);
// set key exchanges, ciphers, macs and compressions if needed
SshConfiguration sshConfiguration = SshConfiguration.configurationFor(new ComponentClientKeyExchangeFactory(ClientKeyExchanges.DH_GROUP_SHA256, ClientKeyExchanges.DH_GROUP_SHA1),
new JceEncryptionFactory(JceEncryptions.AES256_CBC, JceEncryptions.BLOWFISH_CBC),
new JceMacFactory(JceMacs.HMAC_SHA2_512, JceMacs.HMAC_SHA1),
new ComponentCompressionFactory(Compressions.NONE));
// create new Scp instance
Scp scp = new Scp(params, sshConfiguration);
// register event listener
scp.addListener(this);
// establish connection
scp.connect();
// upload file to remote directory
scp.upload(new File("c:/tmp/file.txt"),"/home/jsmith/");
// disconnect
scp.disconnect();
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_SIZE |
static java.io.File |
DEFAULT_LOCAL_DIRECTORY |
static boolean |
DEFAULT_PRESERVE_FILE_ATTRIBUTES |
| Constructor and Description |
|---|
Scp(SshParameters parameters)
Creates a new SCP client instance.
|
Scp(SshParameters parameters,
java.util.logging.Logger logger)
Creates a new SCP client instance.
|
Scp(SshParameters parameters,
SshConfiguration configuration)
Creates a new SCP client instance.
|
Scp(SshParameters parameters,
SshConfiguration configuration,
java.io.File currentLocalDirectory,
int transferBufferSizeBytes,
boolean fileAttributesPreservingRequired,
java.util.logging.Logger logger)
Creates a new SCP client instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(ScpEventListener listener)
Adds an event listener.
|
void |
close() |
Scp |
connect()
Connects to the server.
|
void |
disconnect()
Disconnects from the server.
|
void |
download(java.io.OutputStream destinationStream,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
Downloads a file.
|
java.io.File |
download(java.lang.String remoteDirectory,
java.lang.String remoteFile)
Downloads the file from SSH server.
|
java.io.File |
download(java.lang.String remoteDirectory,
java.lang.String remoteFile,
java.io.File localFile)
Downloads a file.
|
void |
downloadDir(java.lang.String remoteParentDirectory,
java.lang.String remoteDirectory)
Downloads a directory recursively.
|
SshConfiguration |
getConfiguration()
Returns current SSH configuration.
|
boolean |
getDebug()
Returns debug mode flag.
|
java.io.PrintStream |
getDebugStream()
Returns current debug stream if any.
|
int |
getDownloadBlockSize()
Deprecated.
getTransferBufferSizeBytes()
|
SshHostKeys |
getHostKeys()
Returns SSH host keys for further use.
|
java.io.File |
getLocalDir()
Returns current local directory.
|
java.util.logging.Level |
getLogLevel()
Returns current log level.
|
SshParameters |
getParameters()
Returns current SSH parameters.
|
boolean |
getPreserveTime()
Deprecated.
use isFileAttributesPreservingRequired
|
int |
getTransferBufferSizeBytes()
Returns current transfer buffer size.
|
int |
getUploadBlockSize()
Deprecated.
use getTransferBufferSizeBytes()
|
void |
interrupt()
Interrupts current transfer process.
|
boolean |
isConnected()
Checks if client is connected.
|
boolean |
isFileAttributesPreservingRequired()
Returns current file attributes preserving required flag.
|
void |
mdownload(java.lang.String remoteDirectory,
java.util.Collection<java.lang.String> remoteFiles)
Downloads multiple files.
|
void |
mdownload(java.lang.String remoteDirectory,
java.util.Enumeration<java.lang.String> remoteFiles)
Downloads multiple files.
|
void |
mdownload(java.lang.String remoteDirectory,
java.util.Iterator<java.lang.String> remoteFiles)
Downloads multiple files.
|
void |
mdownload(java.lang.String remoteDirectory,
java.lang.String... remoteFiles)
Downloads multiple files.
|
void |
mdownload(java.lang.String remoteDirectory,
java.lang.String wildcard)
Downloads multiple files matching filter from remote directory.
|
void |
mupload(java.lang.String remoteDirectory,
java.util.Collection<java.lang.String> localFiles)
Uploads multiple files taken from the current local directory.
|
void |
mupload(java.lang.String remoteDirectory,
java.util.Enumeration<java.lang.String> localFiles)
Uploads multiple files taken from the current local directory.
|
void |
mupload(java.lang.String remoteDirectory,
java.util.Iterator<java.lang.String> localFiles)
Uploads multiple files taken from the current local directory.
|
void |
mupload(java.lang.String remoteDirectory,
java.lang.String... localFiles)
Uploads multiple files taken from the current local directory.
|
void |
mupload(java.lang.String remoteDirectory,
java.lang.String regex)
Uploads multiple files matching the specified regular expression.
|
void |
removeListener(ScpEventListener listener)
Removes an even listener.
|
void |
setConfiguration(SshConfiguration value)
Sets current SSH configuration.
|
void |
setDebug(boolean value)
Turns on/off debug log level.
|
void |
setDebugStream(java.io.PrintStream value)
Sets a debug stream.
|
void |
setDownloadBlockSize(int value)
Deprecated.
use setTransferBufferSizeBytes()
|
void |
setFileAttributesPreservingRequired(boolean value)
Sets file attributes preserving required flag.
|
void |
setLocalDir(java.io.File value)
Sets current local directory.
|
void |
setLogLevel(java.util.logging.Level level)
Sets current log level.
|
void |
setParameters(SshParameters value)
Sets current SSH parameters.
|
void |
setPreserveTime(boolean value)
Deprecated.
use setFileAttributesPreservingRequired
|
void |
setTransferBufferSizeBytes(int value)
Sets current transfer buffer size.
|
void |
setUploadBlockSize(int value)
Deprecated.
use setTransferBufferSizeBytes()
|
java.lang.String |
toString() |
void |
upload(byte[] sourceData,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
Uploads data.
|
void |
upload(java.io.File localFile,
java.lang.String remoteDirectory)
Uploads a file.
|
void |
upload(java.io.File localFile,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
Uploads a file.
|
void |
upload(java.io.InputStream sourceStream,
long sourceLengthBytes,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
Uploads data.
|
void |
upload(java.io.InputStream sourceStream,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
Uploads data.
|
void |
upload(java.lang.String remoteDirectory,
java.lang.String localFile)
Uploads a file.
|
void |
upload(java.lang.String localFile,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
Uploads a file.
|
void |
uploadDir(java.io.File localDirectory,
java.lang.String remoteParentDirectory)
Uploads a directory.
|
void |
uploadDir(java.io.File localDirectory,
java.lang.String remoteParentDirectory,
java.lang.String remoteDirectory)
Uploads a directory.
|
public static final java.io.File DEFAULT_LOCAL_DIRECTORY
public static final int DEFAULT_BUFFER_SIZE
public static final boolean DEFAULT_PRESERVE_FILE_ATTRIBUTES
public Scp(SshParameters parameters, SshConfiguration configuration, java.io.File currentLocalDirectory, int transferBufferSizeBytes, boolean fileAttributesPreservingRequired, java.util.logging.Logger logger)
parameters - SSH connection parametersconfiguration - SSH configurationcurrentLocalDirectory - current local directorytransferBufferSizeBytes - transfer buffer size in bytesfileAttributesPreservingRequired - file attributes preserving required flaglogger - loggerpublic Scp(SshParameters parameters, SshConfiguration configuration)
parameters - SSH connection parametersconfiguration - SSH configurationpublic Scp(SshParameters parameters, java.util.logging.Logger logger)
parameters - SSH connection parameterslogger - loggerpublic Scp(SshParameters parameters)
parameters - SSH connection parameterspublic SshParameters getParameters()
public void setParameters(SshParameters value)
value - SSH parameterspublic SshConfiguration getConfiguration()
public void setConfiguration(SshConfiguration value)
value - SSH configurationpublic java.io.File getLocalDir()
public void setLocalDir(java.io.File value)
value - local directorypublic int getTransferBufferSizeBytes()
public void setTransferBufferSizeBytes(int value)
value - transfer buffer size in bytespublic int getUploadBlockSize()
public void setUploadBlockSize(int value)
value - upload block size in bytespublic int getDownloadBlockSize()
public void setDownloadBlockSize(int value)
value - download block size in bytespublic boolean isFileAttributesPreservingRequired()
public void setFileAttributesPreservingRequired(boolean value)
value - file attributes preserving required flagpublic boolean getPreserveTime()
public void setPreserveTime(boolean value)
value - preserve timepublic java.util.logging.Level getLogLevel()
public void setLogLevel(java.util.logging.Level level)
level - new log levelpublic boolean getDebug()
true if debug mode is turned onpublic void setDebug(boolean value)
value - if true debug level will bw turned onpublic java.io.PrintStream getDebugStream()
public void setDebugStream(java.io.PrintStream value)
value - debug streampublic void addListener(ScpEventListener listener)
listener - event listenerpublic void removeListener(ScpEventListener listener)
listener - target listenerpublic SshHostKeys getHostKeys()
public Scp connect() throws ScpException
ScpException - if an error occurspublic void disconnect()
public void close()
close in interface java.lang.AutoCloseablepublic boolean isConnected()
true if client is connected; false otherwisepublic void interrupt()
public void download(java.io.OutputStream destinationStream,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
throws java.io.IOException
destinationStream - destination streamremoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFile - source filenamejava.io.IOException - if an error occurspublic java.io.File download(java.lang.String remoteDirectory,
java.lang.String remoteFile,
java.io.File localFile)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFile - source filenamelocalFile - destination filejava.io.IOException - if an error occurspublic java.io.File download(java.lang.String remoteDirectory,
java.lang.String remoteFile)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFile - source/destination filenamejava.io.IOException - if an error occurspublic void mdownload(java.lang.String remoteDirectory,
java.util.Collection<java.lang.String> remoteFiles)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFiles - source file namesjava.io.IOException - if an error occurspublic void mdownload(java.lang.String remoteDirectory,
java.lang.String... remoteFiles)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFiles - source file namesjava.io.IOException - if an error occurspublic void mdownload(java.lang.String remoteDirectory,
java.util.Enumeration<java.lang.String> remoteFiles)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFiles - source file namesjava.io.IOException - if an error occurspublic void mdownload(java.lang.String remoteDirectory,
java.util.Iterator<java.lang.String> remoteFiles)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFiles - source file namesjava.io.IOException - if an error occurspublic void mdownload(java.lang.String remoteDirectory,
java.lang.String wildcard)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directorywildcard - file filter wildcardjava.io.IOException - if an error occurspublic void downloadDir(java.lang.String remoteParentDirectory,
java.lang.String remoteDirectory)
throws java.io.IOException
remoteParentDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteDirectory - directory namejava.io.IOException - if an error occurspublic void upload(java.io.InputStream sourceStream,
long sourceLengthBytes,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
throws java.io.IOException
sourceStream - source data streamsourceLengthBytes - total amount of data to upload in bytesremoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFile - remote file name relative to parent remote directoryjava.io.IOException - if an error occurspublic void upload(byte[] sourceData,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
throws java.io.IOException
sourceData - source data arrayremoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFile - remote file name relative to parent remote directoryjava.io.IOException - if an error occurspublic void upload(java.io.InputStream sourceStream,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
throws java.io.IOException
sourceStream - source data streamremoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFile - remote file name relative to parent remote directoryjava.io.IOException - if an error occurspublic void upload(java.io.File localFile,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
throws java.io.IOException
localFile - source fileremoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFile - remote file name relative to parent remote directoryjava.io.IOException - if an error occurspublic void upload(java.io.File localFile,
java.lang.String remoteDirectory)
throws java.io.IOException
localFile - source fileremoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryjava.io.IOException - if an error occurspublic void upload(java.lang.String localFile,
java.lang.String remoteDirectory,
java.lang.String remoteFile)
throws java.io.IOException
localFile - source file nameremoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteFile - remote file name relative to parent remote directoryjava.io.IOException - if an error occurspublic void upload(java.lang.String remoteDirectory,
java.lang.String localFile)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directorylocalFile - file to upload relative to the current local directoryjava.io.IOException - if an error occurspublic void mupload(java.lang.String remoteDirectory,
java.util.Collection<java.lang.String> localFiles)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directorylocalFiles - sources filesjava.io.IOException - if an error occurspublic void mupload(java.lang.String remoteDirectory,
java.lang.String... localFiles)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directorylocalFiles - source filesjava.io.IOException - if an error occurspublic void mupload(java.lang.String remoteDirectory,
java.util.Enumeration<java.lang.String> localFiles)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directorylocalFiles - source filesjava.io.IOException - if an error occurspublic void mupload(java.lang.String remoteDirectory,
java.util.Iterator<java.lang.String> localFiles)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directorylocalFiles - source filesjava.io.IOException - if an error occurspublic void mupload(java.lang.String remoteDirectory,
java.lang.String regex)
throws java.io.IOException
remoteDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryregex - source file filterjava.io.IOException - if an error occurspublic void uploadDir(java.io.File localDirectory,
java.lang.String remoteParentDirectory,
java.lang.String remoteDirectory)
throws java.io.IOException
localDirectory - source directoryremoteParentDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryremoteDirectory - remote directory name relative to parent remote directoryjava.io.IOException - if an error occurspublic void uploadDir(java.io.File localDirectory,
java.lang.String remoteParentDirectory)
throws java.io.IOException
localDirectory - source directoryremoteParentDirectory - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directoryjava.io.IOException - if an error occurspublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © JSCAPE LLC. 1999-2021. All Rights Reserved