package com.zehon.sftp.samples;
/**
* This CopyFileSample
class
* This sample demonstrates how to copy a file to another directly on the SFTP server
* This sample uses a convenient method, for a Spring-able version of this refer to SFTPClient
* @see com.zehon.sftp.SFTPClient
* Please refer to http://www.zehon.com/features.htm for more information about our SFTP.
* @author Zehon Team (we're happy to serve you!) http://www.zehon.com/
*
*/
import com.zehon.FileTransferStatus;
import com.zehon.exception.FileTransferException;
import com.zehon.sftp.SFTP;
public class CopyFileSample {
/**
* Please refer to http://www.zehon.com/SFTP_samples.htm for its full source code
* @param args
*/
public static void main(String[] args) {
String host = "sftp.zehon.com";
String username = "sftp";
String password = "sftp";
String sourceFilePath = "/upload/test.txt";
String destFilePath = "/uploadCopy/testCopy.txt";
try {
/* This sample uses a convenient method, for a Spring-able version of this refer to SFTPClient
* @see com.zehon.sftp.SFTPClient
*/
int status = SFTP.copyFile(sourceFilePath, destFilePath, host, username, password);
if(FileTransferStatus.SUCCESS == status){
System.out.println(sourceFilePath + " got copied-ed successfully to file "+destFilePath);
}
else if(FileTransferStatus.FAILURE == status){
System.out.println("Fail to copy to folder "+destFilePath);
}
} catch (FileTransferException e) {
e.printStackTrace();
}
}
}