Using SCP command through Startand Java Library

Hello,
Is there any class or way available in Standard Java Library to use SCP command. Actually I want to copy file from one Linux system to another through Java code using SCP protocol .
Zeeshan Hanif

If we can't dissuade you from this course, I'll help you get started: go find RFC 4251, read it, understand it, love it. Then you'll have to do the same with 4252, 4253, 4254, 4255, and 4256. Also, don't forget 1321, 1950, 2104, 2144, 2409, 2440, 3447, and 3526. Then just brush up on java sockets, crypto and IO. Easy as pie! (assuming that pie has 15,641 ingredients, 63 layers, a nine-volume recipe, and must be baked in a perfect vacuum)
:-)

Similar Messages

  • "no row count was produced" error using mqsl commands through Access

    "no row count was produced" error using mqsl commands through Microsoft Access. This sql statement works when I use in in the Access program but it does not work when I try and put it through Access using my Java program. Here is the block of code that I have that does the search.
    public static Game searchRecord(String search) throws SQLException{
    String query = "SELECT* " + "FROM gamefields WHERE SKU = '" + search + "' ORDER BY SKU ASC";
    Game lastGame = new Game(gamefields.getString(1),
    gamefields.getString(2),
    gamefields.getString(3),
    gamefields.getString(4),
    gamefields.getString(5),
    gamefields.getString(6),
    gamefields.getString(7),
    gamefields.getDouble(8));
    Statement statement = connection.createStatement(); //Creates connection
    //statment to database
    statement.executeUpdate(query); //Executes the delete query and Updates the database
    statement.close();
    close();
    open();
    return lastGame;

    When you use the code from java, you access access (!) through the ODBC interface. Things can be different in ODBC and Jet. When you use PrepareadStatements, you should be on the save side:
    public static Game searchRecord(String search) throws SQLException
    String query = "SELECT * FROM gamefields WHERE SKU = ? ORDER BY SKU ASC";
    PreparedStatement statement = connection.prepareStatement(query);
    statement.setString(1,  search);
    ResultSet rs = statement.executeQuery(query);
    if(rs.next()
    // if a row retuned extract the details here
    rs.close();
    statement.close();
    return lastGame;
    }

  • Running a perl shell command through a java program on linux platform

    i'm trying to execute the following command in a java program "perl xxx.pl" using the runtime.getruntime method
    here is the piece of code
    String[] cmd={"perl","-c","AraMorph.pl",""};
    Process p = Runtime.getRuntime().exec(cmd,null,new File("/home/ahmed/buckwalter_morphan_1/data"));
    p.waitFor();
    BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line=in.readLine())!=null)
    System.out.println(line);
    but it doesn't output anything even if i tried to print the output to a file
    i'm trying to execute this program on linux platform but its working properly on a windows platform
    thx
    raar

    String[] cmd={"perl","AraMorph.pl"," </home/ahmed/in.txt"," >/home/ahmed/ast.txt"};
    Process p = Runtime.getRuntime().exec(cmd,null,new File("/home/ahmed/buckwalter_morphan_1/data"));
    BufferedReader in=new BufferedReader(new InputStreamReader(p.getErrorStream()));
    String line;
    while ((line=in.readLine())!=null)
    System.out.println(line);
    p.waitFor();
    String str2=p.getInputStream().toString();
    System.out.println("==================================="+str2);
    and it still outputs nothing but goes in something like infinite loop or as assumed in the article u suggested a deadlock but even all solutions to all pitfalls didn't succeed

  • Running a DOS Command through a JAVA GUI

    I'm trying to run a command line through a GUI.. how would i go about doing this... suppose i wanted to run the following dos command inside a java program:
    String command = "jar cvf classes.jar open.java close.java"
    Does anyone have a good model I can look at that can implement a dos command?

    Maybe you can refer to this resource , I can not remember the Class, It seems like this Runtime.getRuntime().exec() ?? It can execute your command.

  • Print Report using ASCII command through printer selection available on windows

    Hi,
    I'm using Labview 2009 to create a report using Report Generation Toolkit.
    Creating a report is not the problem, the problem is I need to print the report manually by sending an ASCII Code.
    I noticed that there are few example on send ASCII code command, but neither of them are related to printing.
    The printer I use is Panasonic dot matrix printer KX-P1121E with USB port. (Fanfold type of paper)
    I used "NI_report_lvclass: Print report.vi" from Report Generation before this to print my report, everything is okay and not receiving any error.
    But I noticed that after finish printing, the paper will automatically feed out as if that VI (Print report.vi) is sending out "Form Feed" (FF) Command to the printer. 
    My application cannot use this method because I need to print a set of data in every minute. If the data only have 2 rows, then it will be a wasting a lot of paper if everytime finished printing paper feeding out. I want the printer to continue standby on the same paper after finished printing previous data. In other words, maybe just manually send "Line Feed or Carriage Return" to the printer.
    So I have a few things need to be clarified step by step;
    1. How can I send an ASCII Code to my printer? Do you have any example for this? link below is the character of ASCII Codes that can be use :http://webpages.charter.net/dperr/links/esc_p83.ht​m
    2. Can I send a report created by report generation to be printed using this ASCII command method?
    3. If my printer is setup by using windows (Meaning: Available on "Printer and Faxes" list), How can I configure the printer setup in sending the ASCII Code? 
    Really appreciated your reply
    Thanks!

    Hi Zwired1,
    Just to make sure I fully understand the situation - I am assuming since you say you are printing to two different printers that when you are using the Print Report.vi you are using the printer name string to specify which printer you would like to print on. And if the printer that you specify is not functioning it automatically prints on the other printer, is that correct?
    From looking at the code in the Print Report.vi, it looks like if you specify a printer name in the input string, if there is a problem with that printer or if that printer is unavailable, the VI should not print anything, so please let me know if that is not the behavior you are seeing.
    For your question about checking the health of printers, there is a VI in the report gen toolkit called Query Available Printers. You can find it if you open up the Print Report.vi and choose the Standard Report instance, the Query Available Printers.vi is on the block diagram of that VI. It will return the list of available printers and the default printer.
    I hope that helps,

  • Using Unix command lines in java code

    I was wondering if there was a way to run a unix command in java code. I know in C++ there is popen, but i don't know of a way in java. The command i need to run is the whois "domain name" command. Any help would be great!
    jarad

    try something like this:
      public static String whois(String domain) throws IOException {
        BufferedReader is = null;
        Process p = null;
        String result = "";
        p = Runtime.getRuntime().exec("whois " + domain);
        is = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while((line = is.readLine()) != null)
          result += line;
        return result;
      }

  • GETTING THE OUPUT OF UNIX COMMAND THROUGH JAVA

    Hi Guyz...
    Please help me in the below code...
    My intention is to print the output of Unix command through a java program.
    The Java program resides in the Unix Server only.
    I have written the below java code , but its not returning any values....
    String s1= "ls -lt $APPL_TOP/patch/115/odf/jtfgh.odf";
    Runtime r = Runtime.getRuntime();
    Process p= r.exec(s1);
    StringBuffer ret=new StringBuffer();
    InputStream in = p.getInputStream();
    int c;     
    while ((c = in.read()) != -1)
    {                  ret.append((char)c);       
    }     in.close();
    out.println("OTUPUT : "+ ret.toString());
    Can you please help me in this by debugging the existing code or giving me the exact code??
    IT IS URGENT FOR MY PROJECT!!!!!!!!!!!!!!!!!!!!!!!!!!!
    PLEASE HELP ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Since you are expecting the shell to expand the environment variable you need to use
    String[] s1= {"sh","-c","ls -lt $APPL_TOP/patch/115/odf/jtfgh.odf"};
    Also, you should read, digest and implement the recommendations of
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
    P.S Your urgency is not my problem and SHOUTING IS CONSIDERED VERY RUDE!

  • Running OpenSSL command through Java Program

    How do I execute openssl commands through a java program? Any packages or wrapper classes are there? Please help.
    Thanks.

    Hi!
    What do you mean execute commands? Like: "openssl x509 -in cert.pem -out certout.pem" ??
    In that case you can just try the following:
    import java.lang.Runtime;
    try {
    Runtime.getRuntime().exec("openssl x509 -in cert.pem -out certout.pem");
    }catch (Exception e) {
    e.printStackTrace();
    ........

  • How to execute MS DOS command through Java program???

    Dear Sir,
    I want to run a MS-DOS command through my Java program. I have tried "Dir" command but no other command which takes command line args doesn't work at all. Please help.
    import java.io.*;
    class CommandPrompt
         public static void main(String[] args)
              try
                   File file = new File("C:/Temp/Java");
                   String[] cmd = {"command.com","/c","md folder"};
                   String[] envp = {""};
                   Process m;
                   String s = "";
                   m = Runtime.getRuntime().exec(cmd,null,file);
                   BufferedReader buf = new BufferedReader(new InputStreamReader(m.getInputStream()));
                   while ((s = buf.readLine())!=null)
                        System.out.println(s);
              catch (Exception ex)
                   System.out.println("Exception is "+ex);
                   ex.printStackTrace();

    1. This forum is for Swing-related issues only. This question should be posted to the "Java Programming" forum.
    2. Please enclose your sample code in code blocks; it's much easier to read that way. See here for how it's done: http://forum.java.sun.com/faq.jsp#messageformat
    3. Please provide more information, like what error messages you got and what OS you're running. For instance, if you're running WinXP, Win2k or NT4, your command processor should be "cmd.exe", not "command.com". When I made that change, your program worked for me.

  • Runtime class (with scp command)

    Hello
    I wrote a working code , but I think there may be a simpler way to do it.
    I would like to know if it's possible to use the Runtime class , to connect to a remote server and download a file to my computer, using scp command .
    something like:
    String command = "scp Username@server : fileWanted destinationPath";
                Runtime runtime = Runtime.getRuntime();
                Process child = runtime.exec(command);Something in this manner(obviously I will need to take care of the password issue).
    (A code sample will be great)
    thanks,Dave

    You might be interested in jsch, Java Secure Channel (BSD license), a pure-Java implementation of SSH2:
    http://www.jcraft.com/jsch/index.html
    See "ScpFrom.java" in "examples" directory.

  • We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a

    We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a printer."C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /T "\\<Application Server>\Report\<TEST.PDF>" "<Printer Name>". Current Situation: The above command line parameter when executed is working as expected in a User's Workspace. When executed in a command line on the Application Server is working as expected. But, the same is not working while executing it from Deployed environment.Software being used: 1. Adobe 11.0 enterprise version. 2. Webshpere Application Server 8.5.5.2. Please let us know if there is a way to enable trace logs in Adobe Reader to further diagnose this issue.

    This is the Acrobat.com forum.  Your question will have a much better chance being addressed in the Acrobat SDK forum.

  • We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader.

    We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader.
    For which, We created and execute the below command line to call Adobe Reader and print the PDF on a printer.
    "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /T "\\<Application Server>\Report\<TEST.PDF>" "<Printer Name>".
    Current Situation: The above command line parameter when executed is working as expected in a User's Workspace.
    When executed in a command line on the Application Server, it is working as expected.
    But, the same is not working while executing it from Deployed environment.
    Software being used: 1. Adobe 11.0 enterprise version. 2. Webshpere Application Server 8.5.5.2.
    Please let us know if there is a way to enable trace logs in Adobe Reader to further diagnose this issue.

    This is the Acrobat.com forum.  Your question will have a much better chance being addressed in the Acrobat SDK forum.

  • Problem in executing a unix command through java

    hi
    i'm trying to execute unix command through java
    simple shell command like "ls -l >test " but i'm not able to see the result.
    there are no error messages.
    Code is:
    import java.lang.Runtime.*;
    class ExecDemo
         public static void main(String[] args)
              Runtime r=Runtime.getRuntime();
              Process p=null;
              try
                   p=r.exec("ls -l > test");
              catch (Exception e)
                   System.out.println("Error executing nedit.");
    }can anyone help please.

    get the the inputStream of the runtime object after executing the command.
    now use the readLine() function until it becomes null.
    egs: with reference to ur code.
    InputStream is=p.getInputStream()
    while(is!=null)
    String s=is.readLine();
    if the command don't execute try giving the full path also like /sbin/ls -l

  • Running cmd commands through java

    Hi,
    I am trying to run few dos commands through java using Runtime.exec("command") but I am getting following error
    commmand is cd D:\CodeMerge\A\
    java.io.IOException: CreateProcess: cd.. error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at createDirectory.main(createDirectory.java:24)
    Basically what I am looking for is this:
    1) My program is in D:\Amit\RM
    2) I want to get out to D:\ go to CodeMerge\A\.
    3) Create folder with curretn date as name of the folder
    Hence I am doing
    rTime.exec("cd../..");
    rTime.exec("cd D:\CodeMerge\A\");
    rTime.exec("mkdir "+date);
    Can anybody tell me why I am getting this error
    Jounty

    U can run either DOS Commands or UNIX Commands thru the following Java Program
    Written By BalaNagaraju Malisetti
    contact: [email protected]
    import java.io.*;
    public class RunBdiff
    public static String rununixcmd(String v_prev_path,String v_curr_path,String v_delta_path,String v_beg,String v_len)
    String s = null;
    FileOutputStream fos;
    DataOutputStream dos;
    try
    int v_int_beg = Integer.parseInt(v_beg);
    int v_int_len=Integer.parseInt(v_len);
    int v_int_end=(v_int_beg+v_int_len)-1;
    String v_pos1=String.valueOf((v_int_beg+2));
    String v_pos2=String.valueOf((v_int_end+2));
    String cmd1 = "bdiff ";
    String cmd2=v_prev_path;
    String cmd3=" ";
    String cmd4=v_curr_path;
    String cmd5="| grep '^>'";
    String cmd6="| cut -c";
    String cmd7=v_pos1+"-"+v_pos2;
    String cmd8="| sort ";
    String cmd9="| uniq ";
    String cmd=cmd1+cmd2+cmd3+cmd4+cmd5+cmd6+cmd7+cmd8+cmd9;
    String[] commands = {"/bin/csh","-c",cmd}; //in Unix
    //String[] commands = {"cmd.exe","-c",cmd}; //in Windows
    Process p = Runtime.getRuntime().exec(commands);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    // read the output from the command
    File file = new File(v_delta_path);
    fos = new FileOutputStream(file);
    dos=new DataOutputStream(fos);
    //Writing the output of bdiff command to Delta File
    while ((s = stdInput.readLine()) != null)
    dos.writeChars(s);
    //Return Error Message to Calling Procedure
    while ((s = stdError.readLine()) != null)
    return s;
    return s;
    catch (IOException e)
    return String.valueOf(e);
    public static void main(String args[])
    String msg=rununixcmd("/home/g_anil/MS_ADDRESS1.dat","/home/g_anil/MS_ADDRESS2.dat","/home/g_anil/MS_ADDRESS_DELTA.dat","1","9");
    **************************************************************************************************************************************

  • What is the best way to call SSH commands through Java technologies

    What is the best way to call SSH commands through Java technologies

    I don't think you can specify the password at the prompt using ssh. Plink has the -pw command option for passwords. What I did was except ssh to ask me and write the password programmatically through the outputStream I obtained from my Process object. I looked for "password: ", and then wrote the password with a trailing newline.
    Both plink and ssh will also ask if you trust the host if it is the first time you are connecting to it. So before just writing the password, check if the program wants verification from you: normally supplying "y" or "n". This should only have to happen the first time the client connects. It looks like thisPLINK:
    The server's host key is not cached in the registry. You
    have no guarantee that the server is the computer you
    think it is.
    The server's key fingerprint is:
    1024 f8:43:61:4c:a2:5b:77:be:5b:a7:bb:1f:f7:79:b3:b7
    If you trust this host, enter "y" to add the key to
    PuTTY's cache and carry on connecting.
    If you want to carry on connecting just once, without
    adding the key to the cache, enter "n".
    If you do not trust this host, press Return to abandon the
    connection.
    Store key in cache? (y/n)
    SSH:
    The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
    RSA key fingerprint is e1:02:13:c8:52:c2:23:41:9b:5b:58:2c:18:e6:59:af.
    Are you sure you want to continue connecting (yes/no)?What I did was read character by character from the inputStream until I found things of interest ... like "password: ". You only need to search for this in your method which will launch the ssh or plink Process. Once you have verifyed yourself, you can just pass commands to the Process, which is an ssh connection.
    My suggestion is to read() each byte from the Process's inputStream and write it to stdout. Look and see what you need to be looking for so you can interactive with the program correctly. You can't use readLine here becuase when the ssh asks for the password it does not print a newline. I do know for sure, that ssh will simply print, "passowrd: ". Plink will print this as well if the -pw option is not supplied.

Maybe you are looking for