com.zehon.scp
Class SCP

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

public class SCP
extends java.lang.Object

This SCP class offers convenient static methods for uploading/downloading files Please refer to http://www.zehon.com/features.htm for more information about our SCP.

Author:
Zehon Team http://www.zehon.com/

Method Summary
static int getFile(java.lang.String remoteFileName, java.lang.String scpFolder, java.lang.String serverName, java.lang.String username, java.lang.String password, java.lang.String toLocalFolder)
          Retrieve a remote file specified by scpFolder/remoteFileName and buffer it and write a local folder called toLocalFolder
static int sendFile(java.lang.String localFilePath, java.lang.String scpDestFolder, java.lang.String newFileName, java.lang.String serverName, java.lang.String username, java.lang.String password)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sendFile

public static int sendFile(java.lang.String localFilePath,
                           java.lang.String scpDestFolder,
                           java.lang.String newFileName,
                           java.lang.String serverName,
                           java.lang.String username,
                           java.lang.String password)
                    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.
serverName - scp server name
username - scp username
password - scp password
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
SCPException - 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{
SCP.sendFile("C:\myfiles\test.txt", "/myscpFolder", "scp.myhost.com", "scp", "pass" );
}catch(SCPException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

FileTransferException
See Also:
FileTransferStatus

getFile

public static int getFile(java.lang.String remoteFileName,
                          java.lang.String scpFolder,
                          java.lang.String serverName,
                          java.lang.String username,
                          java.lang.String password,
                          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";
serverName - scp server name
username - scp username
password - scp password
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 {
status = SCP.getFile(nameOfFile, scpFolder, toLocalFolder,"scp.myhost.com", "scp", "pass");

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

See Also:
FileTransferStatus


Copyright © 2009 Zehon Team. All Rights Reserved.