Package org.mule.transport.sftp

Examples of org.mule.transport.sftp.SftpClient


    /** No write access on the outbound directory. The source file should still exist */
    @Test
    public void testNoWriteAccessToOutboundDirectory() throws Exception
    {
        SftpClient client = getSftpClient(OUTBOUND_ENDPOINT_NAME);

        try
        {
            // change the chmod to "dr-x------" on the outbound-directory
            remoteChmod(client, OUTBOUND_ENDPOINT_NAME, 00500);

            // Send an file to the SFTP server, which the inbound-outboundEndpoint
            // then can pick up
            Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME,
                OUTBOUND_ENDPOINT_NAME), "sftp", "service");
            assertNotNull(exception);
            assertTrue("expected DispatchException, but got : " + exception.getClass().toString(),
                exception instanceof DispatchException);
            assertTrue("expected IOException, but got : " + exception.getCause().getClass().toString(),
                exception.getCause() instanceof IOException);
            assertEquals("Permission denied", exception.getCause().getMessage());

            verifyInAndOutFiles(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME, true, false);
        }
        finally
        {
            client.disconnect();
        }
    }
View Full Code Here


            exception.getCause() instanceof IOException);
        assertTrue("wrong message : " + exception.getCause().getMessage(), exception.getCause()
            .getMessage()
            .startsWith("Error during login to"));

        SftpClient client = getSftpClient(INBOUND_ENDPOINT_NAME);
        try
        {
            ImmutableEndpoint endpoint = (ImmutableEndpoint) muleContext.getRegistry().lookupObject(INBOUND_ENDPOINT_NAME);
            assertTrue("The inbound file should still exist",
                super.verifyFileExists(client, endpoint.getEndpointURI(), FILENAME));
        }
        finally
        {
            client.disconnect();
        }
    }
View Full Code Here

    public void testCantWriteToFinalDestAfterTempDirectory() throws Exception
    {
        // Must create the temp directory before we change the access rights
        createRemoteDirectory(OUTBOUND_ENDPOINT_NAME, "uploading");

        SftpClient client = getSftpClient(OUTBOUND_ENDPOINT_NAME);
        try
        {
            // change the chmod to "dr-x------" on the outbound-directory
            remoteChmod(client, OUTBOUND_ENDPOINT_NAME, 00500);

            // Send an file to the SFTP server, which the inbound-outboundEndpoint
            // then can pick up
            // Expect an error, permission denied
            Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME,
                OUTBOUND_ENDPOINT_NAME), "sftp", "service");
            assertNotNull(exception);
            assertTrue("did not receive DispatchException, got : " + exception.getClass().toString(),
                exception instanceof DispatchException);
            assertTrue("did not receive IOException, got : " + exception.getCause().getClass().toString(),
                exception.getCause() instanceof IOException);

            assertEquals("Permission denied", exception.getCause().getMessage());

            verifyInAndOutFiles(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME, true, false);

            ImmutableEndpoint endpoint = muleContext.getRegistry().lookupObject(OUTBOUND_ENDPOINT_NAME);
            assertFalse("The inbound file should not be left in the TEMP-dir", super.verifyFileExists(
                client, endpoint.getEndpointURI().getPath() + "/" + TEMP_DIR, FILENAME));
        }
        finally
        {
            client.disconnect();
        }
    }
View Full Code Here

    protected void verifyInAndOutFiles(String inboundEndpointName,
                                       String outboundEndpointName,
                                       boolean shouldInboundFileStillExist,
                                       boolean shouldOutboundFileExist) throws IOException
    {
        SftpClient sftpClientInbound = getSftpClient(inboundEndpointName);
        SftpClient sftpClientOutbound = getSftpClient(outboundEndpointName);

        try
        {
            ImmutableEndpoint inboundEndpoint = muleContext.getRegistry().lookupObject(inboundEndpointName);
            ImmutableEndpoint outboundEndpoint = muleContext.getRegistry().lookupObject(outboundEndpointName);

            if (shouldInboundFileStillExist)
            {
                assertTrue("The inbound file should still exist",
                    super.verifyFileExists(sftpClientInbound, inboundEndpoint.getEndpointURI(), FILENAME));
            }
            else
            {
                assertFalse("The inbound file should have been deleted",
                    super.verifyFileExists(sftpClientInbound, inboundEndpoint.getEndpointURI(), FILENAME));
            }

            if (shouldOutboundFileExist)
            {
                assertTrue("The outbound file should exist",
                    super.verifyFileExists(sftpClientOutbound, outboundEndpoint.getEndpointURI(), FILENAME));
            }
            else
            {
                assertFalse("The outbound file should have been deleted",
                    super.verifyFileExists(sftpClientOutbound, outboundEndpoint.getEndpointURI(), FILENAME));
            }
        }
        finally
        {
            sftpClientInbound.disconnect();
            sftpClientOutbound.disconnect();
        }
    }
View Full Code Here

TOP

Related Classes of org.mule.transport.sftp.SftpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.