plan9port/src/cmd/netfiles/netfileget

46 lines
704 B
Text
Raw Normal View History

2005-03-18 19:30:22 +00:00
#!/usr/local/plan9/bin/rc
f=getfile
if(~ $1 -d){
f=getdir
shift
}
if(! ~ $#* 2){
2005-03-20 23:39:48 +00:00
echo 'usage: netfileget [-d] system path' >[1=2]
2005-03-18 19:30:22 +00:00
exit usage
}
ns=`{namespace}
if(u test -S $ns/$1)
f=$f^9p
t=/tmp/netget.$pid.$USER
fn sigexit { rm -f $t }
fn getfile {
rm -f $t
2005-03-20 23:39:48 +00:00
if(! echo get $2 $t | sftp -b /dev/stdin $1 >/dev/null)
2005-03-18 19:30:22 +00:00
exit 1
cat $t
}
fn getfile9p {
if(! 9p read $1/$2)
exit 1
}
fn getdir {
2005-03-20 23:39:48 +00:00
if(! {echo cd $2; echo ls -l} | sftp -b /dev/stdin $1 | sed '1,2d; s/sftp> //g; /^$/d' >$t)
2005-03-18 19:30:22 +00:00
exit 1
cat $t | awk '$NF == "." || $NF == ".." { next } {s = $NF; if($0 ~ /^d/) s = s "/"; print s}'
}
fn getdir9p {
9p ls -l $1/$2 | awk '{s=$NF; if($0 ~ /^d/) s=s"/"; print s}'
}
$f $1 $2
exit 0