public class SSHUtils extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
SSHUtils.UtilsProgressMonitor
Progress monitor (sftp).
|
Modifier and Type | Field and Description |
---|---|
protected static int |
BUFFER_SIZE |
protected static int |
HUNDRED_KILOBYTES |
protected static byte |
LINE_FEED |
Modifier | Constructor and Description |
---|---|
protected |
SSHUtils()
Utility class
|
Modifier and Type | Method and Description |
---|---|
protected static void |
doSingleSftpransfer(com.jcraft.jsch.Session session,
File localFile,
String remoteFilePath) |
protected static void |
doSingleTransfer(com.jcraft.jsch.Session session,
File localFile,
String remoteFilePath) |
static int |
exec(com.jcraft.jsch.Session session,
String command)
Exec command on remote server.
|
static int |
exec(com.jcraft.jsch.Session session,
String command,
Writer out)
Exec command on remote server.
|
protected static void |
fetchFile(File localFile,
long filesize,
OutputStream out,
InputStream in,
ProgressMonitor monitor) |
protected static void |
getDir(com.jcraft.jsch.ChannelSftp channel,
String remoteFile,
File localFile) |
protected static void |
getFile(com.jcraft.jsch.ChannelSftp channel,
com.jcraft.jsch.ChannelSftp.LsEntry le,
File localFile) |
protected static com.jcraft.jsch.ChannelSftp |
openSftpChannel(com.jcraft.jsch.Session session)
Open sftp channel.
|
protected static File |
parseAndCreateDirectory(String serverResponse,
File localFile) |
protected static void |
parseAndFetchFile(String serverResponse,
File localFile,
OutputStream out,
InputStream in,
ProgressMonitor monitor) |
static void |
scpFrom(com.jcraft.jsch.Session session,
String remoteFileName,
File localFile)
Download a local file from remote server and check md5sum.
|
static void |
scpFrom(com.jcraft.jsch.Session session,
String remoteFileName,
File localFile,
ProgressMonitor monitor)
Download a local file from remote server and check md5sum.
|
static void |
scpTo(com.jcraft.jsch.Session session,
File localFile,
String remoteFilePath)
Upload file on remote server.
|
protected static void |
sendAck(OutputStream out)
Send an ack.
|
protected static void |
sendFileToRemote(com.jcraft.jsch.ChannelSftp channel,
File localFile,
String remotePath) |
protected static void |
sendFileToRemote(File localFile,
InputStream in,
OutputStream out) |
static void |
sftpFrom(com.jcraft.jsch.Session session,
File localFile,
String remotePath)
Perform sftp file transfert.
|
static void |
sftpTo(com.jcraft.jsch.Session session,
File localFile,
String remoteFilePath)
Perform sftp file transfert.
|
protected static void |
startRemoteCpProtocol(InputStream in,
OutputStream out,
File localFile,
ProgressMonitor monitor) |
protected static int |
trackProgress(long filesize,
long totalLength,
int percentTransmitted)
Track progress every 10% if 100kb < filesize < 1mb.
|
protected static void |
waitForAck(InputStream in)
Reads the response, throws a BuildException if the response
indicates an error.
|
protected static final byte LINE_FEED
protected static final int BUFFER_SIZE
protected static final int HUNDRED_KILOBYTES
protected static void sendAck(OutputStream out) throws IOException
out
- the output stream to useIOException
- on errorprotected static void waitForAck(InputStream in) throws IOException, SSHException
in
- the input stream to useIOException
- on I/O errorSSHException
protected static int trackProgress(long filesize, long totalLength, int percentTransmitted)
filesize
- the size of the file been transmittedtotalLength
- the total transmission sizepercentTransmitted
- the current percent transmittedpublic static int exec(com.jcraft.jsch.Session session, String command) throws SSHException
session
- opened valid sessioncommand
- command to execSSHException
public static int exec(com.jcraft.jsch.Session session, String command, Writer out) throws SSHException
session
- opened valid sessioncommand
- command to execout
- exec output (can be null)SSHException
public static void scpFrom(com.jcraft.jsch.Session session, String remoteFileName, File localFile) throws SSHException
session
- opened valid jsch sessionremoteFileName
- remote file name to downloadlocalFile
- local file name to download intoSSHException
- if transfer failpublic static void scpFrom(com.jcraft.jsch.Session session, String remoteFileName, File localFile, ProgressMonitor monitor) throws SSHException
session
- opened valid jsch sessionremoteFileName
- remote file name to downloadlocalFile
- local file name to download intomonitor
- progress monitor (can be null)SSHException
- if transfer failpublic static void scpTo(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) throws SSHException
session
- opened valid sessionlocalFile
- file to uploadremoteFilePath
- remote file pathSSHException
protected static void startRemoteCpProtocol(InputStream in, OutputStream out, File localFile, ProgressMonitor monitor) throws IOException, SSHException
IOException
SSHException
protected static File parseAndCreateDirectory(String serverResponse, File localFile)
protected static void parseAndFetchFile(String serverResponse, File localFile, OutputStream out, InputStream in, ProgressMonitor monitor) throws IOException, SSHException
IOException
SSHException
protected static void fetchFile(File localFile, long filesize, OutputStream out, InputStream in, ProgressMonitor monitor) throws IOException
IOException
protected static void doSingleTransfer(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) throws IOException, com.jcraft.jsch.JSchException, SSHException
IOException
com.jcraft.jsch.JSchException
SSHException
protected static void sendFileToRemote(File localFile, InputStream in, OutputStream out) throws IOException, SSHException
IOException
SSHException
protected static com.jcraft.jsch.ChannelSftp openSftpChannel(com.jcraft.jsch.Session session) throws com.jcraft.jsch.JSchException
session
- com.jcraft.jsch.JSchException
ChannelSftp
public static void sftpFrom(com.jcraft.jsch.Session session, File localFile, String remotePath) throws SSHException
session
- localFile
- remotePath
- SSHException
- on i/o errorsprotected static void getDir(com.jcraft.jsch.ChannelSftp channel, String remoteFile, File localFile) throws IOException, com.jcraft.jsch.SftpException
IOException
com.jcraft.jsch.SftpException
protected static void getFile(com.jcraft.jsch.ChannelSftp channel, com.jcraft.jsch.ChannelSftp.LsEntry le, File localFile) throws IOException, com.jcraft.jsch.SftpException
IOException
com.jcraft.jsch.SftpException
public static void sftpTo(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) throws SSHException
session
- localFile
- remoteFilePath
- SSHException
- on i/o errorsprotected static void doSingleSftpransfer(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) throws IOException, com.jcraft.jsch.JSchException
IOException
com.jcraft.jsch.JSchException
protected static void sendFileToRemote(com.jcraft.jsch.ChannelSftp channel, File localFile, String remotePath) throws IOException, com.jcraft.jsch.SftpException
IOException
com.jcraft.jsch.SftpException
Copyright © 1999–2020 CodeLutin. All rights reserved.