diff options
author | rsc <devnull@localhost> | 2005-03-18 19:00:09 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-03-18 19:00:09 +0000 |
commit | f5874be6261edbe5fa48c3343c69b735b317c6d9 (patch) | |
tree | 4d35d60929b472e98a04fa9621849f7d8a86fb9e /bin | |
parent | 3ff8f72ec222c73f3733337d477bedb1481b350a (diff) | |
download | plan9port-f5874be6261edbe5fa48c3343c69b735b317c6d9.tar.gz plan9port-f5874be6261edbe5fa48c3343c69b735b317c6d9.tar.bz2 plan9port-f5874be6261edbe5fa48c3343c69b735b317c6d9.zip |
add for netfiles
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/netfileget | 32 | ||||
-rwxr-xr-x | bin/netfileput | 15 | ||||
-rwxr-xr-x | bin/netfilestat | 30 |
3 files changed, 77 insertions, 0 deletions
diff --git a/bin/netfileget b/bin/netfileget new file mode 100755 index 00000000..1b39f0f3 --- /dev/null +++ b/bin/netfileget @@ -0,0 +1,32 @@ +#!/usr/local/plan9/bin/rc + +f=getfile +if(~ $1 -d){ + f=getdir + shift +} + +if(! ~ $#* 2){ + echo 'usage: netget [-d] system path' >[1=2] + exit usage +} + +t=/tmp/netget.$pid.$USER +fn sigexit { rm -f $t } + +fn getfile { + rm -f $t + if(! echo get $2 $t | sftp -b - $1 >/dev/null) + exit 1 + cat $t +} + +fn getdir { + if(! {echo cd $2; echo ls -l} | sftp -b - $1 | sed '1,2d; s/sftp> //g; /^$/d' >$t) + exit 1 + cat $t | awk '$NF == "." || $NF == ".." { next } {s = $NF; if($0 ~ /^d/) s = s "/"; print s}' +} + +$f $1 $2 +exit 0 + diff --git a/bin/netfileput b/bin/netfileput new file mode 100755 index 00000000..9a5a396d --- /dev/null +++ b/bin/netfileput @@ -0,0 +1,15 @@ +#!/usr/local/plan9/bin/rc + +whatis '*' +if(! ~ $#* 2){ + echo 'usage: netput system path' >[1=2] + exit usage +} + +t=/tmp/netget.$pid.$USER +fn sigexit { rm -f $t } + +cat >$t +if(! echo put $t $2 | sftp -b - $1 >/dev/null) + exit 1 +exit 0 diff --git a/bin/netfilestat b/bin/netfilestat new file mode 100755 index 00000000..8e81cf69 --- /dev/null +++ b/bin/netfilestat @@ -0,0 +1,30 @@ +#!/usr/local/plan9/bin/rc + +if(! ~ $#* 2){ + echo usage: netisdir system path >[1=2] + exit usage +} + +t=/tmp/netisdir.$pid.$USER +fn sigexit { rm -f $t } + +{ + echo !echo XXX connected + echo cd $2 + echo !echo XXX directory exists +} | sftp -b - $1 >$t >[2=1] +if(9 grep -s XXX.directory.exists $t){ + echo directory + exit 0 +} +if(9 grep -s 'is not a directory' $t){ + echo file + exit 0 +} +cat $t | sed 's/sftp> //g; /^$/d; /XXX/d; /^cd /d' >[1=2] +if(! 9 grep -s XXX.connected $t){ + echo connect failed + exit 0 +} +echo nonexistent +exit 0 |