org.apache.ivy.plugins.repository.ssh
Class Scp

java.lang.Object
  extended by 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. To minimize the dependency to the ssh library and because I needed some additional functionality, I decided to copy'n'paste the single class rather than to inherit or delegate it somehow. Nevertheless credit should go to the original author.

Author:
Andreas Sahlbach, Christian Plattner, plattner@inf.ethz.ch

Nested Class Summary
 class Scp.FileInfo
           
 
Constructor Summary
Scp(com.jcraft.jsch.Session session)
           
 
Method Summary
 void get(java.lang.String remoteFile, java.io.OutputStream localTarget)
          Download a file from the remote server into an OutputStream
 void get(java.lang.String remoteFile, java.lang.String localTarget)
          Download a file from the remote server to a local file.
 Scp.FileInfo getFileinfo(java.lang.String remoteFile)
          Initiates an SCP sequence but stops after getting fileinformation header
 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 localFile, java.lang.String remoteTargetDirectory, java.lang.String remoteName)
          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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scp

public Scp(com.jcraft.jsch.Session session)
Method Detail

put

public void put(java.lang.String localFile,
                java.lang.String remoteTargetDirectory,
                java.lang.String remoteName)
         throws java.io.IOException,
                RemoteScpException
Copy a local file to a remote directory, uses mode 0600 when creating the file on the remote side.

Parameters:
localFile - Path and name of local file.
remoteTargetDirectory - Remote target directory where the file has to end up (optional)
remoteName - target filename to use
Throws:
java.io.IOException - in case of network problems
RemoteScpException - in case of problems on the target system (connection ok)

put

public void put(byte[] data,
                java.lang.String remoteFileName,
                java.lang.String remoteTargetDirectory)
         throws java.io.IOException,
                RemoteScpException
Create a remote file and copy the contents of the passed byte array into it. Uses mode 0600 for creating the remote file.

Parameters:
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 where the file has to end up (optional)
Throws:
java.io.IOException - in case of network problems
RemoteScpException - in case of problems on the target system (connection ok)

put

public void put(byte[] data,
                java.lang.String remoteFileName,
                java.lang.String remoteTargetDirectory,
                java.lang.String mode)
         throws java.io.IOException,
                RemoteScpException
Create a remote file and copy the contents of the passed byte array into it. The method use the specified mode when creating the file on the remote side.

Parameters:
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 where the file has to end up (optional)
mode - a four digit string (e.g., 0644, see "man chmod", "man open")
Throws:
java.io.IOException - in case of network problems
RemoteScpException - in case of problems on the target system (connection ok)

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.
remoteTargetDir - Remote target directory where the file has to end up (optional)
remoteTargetName - file name to use on the target system
mode - a four digit string (e.g., 0644, see "man chmod", "man open")
Throws:
java.io.IOException - in case of network problems
RemoteScpException - 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.
Throws:
java.io.IOException - in case of network problems
RemoteScpException - 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 problems
RemoteScpException - 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 problems
RemoteScpException - in case of problems on the target system (connection ok)