title: SCP from remote host using groovy
body: <p>I am trying to SCP from a remote host using JSch. I have successfully copied file form remote host in java STS IDE. However, when I tried to run it in groovy script which I am executing using SOAP UI, I get following error.</p>
  
  <pre><code>Fri Jun 07 16:53:02 IST 2013:INFO:Exception : groovy.lang.MissingMethodException: No signature of method: java.lang.Byte.minus() is applicable for argument types: (java.lang.String) values: [0]
  Possible solutions: minus(java.lang.Number), minus(java.lang.Character), plus(java.lang.String), plus(java.lang.Character), plus(java.lang.Number), times(groovy.lang.Closure)
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>import com.jcraft.jsch.*;
  import java.io.*;
  import java.lang.*;
  
  
      FileOutputStream fos=null;
      try{
  
        String user="soapui";
        String host="192.168.1.1";
        String rfile="//bin//output.txt";
        String lfile="E://temp1.txt";
  
        String prefix=null;
        if(new File(lfile).isDirectory()){
          prefix=lfile+File.separator;
        }
  
        JSch jsch=new JSch();
        Session session=jsch.getSession(user, host, 22);
  
        // username and password will be given via UserInfo interface.
        UserInfo ui=new MyUserInfo();
        session.setUserInfo(ui);
        session.connect();
  
        // exec 'scp -f rfile' remotely
        String command="scp -f "+rfile;
        Channel channel=session.openChannel("exec");
        ((ChannelExec)channel).setCommand(command);
  
        // get I/O streams for remote scp
        OutputStream out=channel.getOutputStream();
        InputStream ins=channel.getInputStream();
  
        channel.connect();
  
        byte[] buf=new byte[10240];
  
        // send '\0'
        buf[0]=0; out.write(buf, 0, 1); out.flush();
  
        while(true){
      int c=checkAck(ins);
          if(c!='C'){
        break;
      }
  
          // read '0644 '
          ins.read(buf, 0, 5);
  
          long filesize=0L;
          while(true){
            if(ins.read(buf, 0, 1)&lt;0){
              // error
              break; 
            }
            if(buf[0]==' ')break;
            //char c1='0';
            //long tmp=Long.valueOf(buf[0]-'0');
            **filesize=filesize*10L+(long)(buf[0]-'0');**
          }
  
          String file=null;
          for(int i=0;;i++){
            ins.read(buf, i, 1);
            if(buf[i]==(byte)0x0a){
              file=new String(buf, 0, i);
              break;
        }
          }
  
      log.info("filesize="+filesize+", file="+file);
  
          // send '\0'
          buf[0]=0; out.write(buf, 0, 1); out.flush();
  
          // read a content of lfile
          fos=new FileOutputStream(prefix==null ? lfile : prefix+file);
          int foo;
          while(true){
            if(buf.length&lt;filesize) foo=buf.length;
        else foo=(int)filesize;
            foo=ins.read(buf, 0, foo);
            if(foo&lt;0){
              // error 
              break;
            }
            fos.write(buf, 0, foo);
            filesize-=foo;
            if(filesize==0L) break;
          }
          fos.close();
          fos=null;
          log.info("Closing Stream");
  
      if(checkAck(ins)!=0){
        System.exit(0);
      }
  
          // send '\0'
          buf[0]=0; out.write(buf, 0, 1); out.flush();
        }
  
        session.disconnect();
  
        System.exit(0);
      }
      catch(Exception e){
        log.info("Exception : " + e);
        try{if(fos!=null)fos.close();}catch(Exception ee){}
      }
  
  
    static int checkAck(InputStream ins) throws IOException{
      int b=ins.read();
      // b may be 0 for success,
      //          1 for error,
      //          2 for fatal error,
      //          -1
      if(b==0) return b;
      if(b==-1) return b;
  
      if(b==1 || b==2){
        StringBuffer sb=new StringBuffer();
        int c;
       while(c!='\n') {
      c=ins.read();
      sb.append((char)c);
        }
  
        if(b==1){ // error
      System.out.print(sb.toString());
        }
        if(b==2){ // fatal error
      System.out.print(sb.toString());
        }
      }
      return b;
    }
  
    public  class MyUserInfo implements UserInfo{
      public String getPassword(){ return passwd;}
      public boolean promptYesNo(String str){return true;} 
      String passwd="123";
      public String getPassphrase(){return null;}
      public boolean promptPassphrase(String message){return true;}
      public boolean promptPassword(String message){return true;}
      public void showMessage(String s){};
      }
  </code></pre>
  
  <p>What I have debugged is that on line <code>filesize=filesize*10L+(long)(buf[0]-'0');</code> of code, groovy fails and generates the exception groovy.lang.MissingMethodException: No signature of method: <code>java.lang.Byte.minus()</code>. Please suggest some solution to this issue.</p>