0

I am implementing a Java program,

  1. which has to connect to remote server
  2. connected remote server should download a file from ftp

i am using Apache MINA lib's for this code

here is code, which connects to the remote server

public class filetrans
{
    public static void main(String[] args) throws IOException, InterruptedException 
    {
        SshClient client = null; 
        String login="user";
        String password="password";


        try 
        {
            client = SshClient.setUpDefaultClient(); 
            client.start(); 
            ConnectFuture future = client.connect("myhost",myport); 
            future.await(); 
            ClientSession session = (ClientSession) future.getSession(); 
            boolean auth = session.authPassword(login, password).await().isSuccess(); 
            if (auth) 
            { 
                System.out.println("Authenticated...."); 
                ClientChannel channel = session.createChannel("shell");
                channel.setIn(new NoCloseInputStream(System.in));
                channel.setOut(new NoCloseOutputStream(System.out));
                channel.setErr(new NoCloseOutputStream(System.err));
                channel.open();
                channel.waitFor(ClientChannel.CLOSED, 5000);
                channel.close(true);
            } 
            else 
            {
                System.out.println("Authentication failed....");
            } 
        } 

        catch (Throwable t) 
        {
            System.out.println(t);
        } 
        finally 
        { 
            client.stop(); 
        } 
    }
}

I am successfully connecting to the Remote server. now i have to connect to the FTP server and download a file and to save in the Remote Server. I am Stuck here, any ideas how to implement further or any codes or any suggestion will be great. thanks

MAHI
  • 9,263
  • 11
  • 36
  • 47
  • What exactly are you stuck with? Does your "server" have some API for telling it to download via ftp? Do you have to write that servercode? Are you *allowed* to write server code? ... – Fildor Apr 17 '13 at 07:21
  • @Fildor here i have written a code for connecting remote server. further this server should connect to FTP and download a file. here in this code how should i implement code to download file from ftp. – MAHI Apr 17 '13 at 07:30
  • If this gives you a shell instance, you can execute FTP commands to get files: http://www.cs.colostate.edu/helpdocs/ftp.html – Himanshu Bhardwaj Apr 17 '13 at 07:32
  • @HimanshuBhardwaj i have tried that too, i have given syntax like " ftp://user:password@host" it says "No such file or directory" unable to connect the FTP. – MAHI Apr 17 '13 at 07:34

0 Answers0