plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

netfileget (552B)


      1 #!/usr/local/plan9/bin/rc
      2 
      3 f=getfile
      4 if(~ $1 -d){
      5 	f=getdir
      6 	shift
      7 }
      8 
      9 if(! ~ $#* 2){
     10 	echo 'usage: netfileget [-d] system path' >[1=2]
     11 	exit usage
     12 }
     13 
     14 . netfilelib.rc $1
     15 
     16 fn getfile9p {
     17 	if(! 9p read $1/$2)
     18 		exit 1
     19 }
     20 
     21 fn getdir9p {
     22 	9p ls -l $1/$2 | awk '{s=$NF; if($0 ~ /^d/) s=s"/"; print s}'
     23 }
     24 
     25 fn getfile {
     26 	rm -f $t
     27 	echo get $2 $t | runsftp -e $1
     28 	cat $t
     29 }
     30 
     31 fn getdir {
     32 	{echo cd $2; echo ls -l} | runsftp $1
     33 	awk '
     34 		$NF == "." || $NF == ".." { next } 
     35 		{
     36 			s = $NF
     37 			if($0 ~ /^d/)
     38 				s = s "/"
     39 			print s
     40 		}
     41 	' $t.sftp
     42 }
     43 
     44 $f $1 $2
     45 exit 0
     46