README.fish 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. FIles transferred over SHell protocol (V 0.0.3)
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. This protocol was designed for transferring files over a remote shell
  4. connection (rsh and compatibles). It can be as well used for transfers over
  5. rsh, and there may be other uses.
  6. Client sends requests of following form:
  7. #FISH_COMMAND
  8. equivalent shell commands,
  9. which may be multiline
  10. Only fish commands are defined here, shell equivalents are for your
  11. information only and will probably vary from implementation to
  12. implementation. Fish commands always have priority: server is
  13. expected to execute fish command if it understands it. If it does not,
  14. however, it can try the luck and execute shell command.
  15. Since version 4.7.3, the scripts that FISH sends to host machines after
  16. a command is transmitted are no longer hardwired in the Midnight
  17. Commander source code.
  18. First, mc looks for system-wide set of scripts, then it checks whether
  19. current user has host-specific overrides in his per-user mc
  20. configuration folder. User-defined overrides take priority over
  21. sytem-wide scripts if they exist. The order in which the folders are
  22. traversed is as follows:
  23. /usr/libexec/mc/fish
  24. ~/.mc/fish/<hostname>/
  25. Server's reply is multiline, but always ends with
  26. ### 000<optional text>
  27. line. ### is prefix to mark this line, 000 is return code. Return
  28. codes are superset to those used in ftp.
  29. There are few new exit codes defined:
  30. 000 don't know; if there were no previous lines, this marks COMPLETE
  31. success, if they were, it marks failure.
  32. 001 don't know; if there were no previous lines, this marks
  33. PRELIMinary success, if they were, it marks failure
  34. Connecting
  35. ~~~~~~~~~~
  36. Client uses "echo FISH:;/bin/sh" as command executed on remote
  37. machine. This should make it possible for server to distinguish FISH
  38. connections from normal rsh/ssh.
  39. Commands
  40. ~~~~~~~~
  41. #FISH
  42. echo; start_fish_server; echo '### 200'
  43. This command is sent at the beginning. It marks that client wishes to
  44. talk via FISH protocol. #VER command must follow. If server
  45. understands FISH protocol, it has option to put FISH server somewhere
  46. on system path and name it start_fish_server.
  47. #VER 0.0.2 <feature1> <feature2> <...>
  48. echo '### 000'
  49. This command is the second one. It sends client version and extensions
  50. to the server. Server should reply with protocol version to be used,
  51. and list of extensions accepted.
  52. VER 0.0.0 <feature2>
  53. ### 200
  54. #PWD
  55. pwd; echo '### 200'
  56. Server should reply with current directory (in form /abc/def/ghi)
  57. followed by line indicating success.
  58. #LIST /directory
  59. ls -lLa $1 | grep '^[^cbt]' | ( while read p x u g s m d y n; do echo "P$p $u.$g
  60. S$s
  61. d$m $d $y
  62. :$n
  63. "; done )
  64. ls -lLa $1 | grep '^[cb]' | ( while read p x u g a i m d y n; do echo "P$p $u.$g
  65. E$a$i
  66. dD$m $d $y
  67. :$n
  68. "; done )
  69. echo '### 200'
  70. This allows client to list directory or get status information about
  71. single file. Output is in following form (any line except :<filename>
  72. may be omitted):
  73. P<unix permissions> <owner>.<group>
  74. S<size>
  75. d<3-letters month name> <day> <year or HH:MM>
  76. D<year> <month> <day> <hour> <minute> <second>[.1234]
  77. E<major-of-device>,<minor>
  78. :<filename>
  79. L<filename symlink points to>
  80. <blank line to separate items>
  81. Unix permissions are of form X--------- where X is type of
  82. file. Currently, '-' means regular file, 'd' means directory, 'c', 'b'
  83. means character and block device, 'l' means symbolic link, 'p' means
  84. FIFO and 's' means socket.
  85. 'd' has three fields: month (one of strings Jan Feb Mar Apr May Jun
  86. Jul Aug Sep Oct Nov Dec), day of month, and third is either single
  87. number indicating year, or HH:MM field (assume current year in such
  88. case). As you've probably noticed, this is pretty broken; it is for
  89. compatibility with ls listing.
  90. #RETR /some/name
  91. ls -l /some/name | ( read a b c d x e; echo $x ); echo '### 100'; cat /some/name; echo '### 200'
  92. Server sends line with filesize on it, followed by line with ### 100
  93. indicating partial success, then it sends binary data (exactly
  94. filesize bytes) and follows them with (with no preceding newline) ###
  95. 200.
  96. Note that there's no way to abort running RETR command - except
  97. closing the connection.
  98. #STOR <size> /file/name
  99. > /file/name; echo '### 001'; ( dd bs=4096 count=<size/4096>; dd bs=<size%4096> count=1 ) 2>/dev/null | ( cat > %s; cat > /dev/null ); echo '### 200'
  100. This command is for storing /file/name, which is exactly size bytes
  101. big. You probably think I went crazy. Well, I did not: that strange
  102. cat > /dev/null has purpose to discard any extra data which was not
  103. written to disk (due to for example out of space condition).
  104. [Why? Imagine uploading file with "rm -rf /" line in it.]
  105. #CWD /somewhere
  106. cd /somewhere; echo '### 000'
  107. It is specified here, but I'm not sure how wise idea is to use this
  108. one: it breaks stateless-ness of the protocol.
  109. Following commands should be rather self-explanatory:
  110. #CHMOD 1234 file
  111. chmod 1234 file; echo '### 000'
  112. #DELE /some/path
  113. rm -f /some/path; echo '### 000'
  114. #MKD /some/path
  115. mkdir /some/path; echo '### 000'
  116. #RMD /some/path
  117. rmdir /some/path; echo '### 000'
  118. #RENAME /path/a /path/b
  119. mv /path/a /path/b; echo '### 000'
  120. #LINK /path/a /path/b
  121. ln /path/a /path/b; echo '### 000'
  122. #SYMLINK /path/a /path/b
  123. ln -s /path/a /path/b; echo '### 000'
  124. #CHOWN user /file/name
  125. chown user /file/name; echo '### 000'
  126. #CHGRP group /file/name
  127. chgrp group /file/name; echo '### 000'
  128. #INFO
  129. ...collect info about host into $result ...
  130. echo $result
  131. echo '### 200'
  132. #READ <offset> <size> /path/and/filename
  133. cat /path/and/filename | ( dd bs=4096 count=<offset/4096> > /dev/null;
  134. dd bs=<offset%4096> count=1 > /dev/null;
  135. dd bs=4096 count=<offset/4096>;
  136. dd bs=<offset%4096> count=1; )
  137. Returns ### 200 on successful exit, ### 291 on successful exit when
  138. reading ended at eof, ### 292 on successfull exit when reading did not
  139. end at eof.
  140. #WRITE <offset> <size> /path/and/filename
  141. Hmm, shall we define these ones if we know our client is not going to
  142. use them?
  143. you can use follow parameters:
  144. FISH_FILESIZE
  145. FISH_FILENAME
  146. FISH_FILEMODE
  147. FISH_FILEOWNER
  148. FISH_FILEGROUPE
  149. FISH_FILEFROM
  150. FISH_FILETO
  151. NB:
  152. 'FISH_FILESIZE' used if we operate with single file name in 'unlink', 'rmdir', 'chmod', etc...
  153. 'FISH_FILEFROM','FISH_FILETO' used if we operate with two files in 'ln', 'hardlink', 'mv' etc...
  154. 'FISH_FILEOWNER', 'FISH_FILEGROUPE' is a new user/group in chown
  155. also flags:
  156. FISH_HAVE_HEAD
  157. FISH_HAVE_SED
  158. FISH_HAVE_AWK
  159. FISH_HAVE_PERL
  160. FISH_HAVE_LSQ
  161. FISH_HAVE_DATE_MDYT
  162. That's all, folks!
  163. pavel@ucw.cz