aboutsummaryrefslogtreecommitdiff
path: root/bin/netfileget
blob: 1b39f0f308694c731c9151a95bdb8182c387e3db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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