SFTP permissions mismatch

That’s fine with me. It would good to document this in the PDFs, though. I didn’t notice any mention of the fact that, in site definitions, the beginning slash means a relative path from the user’s home directory rather than Linux’s usual absolute path from the root. That symlink idea works great, though.

Another route maybe to use opensource java jcraft (http://www.jcraft.com/) routines and hook this into the publishing script:

Here’s a small example of using the jcraft routines (below). The with the examples they include you could scp a tar file, extract, and update permissions.

package erau;
import com.jcraft.jsch.;
import java.io.
;

public class Task1
{
public Task1()
{
}

public static void main(String[] arg){

  try{



    String user="someuser";
    String host="someservre";
    String password="somepassword";
    String rfile="/test/20080107/somefile.txt";
    String lfile="somefile.txt";


    JSch jsch=new JSch();
    int port=22;
    Session session=jsch.getSession(user, host, 22);
    session.setPassword(password);
    
    session.setConfig("StrictHostKeyChecking", "no");
    session.connect();
    
    FileOutputStream fos=null;

    String prefix=null;
    if(new File(lfile).isDirectory()){
      prefix=lfile+File.separator;
    }

    //change dir
    //Channel schannel=session.openChannel("sftp");
    //ChannelSftp csftp=(ChannelSftp)schannel;      
    //csftp.lcd(path);

    String command = "";

    // exec 'scp -f rfile' remotely
    //command="cd "+path;
    //Channel channel=session.openChannel("exec");
    //((ChannelExec)channel).setCommand(command);


    // exec 'scp -f rfile' remotely
    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 in=channel.getInputStream();

    channel.connect();

    byte[] buf=new byte[1024];

    // send '\0'
    buf[0]=0; out.write(buf, 0, 1); out.flush();

    while(true){
     int c=checkAck(in);
      if(c!='C'){
        break;
      }//if

      // read '0644 '
      in.read(buf, 0, 5);

      long filesize=0L;
      while(true){
        if(in.read(buf, 0, 1)<0){
        // error
          break; 
        }
        
        if(buf[0]==' ')break;
          filesize=filesize*10L+(long)(buf[0]-'0');
      }//while

      String file=null;
      for(int i=0;;i++){
        in.read(buf, i, 1);
        if(buf[i]==(byte)0x0a){
          file=new String(buf, 0, i);
          break;
        }//if
      }//for

      //System.out.println("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<filesize) foo=buf.length;
        else foo=(int)filesize;
        foo=in.read(buf, 0, foo);
        if(foo<0){
          // error 
          break;
        }
      fos.write(buf, 0, foo);
      filesize-=foo;
      if(filesize==0L) break;
      }//while
      fos.close();
      fos=null;

     if(checkAck(in)!=0){
        System.exit(0);
      }

      // send '\0'
      buf[0]=0; out.write(buf, 0, 1); out.flush();
  }//while

  session.disconnect();

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

}//main

static int checkAck(InputStream in) throws IOException{
int b=in.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;
  do {

c=in.read();
sb.append((char)c);
}
while(c!=’
');
if(b==1){ // error
System.out.print(sb.toString());
}
if(b==2){ // fatal error
System.out.print(sb.toString());
}
}
return b;
}

}

For changing site roots this sed script may be handy:

#Update site root to from cm.erau.edu:9992/ERAU_Home to www.erau.edu/erau
find /home/tcuser/apache/htdocs -name ‘*.html’ -type f |
while read filename
do
sed ‘s/cm.erau.edu:9992/ERAU_Home/www.erau.edu/erau/g’ < $filename > ${filename}.modified
mv ${filename}.modified $filename # omit this line if you want to keep both versions
done

[QUOTE]
Another route maybe to use opensource java jcraft (http://www.jcraft.com/) routines and hook this into the publishing script:
[\QUOTE]

This is precisely what the “new SFTP plugin” is based on.

I have made some improvements in it (at Michael’s request) and it should be available from Tech Support upon request.

Dave