Package fr.ifremer.isisfish.util.ssh
Class SSHUtils
java.lang.Object
fr.ifremer.isisfish.util.ssh.SSHUtils
SSH utils class.
All this code has be taken from ant optionnal ssh task.
Use full for:
- exec command
- scpTo command
- scpFrom command
- Version:
- $Revision$ Last update : $Date$ By : $Author$
- Author:
- chatellier
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classProgress monitor (sftp). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final intprotected static final byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voiddoSingleSftpransfer(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) protected static voiddoSingleTransfer(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) static intExec command on remote server.static intExec command on remote server.protected static voidfetchFile(File localFile, long filesize, OutputStream out, InputStream in, ProgressMonitor monitor) protected static voidprotected static voidgetFile(com.jcraft.jsch.ChannelSftp channel, com.jcraft.jsch.ChannelSftp.LsEntry le, File localFile) protected static com.jcraft.jsch.ChannelSftpopenSftpChannel(com.jcraft.jsch.Session session) Open sftp channel.protected static FileparseAndCreateDirectory(String serverResponse, File localFile) protected static voidparseAndFetchFile(String serverResponse, File localFile, OutputStream out, InputStream in, ProgressMonitor monitor) static voidDownload a local file from remote server and check md5sum.static voidscpFrom(com.jcraft.jsch.Session session, String remoteFileName, File localFile, ProgressMonitor monitor) Download a local file from remote server and check md5sum.static voidUpload file on remote server.protected static voidsendAck(OutputStream out) Send an ack.protected static voidsendFileToRemote(com.jcraft.jsch.ChannelSftp channel, File localFile, String remotePath) protected static voidsendFileToRemote(File localFile, InputStream in, OutputStream out) static voidPerform sftp file transfert.static voidPerform sftp file transfert.protected static voidstartRemoteCpProtocol(InputStream in, OutputStream out, File localFile, ProgressMonitor monitor) protected static inttrackProgress(long filesize, long totalLength, int percentTransmitted) Track progress every 10% if 100kb < filesize < 1mb.protected static voidReads the response, throws a BuildException if the response indicates an error.
-
Field Details
-
LINE_FEED
protected static final byte LINE_FEED- See Also:
-
BUFFER_SIZE
protected static final int BUFFER_SIZE- See Also:
-
HUNDRED_KILOBYTES
protected static final int HUNDRED_KILOBYTES- See Also:
-
-
Constructor Details
-
SSHUtils
protected SSHUtils()Utility class
-
-
Method Details
-
sendAck
Send an ack.- Parameters:
out- the output stream to use- Throws:
IOException- on error
-
waitForAck
Reads the response, throws a BuildException if the response indicates an error.- Parameters:
in- the input stream to use- Throws:
IOException- on I/O errorSSHException
-
trackProgress
protected static int trackProgress(long filesize, long totalLength, int percentTransmitted) Track progress every 10% if 100kb < filesize < 1mb. For larger files track progress for every percent transmitted.- Parameters:
filesize- the size of the file been transmittedtotalLength- the total transmission sizepercentTransmitted- the current percent transmitted- Returns:
- the percent that the file is of the total
-
exec
Exec command on remote server.- Parameters:
session- opened valid sessioncommand- command to exec- Returns:
- channel exit status (0 = no problem)
- Throws:
SSHException
-
exec
public static int exec(com.jcraft.jsch.Session session, String command, Writer out) throws SSHException Exec command on remote server.- Parameters:
session- opened valid sessioncommand- command to execout- exec output (can be null)- Returns:
- channel exit status (0 = no problem)
- Throws:
SSHException
-
scpFrom
public static void scpFrom(com.jcraft.jsch.Session session, String remoteFileName, File localFile) throws SSHException Download a local file from remote server and check md5sum.- Parameters:
session- opened valid jsch sessionremoteFileName- remote file name to downloadlocalFile- local file name to download into- Throws:
SSHException- if transfer fail
-
scpFrom
public static void scpFrom(com.jcraft.jsch.Session session, String remoteFileName, File localFile, ProgressMonitor monitor) throws SSHException Download a local file from remote server and check md5sum.- Parameters:
session- opened valid jsch sessionremoteFileName- remote file name to downloadlocalFile- local file name to download intomonitor- progress monitor (can be null)- Throws:
SSHException- if transfer fail
-
scpTo
public static void scpTo(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) throws SSHException Upload file on remote server.- Parameters:
session- opened valid sessionlocalFile- file to uploadremoteFilePath- remote file path- Throws:
SSHException
-
startRemoteCpProtocol
protected static void startRemoteCpProtocol(InputStream in, OutputStream out, File localFile, ProgressMonitor monitor) throws IOException, SSHException - Throws:
IOExceptionSSHException
-
parseAndCreateDirectory
-
parseAndFetchFile
protected static void parseAndFetchFile(String serverResponse, File localFile, OutputStream out, InputStream in, ProgressMonitor monitor) throws IOException, SSHException - Throws:
IOExceptionSSHException
-
fetchFile
protected static void fetchFile(File localFile, long filesize, OutputStream out, InputStream in, ProgressMonitor monitor) throws IOException - Throws:
IOException
-
doSingleTransfer
protected static void doSingleTransfer(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) throws IOException, com.jcraft.jsch.JSchException, SSHException - Throws:
IOExceptioncom.jcraft.jsch.JSchExceptionSSHException
-
sendFileToRemote
protected static void sendFileToRemote(File localFile, InputStream in, OutputStream out) throws IOException, SSHException - Throws:
IOExceptionSSHException
-
openSftpChannel
protected static com.jcraft.jsch.ChannelSftp openSftpChannel(com.jcraft.jsch.Session session) throws com.jcraft.jsch.JSchException Open sftp channel.- Parameters:
session-- Returns:
- sftp channel
- Throws:
com.jcraft.jsch.JSchException- See Also:
-
ChannelSftp
-
sftpFrom
public static void sftpFrom(com.jcraft.jsch.Session session, File localFile, String remotePath) throws SSHException Perform sftp file transfert.- Parameters:
session-localFile-remotePath-- Throws:
SSHException- on i/o errors
-
getDir
protected static void getDir(com.jcraft.jsch.ChannelSftp channel, String remoteFile, File localFile) throws IOException, com.jcraft.jsch.SftpException - Throws:
IOExceptioncom.jcraft.jsch.SftpException
-
getFile
protected static void getFile(com.jcraft.jsch.ChannelSftp channel, com.jcraft.jsch.ChannelSftp.LsEntry le, File localFile) throws IOException, com.jcraft.jsch.SftpException - Throws:
IOExceptioncom.jcraft.jsch.SftpException
-
sftpTo
public static void sftpTo(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) throws SSHException Perform sftp file transfert.- Parameters:
session-localFile-remoteFilePath-- Throws:
SSHException- on i/o errors
-
doSingleSftpransfer
protected static void doSingleSftpransfer(com.jcraft.jsch.Session session, File localFile, String remoteFilePath) throws IOException, com.jcraft.jsch.JSchException - Throws:
IOExceptioncom.jcraft.jsch.JSchException
-
sendFileToRemote
protected static void sendFileToRemote(com.jcraft.jsch.ChannelSftp channel, File localFile, String remotePath) throws IOException, com.jcraft.jsch.SftpException - Throws:
IOExceptioncom.jcraft.jsch.SftpException
-