Class Scp
- java.lang.Object
-
- org.apache.ivy.plugins.repository.ssh.Scp
-
public class Scp extends java.lang.Object
This class is using the scp client to transfer data and information for the repository.It is based on the SCPClient from the ganymed ssh library from Christian Plattner, released under a BSD style license.
To minimize the dependency to the ssh library and because we needed some additional functionality, we decided to copy'n'paste the single class rather than to inherit or delegate it somehow.
Nevertheless credit should go to the original author.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Scp.FileInfo
-
Field Summary
Fields Modifier and Type Field Description private static int
BUFFER_SIZE
private static int
CLINE_SPACE_INDEX1
private static int
CLINE_SPACE_INDEX2
private static int
DEFAULT_LINE_BUFFER_LENGTH
private static int
MAX_SCP_LINE_LENGTH
private static int
MIN_C_LINE_LENGTH
private static int
MIN_TLINE_LENGTH
private static int
MODE_LENGTH
private static int
SEND_BYTES_BUFFER_LENGTH
private static int
SEND_FILE_BUFFER_LENGTH
private com.jcraft.jsch.Session
session
-
Constructor Summary
Constructors Constructor Description Scp(com.jcraft.jsch.Session session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
get(java.lang.String remoteFile, java.io.OutputStream localTarget)
Download a file from the remote server into an OutputStreamvoid
get(java.lang.String remoteFile, java.lang.String localTarget)
Download a file from the remote server to a local file.private com.jcraft.jsch.ChannelExec
getExecChannel()
Scp.FileInfo
getFileinfo(java.lang.String remoteFile)
Initiates an SCP sequence but stops after getting fileinformation headerprivate void
parseCLine(java.lang.String line, Scp.FileInfo fileInfo)
private void
parseTLine(java.lang.String line, Scp.FileInfo fileInfo)
void
put(java.lang.String localFile, java.lang.String remoteTargetDir, java.lang.String remoteTargetName, java.lang.String mode)
Copy a local file to a remote site, uses the specified mode when creating the file on the remote side.private void
readResponse(java.io.InputStream is)
private java.lang.String
receiveLine(java.io.InputStream is)
private Scp.FileInfo
receiveStream(com.jcraft.jsch.Channel channel, java.lang.String file, java.io.OutputStream targetStream)
Receive a file via scp and store it in a streamprivate void
sendFile(com.jcraft.jsch.Channel channel, java.lang.String localFile, java.lang.String remoteName, java.lang.String mode)
-
-
-
Field Detail
-
MODE_LENGTH
private static final int MODE_LENGTH
- See Also:
- Constant Field Values
-
SEND_FILE_BUFFER_LENGTH
private static final int SEND_FILE_BUFFER_LENGTH
- See Also:
- Constant Field Values
-
SEND_BYTES_BUFFER_LENGTH
private static final int SEND_BYTES_BUFFER_LENGTH
- See Also:
- Constant Field Values
-
MIN_TLINE_LENGTH
private static final int MIN_TLINE_LENGTH
- See Also:
- Constant Field Values
-
CLINE_SPACE_INDEX2
private static final int CLINE_SPACE_INDEX2
- See Also:
- Constant Field Values
-
CLINE_SPACE_INDEX1
private static final int CLINE_SPACE_INDEX1
- See Also:
- Constant Field Values
-
MIN_C_LINE_LENGTH
private static final int MIN_C_LINE_LENGTH
- See Also:
- Constant Field Values
-
DEFAULT_LINE_BUFFER_LENGTH
private static final int DEFAULT_LINE_BUFFER_LENGTH
- See Also:
- Constant Field Values
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
MAX_SCP_LINE_LENGTH
private static final int MAX_SCP_LINE_LENGTH
- See Also:
- Constant Field Values
-
session
private com.jcraft.jsch.Session session
-
-
Method Detail
-
readResponse
private void readResponse(java.io.InputStream is) throws java.io.IOException, RemoteScpException
- Throws:
java.io.IOException
RemoteScpException
-
receiveLine
private java.lang.String receiveLine(java.io.InputStream is) throws java.io.IOException, RemoteScpException
- Throws:
java.io.IOException
RemoteScpException
-
parseCLine
private void parseCLine(java.lang.String line, Scp.FileInfo fileInfo) throws RemoteScpException
- Throws:
RemoteScpException
-
parseTLine
private void parseTLine(java.lang.String line, Scp.FileInfo fileInfo) throws RemoteScpException
- Throws:
RemoteScpException
-
sendFile
private void sendFile(com.jcraft.jsch.Channel channel, java.lang.String localFile, java.lang.String remoteName, java.lang.String mode) throws java.io.IOException, RemoteScpException
- Throws:
java.io.IOException
RemoteScpException
-
receiveStream
private Scp.FileInfo receiveStream(com.jcraft.jsch.Channel channel, java.lang.String file, java.io.OutputStream targetStream) throws java.io.IOException, RemoteScpException
Receive a file via scp and store it in a stream- Parameters:
channel
- ssh channel to usefile
- to receive from remotetargetStream
- to store file into (if null, get only file info)- Returns:
- file information of the file we received
- Throws:
java.io.IOException
- in case of network or protocol troubleRemoteScpException
- in case of problems on the target system (connection is fine)
-
getExecChannel
private com.jcraft.jsch.ChannelExec getExecChannel() throws com.jcraft.jsch.JSchException
- Returns:
- ChannelExec
- Throws:
com.jcraft.jsch.JSchException
- if something goes wrong
-
put
public void put(java.lang.String localFile, java.lang.String remoteTargetDir, java.lang.String remoteTargetName, java.lang.String mode) throws java.io.IOException, RemoteScpException
Copy a local file to a remote site, uses the specified mode when creating the file on the remote side.- Parameters:
localFile
- Path and name of local file. Must be absolute.remoteTargetDir
- Remote target directory where the file has to end up (optional)remoteTargetName
- file name to use on the target systemmode
- a four digit string (e.g., 0644, see "man chmod", "man open")- Throws:
java.io.IOException
- in case of network problemsRemoteScpException
- in case of problems on the target system (connection ok)
-
get
public void get(java.lang.String remoteFile, java.lang.String localTarget) throws java.io.IOException, RemoteScpException
Download a file from the remote server to a local file.- Parameters:
remoteFile
- Path and name of the remote file.localTarget
- Local file where to store the data. Must be absolute.- Throws:
java.io.IOException
- in case of network problemsRemoteScpException
- in case of problems on the target system (connection ok)
-
get
public void get(java.lang.String remoteFile, java.io.OutputStream localTarget) throws java.io.IOException, RemoteScpException
Download a file from the remote server into an OutputStream- Parameters:
remoteFile
- Path and name of the remote file.localTarget
- OutputStream to store the data.- Throws:
java.io.IOException
- in case of network problemsRemoteScpException
- in case of problems on the target system (connection ok)
-
getFileinfo
public Scp.FileInfo getFileinfo(java.lang.String remoteFile) throws java.io.IOException, RemoteScpException
Initiates an SCP sequence but stops after getting fileinformation header- Parameters:
remoteFile
- to get information for- Returns:
- the file information got
- Throws:
java.io.IOException
- in case of network problemsRemoteScpException
- in case of problems on the target system (connection ok)
-
-