Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCP Issue 8 - Expect4J not working correctly #5

Open
cverges opened this issue Aug 27, 2013 · 0 comments
Open

GCP Issue 8 - Expect4J not working correctly #5

cverges opened this issue Aug 27, 2013 · 0 comments

Comments

@cverges
Copy link
Owner

cverges commented Aug 27, 2013

Reported by shamsnez...@gmail.com, May 22, 2010
What steps will reproduce the problem?

  1. I want to use expect4j for ftp but it is not working, the following is
    my code

public static void main( String[] args )
    {
        String command1 = "ftp";
        String command2 = "open 127.0.0.1";
        String command3 = "get ftp.txt ftp.txt";
        final String username = "msn";
        final String password = "nezami";
        try
        {
            System.out.println( "FtpTest started ..." );
            Expect4j expect = ExpectUtils.spawn( command1 );
            expect.setDefaultTimeout( Expect4j.TIMEOUT_DEFAULT );
            expect.send( command2 + "\n" );
            DataClosure userNameClosure = new DataClosure( expect, username 
);
            DataClosure passwordClosure = new DataClosure( expect, password 
);
            Match match[] =
            { new GlobMatch( "User", userNameClosure ), new GlobMatch( 
"Password", passwordClosure ) };
            expect.expect( match );
            expect.send( command3 + "\n" );
            expect.close();
            System.out.println( "FtpTest completed ..." );
        }
        catch ( Exception ex )
        {
            ex.printStackTrace();
        }
    }
public class DataClosure
    implements Closure
{
    Expect4j expect;
    String   data;

    public DataClosure()
    {
    }

    public DataClosure( Expect4j expectParam, String dataParam )
    {
        expect = expectParam;
        data = dataParam;
    }

    public void run( ExpectState state )
        throws Exception
    {
        try
        {
            expect.send( data + "\n" );
        }
        catch ( Exception e )
        {
            System.out.println(e.getMessage());
            Expect4j.log.warning( e.getMessage() );
        }
        System.out.println(data +" sent");
        state.addVar( data, Boolean.TRUE );
        state.exp_continue();
    }
}

What is the expected output? What do you see instead?
It should download a existing file from ftp to current directory

What version of the product are you using? On what operating system?
version 1.0 on windows xp3

Please provide any additional information below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant