Search in sources :

Example 1 with FileTransferClient

use of com.axway.ats.action.filetransfer.FileTransferClient in project ats-framework by Axway.

the class FileTransferTests method executFtpCommands.

/**
 * Run some direct FTP commands
 */
@Test
public void executFtpCommands() {
    // connect in the regular way, it is easier than sending separated FTP commands
    FileTransferClient transferClient = new FileTransferClient(TransferProtocol.FTP);
    transferClient.setPort(configuration.getFtpServerPort());
    transferClient.connect(configuration.getServerIp(), configuration.getUserName(), configuration.getUserPassword());
    // send FTP commands and check the returned results
    log.info("List of supported FTP commands:\n" + transferClient.executeCommand("help"));
    log.info("Get current directory:\n" + transferClient.executeCommand("pwd"));
    log.info("The connection status is:\n" + transferClient.executeCommand("stat"));
    transferClient.disconnect();
}
Also used : FileTransferClient(com.axway.ats.action.filetransfer.FileTransferClient) Test(org.testng.annotations.Test)

Example 2 with FileTransferClient

use of com.axway.ats.action.filetransfer.FileTransferClient in project ats-framework by Axway.

the class FileTransferTests method ftpTransfer.

/**
 * Upload and download over FTP
 */
@Test
public void ftpTransfer() {
    // Instantiate the File Transfer client by providing the protocol to use
    FileTransferClient transferClient = new FileTransferClient(TransferProtocol.FTP);
    transferClient.setPort(configuration.getFtpServerPort());
    // 1. upload a file
    transferClient.connect(configuration.getServerIp(), configuration.getUserName(), configuration.getUserPassword());
    transferClient.uploadFile(RESOURCES_ROOT_DIR + LOCAL_FILE_NAME, "/", REMOTE_FILE_NAME);
    transferClient.disconnect();
    // 2. make sure our we do not have the file on the local folder
    assertFalse(new FileSystemOperations().doesFileExist(DOWNLOADS_DIR + REMOTE_FILE_NAME));
    // 3. download a file
    transferClient.connect(configuration.getServerIp(), configuration.getUserName(), configuration.getUserPassword());
    transferClient.downloadFile(DOWNLOADS_DIR, "/", REMOTE_FILE_NAME);
    transferClient.disconnect();
    // 4. make sure the file is downloaded
    assertTrue(new FileSystemOperations().doesFileExist(DOWNLOADS_DIR + REMOTE_FILE_NAME));
}
Also used : FileTransferClient(com.axway.ats.action.filetransfer.FileTransferClient) FileSystemOperations(com.axway.ats.action.filesystem.FileSystemOperations) Test(org.testng.annotations.Test)

Example 3 with FileTransferClient

use of com.axway.ats.action.filetransfer.FileTransferClient in project ats-framework by Axway.

the class FileTransferTests method httpTransfer.

/**
 * Upload and download over HTTP
 */
@Test
public void httpTransfer() {
    FileTransferClient transferClient = new FileTransferClient(TransferProtocol.HTTP);
    // set a custom port(if not using the default one)
    transferClient.setPort(configuration.getHttpServerPort());
    // connect using appropriate parameters(we do not need user information)
    transferClient.connect(configuration.getServerIp());
    // upload a local file
    transferClient.uploadFile(RESOURCES_ROOT_DIR + LOCAL_FILE_NAME, "/" + configuration.getHttpServerWebappWar() + "/transfers/", "remoteFile.txt");
    // download the just uploaded file
    transferClient.downloadFile(DOWNLOADS_DIR, "/" + configuration.getHttpServerWebappWar() + "/transfers/", "remoteFile.txt");
    transferClient.disconnect();
}
Also used : FileTransferClient(com.axway.ats.action.filetransfer.FileTransferClient) Test(org.testng.annotations.Test)

Example 4 with FileTransferClient

use of com.axway.ats.action.filetransfer.FileTransferClient in project ats-framework by Axway.

the class FileTransferActions method connect.

/**
 * Do a connect
 *
 * @param protocol the transfer protocol to use
 * @param port the remote port
 * @param hostname the remote host
 * @param username the user name
 * @param password the user password
 */
@Action
public void connect(@Parameter(name = "protocol") String protocol, @Parameter(name = "port") int port, @Parameter(name = "hostname") String hostname, @Parameter(name = "username") String username, @Parameter(name = "password") String password) {
    // make instance of the transfer client and do a connect
    transferClient = new FileTransferClient(TransferProtocol.valueOf(protocol));
    transferClient.setPort(port);
    transferClient.connect(hostname, username, password);
}
Also used : FileTransferClient(com.axway.ats.action.filetransfer.FileTransferClient) Action(com.axway.ats.agent.core.model.Action)

Aggregations

FileTransferClient (com.axway.ats.action.filetransfer.FileTransferClient)4 Test (org.testng.annotations.Test)3 FileSystemOperations (com.axway.ats.action.filesystem.FileSystemOperations)1 Action (com.axway.ats.agent.core.model.Action)1