com.zehon.scp
Class SCPClient

java.lang.Object
  extended by com.zehon.scp.SCPClient

public class SCPClient
extends java.lang.Object

This SCPClient class has methods for uploading/downloading files This class has getter/setter methods that can be injected via Spring. Log4j is used for logging, for debugging information please turn on the debug mode for this class package. Please refer to http://www.zehon.com/features.htm for more information about our SCP.

Author:
Zehon Team (we're happy to serve you!) http://www.zehon.com/

Constructor Summary
SCPClient()
           
SCPClient(java.lang.String serverName, java.lang.String username, java.lang.String password)
           
 
Method Summary
 int getFile(java.lang.String remoteFileName, java.lang.String scpFolder, java.lang.String toLocalFolder)
          Retrieve a remote file specified by scpFolder/remoteFileName and buffer it and write a local folder called toLocalFolder
 java.lang.String getPassword()
           
 java.lang.String getServerName()
           
 java.lang.String getUsername()
           
static void scpFrom(java.lang.String host, java.lang.String user, java.lang.String password, java.lang.String remoteFile, java.lang.String localFolderFile)
           
static void scpTo(java.lang.String host, java.lang.String user, java.lang.String password, java.lang.String localFile, java.lang.String remoteFile)
           
 int sendFile(java.lang.String localFilePath, java.lang.String scpDestFolder, java.lang.String newFileName)
          Read in a file specified by localFilePath, for example: C:\myfiles\test.txt or /home/joe/images/img.jpg it does not matter if the file is of binary or text, and scp it to a remote scp folder specified by scpDestFolder, i.e / or /scpRoot or /myscpFolder.
 void setPassword(java.lang.String password)
           
 void setServerName(java.lang.String serverName)
           
 void setUsername(java.lang.String username)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SCPClient

public SCPClient()

SCPClient

public SCPClient(java.lang.String serverName,
                 java.lang.String username,
                 java.lang.String password)
Method Detail

getServerName

public java.lang.String getServerName()

setServerName

public void setServerName(java.lang.String serverName)

getUsername

public java.lang.String getUsername()

setUsername

public void setUsername(java.lang.String username)

getPassword

public java.lang.String getPassword()

setPassword

public void setPassword(java.lang.String password)

sendFile

public int sendFile(java.lang.String localFilePath,
                    java.lang.String scpDestFolder,
                    java.lang.String newFileName)
             throws FileTransferException
Read in a file specified by localFilePath, for example: C:\myfiles\test.txt or /home/joe/images/img.jpg it does not matter if the file is of binary or text, and scp it to a remote scp folder specified by scpDestFolder, i.e / or /scpRoot or /myscpFolder.

Parameters:
localFilePath - Local file path including the file name for example: C:\myfiles\test.txt or /home/joe/images/img.jpg
scpDestFolder - remote scp folder, for example: / or /scpRoot or /myscpFolder.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error loading or scping the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

for example:


try{
SCPClient scpClient = new SCPClient("scp.myhost.com", "scp", "pass");
scpClient.sendFile("C:\myfiles\test.txt", "/myscpFolder");
catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)

See Also:
FileTransferStatus

getFile

public int getFile(java.lang.String remoteFileName,
                   java.lang.String scpFolder,
                   java.lang.String toLocalFolder)
            throws FileTransferException
Retrieve a remote file specified by scpFolder/remoteFileName and buffer it and write a local folder called toLocalFolder

Parameters:
remoteFileName - the name of the file on the remote server to retrieve, i.e test.txt
scpFolder - remote scp folder, for example: / or /scpRoot or /myscpFolder.
toLocalFolder - local filesystem folder to write the remote file to C:\\myfiles\\project\\scpProject\\writeToFolder";
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error getting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String scpFolder = "/test";
String nameOfFile = "testStream.txt";
String toLocalFolder = "C:\\myfiles\\project\\scpProject\\writeToFolder";
int status = -1;
try {
SCPClient scpClient = new SCPClient("scp.myhost.com", "scp", "pass");
status = scpClient.getFile(nameOfFile, scpFolder, toLocalFolder);

catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)

See Also:
FileTransferStatus

scpFrom

public static void scpFrom(java.lang.String host,
                           java.lang.String user,
                           java.lang.String password,
                           java.lang.String remoteFile,
                           java.lang.String localFolderFile)
                    throws FileTransferException
Throws:
FileTransferException

scpTo

public static void scpTo(java.lang.String host,
                         java.lang.String user,
                         java.lang.String password,
                         java.lang.String localFile,
                         java.lang.String remoteFile)
                  throws FileTransferException
Throws:
FileTransferException


Copyright 2009 Zehon Team. All Rights Reserved.