Mikrotik routerboard backup using SFTP

Discussion in 'General Computer Support' started by muhamed, Nov 7, 2012.

  1. muhamed

    muhamed

    Joined:
    Nov 7, 2012
    Messages:
    1
    Likes Received:
    0
    Hello guys, i have problem with this code. I'm tryin to get backup file from Mikrotik routerboards using following code. But when run this code "10: Resource temporarily unavailable" error appeared. Someone help me pls
    package main;

    import java.util.Properties;
    import com.jcraft.jsch.*;
    import com.jcraft.jsch.ChannelSftp;
    import com.jcraft.jsch.Channel;


    public class Main {

    public static void main(String args[])
    {
    String host = "ip address";
    String username = "admin";
    String password = "pass";
    String command = "system backup save name=backup_name";
    String rfile = "backup_name.backup";
    String ftpRemoteDirectory = "/files/";
    int port = 22;

    try{
    JSch jsch = new JSch();
    Session session = jsch.getSession(username, host, port);
    session.setPassword(password);
    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    System.out.println("connecting...");
    session.connect();
    System.out.println("connected.");

    Channel channel = session.openChannel("exec");
    ((ChannelExec)channel).setCommand(command);
    channel.connect();

    Channel cp_channel = session.openChannel("sftp");
    cp_channel.connect();
    ChannelSftp sftpChannel = (ChannelSftp)cp_channel;
    sftpChannel.get("../file/2012/11/backup_name.backup", "D:/backup_name.backup");
    sftpChannel.exit();
    cp_channel.connect();
    channel.disconnect();
    cp_channel.disconnect();
    session.disconnect();

    }
    catch(Exception e)
    {
    System.err.print(e);
    }


    }


    }
     
    muhamed, Nov 7, 2012
    #1
    1. Advertisements

  2. muhamed

    Jazz555

    Joined:
    Jan 23, 2013
    Messages:
    1
    Likes Received:
    0
    Hmmm, first command is usable... Second command, I don't know how to convert it for plink.
    I'm using a plink.exe for that but I have no idea how to make it download configuration or at least, I don't know what command is used to download backup file. Creation of backup file would be like.
     
    Jazz555, Jan 23, 2013
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.