README.fish 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. FIles transferred over SHell protocol (V 0.0.2)
  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. Server's reply is multiline, but always ends with
  16. ### 000<optional text>
  17. line. ### is prefix to mark this line, 000 is return code. Return
  18. codes are superset to those used in ftp.
  19. There are few new exit codes defined:
  20. 000 don't know; if there were no previous lines, this marks COMPLETE
  21. success, if they were, it marks failure.
  22. 001 don't know; if there were no previous lines, this marks
  23. PRELIMinary success, if they were, it marks failure
  24. Connecting
  25. ~~~~~~~~~~
  26. Client uses "echo FISH:;/bin/sh" as command executed on remote
  27. machine. This should make it possible for server to distinguish FISH
  28. connections from normal rsh/ssh.
  29. Commands
  30. ~~~~~~~~
  31. #FISH
  32. echo; start_fish_server; echo '### 200'
  33. This command is sent at the beginning. It marks that client wishes to
  34. talk via FISH protocol. #VER command must follow. If server
  35. understands FISH protocol, it has option to put FISH server somewhere
  36. on system path and name it start_fish_server.
  37. #VER 0.0.2 <feature1> <feature2> <...>
  38. echo '### 000'
  39. This command is the second one. It sends client version and extensions
  40. to the server. Server should reply with protocol version to be used,
  41. and list of extensions accepted.
  42. VER 0.0.0 <feature2>
  43. ### 200
  44. #PWD
  45. pwd; echo '### 200'
  46. Server should reply with current directory (in form /abc/def/ghi)
  47. followed by line indicating success.
  48. #LIST /directory
  49. ls -lLa $1 | grep '^[^cbt]' | ( while read p x u g s m d y n; do echo "P$p $u.$g
  50. S$s
  51. d$m $d $y
  52. :$n
  53. "; done )
  54. ls -lLa $1 | grep '^[cb]' | ( while read p x u g a i m d y n; do echo "P$p $u.$g
  55. E$a$i
  56. dD$m $d $y
  57. :$n
  58. "; done )
  59. echo '### 200'
  60. This allows client to list directory or get status information about
  61. single file. Output is in following form (any line except :<filename>
  62. may be omitted):
  63. P<unix permissions> <owner>.<group>
  64. S<size>
  65. d<3-letters month name> <day> <year or HH:MM>
  66. D<year> <month> <day> <hour> <minute> <second>[.1234]
  67. E<major-of-device>,<minor>
  68. :<filename>
  69. L<filename symlink points to>
  70. <blank line to separate items>
  71. Unix permissions are of form X--------- where X is type of
  72. file. Currently, '-' means regular file, 'd' means directory, 'c', 'b'
  73. means character and block device, 'l' means symbolic link, 'p' means
  74. FIFO and 's' means socket.
  75. 'd' has three fields: month (one of strings Jan Feb Mar Apr May Jun
  76. Jul Aug Sep Oct Nov Dec), day of month, and third is either single
  77. number indicating year, or HH:MM field (assume current year in such
  78. case). As you've probably noticed, this is pretty broken; it is for
  79. compatibility with ls listing.
  80. #RETR /some/name
  81. ls -l /some/name | ( read a b c d x e; echo $x ); echo '### 100'; cat /some/name; echo '### 200'
  82. Server sends line with filesize on it, followed by line with ### 100
  83. indicating partial success, then it sends binary data (exactly
  84. filesize bytes) and follows them with (with no preceding newline) ###
  85. 200.
  86. Note that there's no way to abort running RETR command - except
  87. closing the connection.
  88. #STOR <size> /file/name
  89. > /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'
  90. This command is for storing /file/name, which is exactly size bytes
  91. big. You probably think I went crazy. Well, I did not: that strange
  92. cat > /dev/null has purpose to discard any extra data which was not
  93. written to disk (due to for example out of space condition).
  94. [Why? Imagine uploading file with "rm -rf /" line in it.]
  95. #CWD /somewhere
  96. cd /somewhere; echo '### 000'
  97. It is specified here, but I'm not sure how wise idea is to use this
  98. one: it breaks stateless-ness of the protocol.
  99. Following commands should be rather self-explanatory:
  100. #CHMOD 1234 file
  101. chmod 1234 file; echo '### 000'
  102. #DELE /some/path
  103. rm -f /some/path; echo '### 000'
  104. #MKD /some/path
  105. mkdir /some/path; echo '### 000'
  106. #RMD /some/path
  107. rmdir /some/path; echo '### 000'
  108. #RENAME /path/a /path/b
  109. mv /path/a /path/b; echo '### 000'
  110. #LINK /path/a /path/b
  111. ln /path/a /path/b; echo '### 000'
  112. #SYMLINK /path/a /path/b
  113. ln -s /path/a /path/b; echo '### 000'
  114. #CHOWN user /file/name
  115. chown user /file/name; echo '### 000'
  116. #CHGRP group /file/name
  117. chgrp group /file/name; echo '### 000'
  118. #READ <offset> <size> /path/and/filename
  119. cat /path/and/filename | ( dd bs=4096 count=<offset/4096> > /dev/null;
  120. dd bs=<offset%4096> count=1 > /dev/null;
  121. dd bs=4096 count=<offset/4096>;
  122. dd bs=<offset%4096> count=1; )
  123. Returns ### 200 on successful exit, ### 291 on successful exit when
  124. reading ended at eof, ### 292 on successfull exit when reading did not
  125. end at eof.
  126. #WRITE <offset> <size> /path/and/filename
  127. Hmm, shall we define these ones if we know our client is not going to
  128. use them?
  129. That's all, folks!
  130. pavel@ucw.cz