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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
|
<pre>Network Working Group Mark K. Lottor
Request for Comments: 913 MIT
September 1984
<span class="h1">Simple File Transfer Protocol</span>
STATUS OF THIS MEMO
This RFC suggests a proposed protocol for the ARPA-Internet
community, and requests discussion and suggestions for improvements.
Distribution of this memo is unlimited.
INTRODUCTION
SFTP is a simple file transfer protocol. It fills the need of people
wanting a protocol that is more useful than TFTP but easier to
implement (and less powerful) than FTP. SFTP supports user access
control, file transfers, directory listing, directory changing, file
renaming and deleting.
SFTP can be implemented with any reliable 8-bit byte stream oriented
protocol, this document describes its TCP specification. SFTP uses
only one TCP connection; whereas TFTP implements a connection over
UDP, and FTP uses two TCP connections (one using the TELNET
protocol).
THE PROTOCOL
SFTP is used by opening a TCP connection to the remote hosts' SFTP
port (115 decimal). You then send SFTP commands and wait for
replies. SFTP commands sent to the remote server are always 4 ASCII
letters (of any case) followed by a space, the argument(s), and a
<NULL>. The argument can sometimes be null in which case the command
is just 4 characters followed by <NULL>. Replies from the server are
always a response character followed immediately by an ASCII message
string terminated by a <NULL>. A reply can also be just a response
character and a <NULL>.
<command> : = <cmd> [<SPACE> <args>] <NULL>
<cmd> : = USER ! ACCT ! PASS ! TYPE ! LIST ! CDIR
KILL ! NAME ! DONE ! RETR ! STOR
<response> : = <response-code> [<message>] <NULL>
<response-code> : = + | - | | !
<message> can contain <CRLF>
Commands that can be sent to the server are listed below. The server
<span class="grey">Lottor [Page 1]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-2" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
replies to each command with one of the possible response codes
listed under each message. Along with the response, the server
should optionally return a message explaining the error in more
detail. Example message texts are listed but do not have to be
followed. All characters used in messages are ASCII 7-bit with the
high-order bit zero, in an 8 bit field.
The response codes and their meanings:
+ Success.
- Error.
An error occurred while processing your command.
Number.
The number-sign is followed immediately by ASCII digits
representing a decimal number.
! Logged in.
You have sent enough information to be able to log yourself in.
This is also used to mean you have sent enough information to
connect to a directory.
To use SFTP you first open a connection to the remote SFTP server.
The server replies by sending either a positive or negative greeting,
such as:
+MIT-XX SFTP Service
(the first word should be the host name)
-MIT-XX Out to Lunch
<span class="grey">Lottor [Page 2]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-3" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
If the server send back a '-' response it will also close the
connection, otherwise you must now send a USER command.
USER user-id
Your userid on the remote system.
The reply to this command will be one of:
!<user-id> logged in
Meaning you don't need an account or password or you
specified a user-id not needing them.
+User-id valid, send account and password
-Invalid user-id, try again
If the remote system does not have user-id's then you should
send an identification such as your personal name or host name
as the argument, and the remote system would reply with '+'.
ACCT account
The account you want to use (usually used for billing) on the
remote system.
Valid replies are:
! Account valid, logged-in
Account was ok or not needed. Skip the password.
+Account valid, send password
Account ok or not needed. Send your password next.
-Invalid account, try again
<span class="grey">Lottor [Page 3]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-4" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
PASS password
Your password on the remote system.
Valid replies are:
! Logged in
Password is ok and you can begin file transfers.
+Send account
Password ok but you haven't specified the account.
-Wrong password, try again
<span class="grey">Lottor [Page 4]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-5" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
You cannot specify any of the following commands until you receive a
'!' response from the remote system.
TYPE { A | B | C }
The mapping of the stored file to the transmission byte stream
is controlled by the type. The default is binary if the type
is not specified.
A - ASCII
The ASCII bytes are taken from the file in the source
system, transmitted over the connection, and stored in the
file in the destination system.
The data is the 7-bit ASCII codes, transmitted in the
low-order 7 bits of 8-bit bytes. The high-order bit of the
transmission byte must be zero, and need not be stored in
the file.
The data is "NETASCII" and is to follow the same rules as
data sent on Telnet connections. The key requirement here
is that the local end of line is to be converted to the pair
of ASCII characters CR and LF when transmitted on the
connection.
For example, TOPS-20 machines have 36-bit words. On TOPS-20
machines, The standard way of labeling the bits is 0 through
35 from high-order to low-order. On TOPS-20 the normal way
of storing ASCII data is to use 5 7-bit bytes per word. In
ASCII mode, the bytes transmitted would be [0-6], [7-13],
[14-20], [21-27], [28-34], (bit 35 would not be
transmitted), each of these 7-bit quantities would be
transmitted as the low-order 7 bits of an 8-bit byte (with
the high-order bit zero).
For example, one disk page of a TOPS-20 file is 512 36-bit
words. But using only 35 bits per word for 7-bit bytes, a
page is 17920 bits or 2560 bytes.
<span class="grey">Lottor [Page 5]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-6" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
B - BINARY
The 8-bit bytes are taken from the file in the source
system, transmitted over the connection, and stored in the
file in the destination system.
The data is in 8-bit units. In systems with word sizes
which are not a multiple of 8, some bits of the word will
not be transmitted.
For example, TOPS-20 machines have 36-bit words. In binary
mode, the bytes transmitted would be [0-7], [8-15], [16-23],
[24-31], (bits 32-35 would not be transmitted).
For example, one disk page of a TOPS-20 file is 512 36-bit
words. But using only 32 bits per word for 8-bit bytes, a
page is 16384 bits or 2048 bytes.
C - CONTINUOUS
The bits are taken from the file in the source system
continuously, ignoring word boundaries, and sent over the
connection packed into 8-bit bytes. The destination system
stores the bits received into the file continuously,
ignoring word boundaries.
For systems on machines with a word size that is a multiple
of 8 bits, the implementation of binary and continuous modes
should be identical.
For example, TOPS-20 machines have 36-bit words. In
continuous mode, the bytes transmitted would be [first word,
bits 0-7], [first word, bits 8-15], [first word, bits
16-23], [first word, bits 24-31], [first word, bits 32-35 +
second word, bits 0-3], [second word, bits 4-11], [second
word, bits 12-19], [second word, bits 20-27], [second word,
bits 28-35], then the pattern repeats.
For example, one disk page of a TOPS-20 file is 512 36-bit
words. This is 18432 bits or 2304 8-bit bytes.
Replies are:
+Using { Ascii | Binary | Continuous } mode
-Type not valid
<span class="grey">Lottor [Page 6]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-7" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
LIST { F | V } directory-path
A null directory-path will return the current connected
directory listing.
F specifies a standard formatted directory listing.
An error reply should be a '-' followed by the error message
from the remote systems directory command. A directory
listing is a '+' followed immediately by the current
directory path specification and a <CRLF>. Following the
directory path is a single line for each file in the
directory. Each line is just the file name followed by
<CRLF>. The listing is terminated with a <NULL> after the
last <CRLF>.
V specifies a verbose directory listing.
An error returns '-' as above. A verbose directory listing
is a '+' followed immediately by the current directory path
specification and a <CRLF>. It is then followed by one line
per file in the directory (a line ending in <CRLF>). The
line returned for each file can be of any format. Possible
information to return would be the file name, size,
protection, last write date, and name of last writer.
<span class="grey">Lottor [Page 7]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-8" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
CDIR new-directory
This will change the current working directory on the remote
host to the argument passed.
Replies are:
!Changed working dir to <new-directory>
-Can't connect to directory because: (reason)
+directory ok, send account/password
If the server replies with '+' you should then send an ACCT or
PASS command. The server will wait for ACCT or PASS commands
until it returns a '-' or '!' response.
Replies to ACCT could be:
!Changed working dir to <new-directory>
+account ok, send password
-invalid account
Replies to PASS could be:
!Changed working dir to <new-directory>
+password ok, send account
-invalid password
KILL file-spec
This will delete the file from the remote system.
Replies are:
+<file-spec> deleted
-Not deleted because (reason)
<span class="grey">Lottor [Page 8]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-9" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
NAME old-file-spec
Renames the old-file-spec to be new-file-spec on the remote
system.
Replies:
+File exists
-Can't find <old-file-spec>
NAME command is aborted, don't send TOBE.
If you receive a '+' you then send:
TOBE new-file-spec
The server replies with:
+<old-file-spec> renamed to <new-file-spec>
-File wasn't renamed because (reason)
DONE
Tells the remote system you are done.
The remote system replies:
+(the message may be charge/accounting info)
and then both systems close the connection.
<span class="grey">Lottor [Page 9]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-10" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
RETR file-spec
Requests that the remote system send the specified file.
Receiving a '-' from the server should abort the RETR command
and the server will wait for another command.
The reply from the remote system is:
<number-of-bytes-that-will-be-sent> (as ascii digits)
-File doesn't exist
You then reply to the remote system with:
SEND (ok, waiting for file)
The file is then sent as a stream of exactly the number
of 8-bit bytes specified. When all bytes are received
control passes back to you (the remote system is waiting
for the next command). If you don't receive a byte
within a reasonable amount of time you should abort the
file transfer by closing the connection.
STOP (You don't have enough space to store file)
Replies could be:
+ok, RETR aborted
You are then ready to send another command to the remote host.
<span class="grey">Lottor [Page 10]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-11" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
STOR { NEW | OLD | APP } file-spec
Tells the remote system to receive the following file and save
it under that name.
Receiving a '-' should abort the STOR command sequence and the
server should wait for the next command.
NEW specifies it should create a new generation of the file and
not delete the existing one.
Replies could be:
+File exists, will create new generation of file
+File does not exist, will create new file
-File exists, but system doesn't support generations
OLD specifies it should write over the existing file, if any,
or else create a new file with the specified name.
Replies could be:
+Will write over old file
+Will create new file
(OLD should always return a '+')
APP specifies that what you send should be appended to the file
on the remote site. If the file doesn't exist it will be
created.
Replies could be:
+Will append to file
+Will create file
(APP should always return a '+')
<span class="grey">Lottor [Page 11]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-12" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
You then send:
SIZE <number-of-bytes-in-file> (as ASCII digits)
where number-of-bytes-in-file
is the exact number of 8-bit bytes you will be
sending.
The remote system replies:
+ok, waiting for file
You then send the file as exactly the number of bytes
specified above.
When you are done the remote system should reply:
+Saved <file-spec>
-Couldn't save because (reason)
-Not enough room, don't send it
This aborts the STOR sequence, the server is waiting for
your next command.
You are then ready to send another command to the remote host.
<span class="grey">Lottor [Page 12]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-13" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
AN EXAMPLE
An example file transfer. 'S' is the sender, the user process. 'R'
is the reply from the remote server. Remember all server replies are
terminated with <NULL>. If the reply is more than one line each line
ends with a <CRLF>.
R: (listening for connection)
S: (opens connection to R)
R: +MIT-XX SFTP Service
S: USER MKL
R: +MKL ok, send password
S: PASS foo
R: ! MKL logged in
S: LIST F PS: <MKL>
R: +PS: <MKL>
Small.File
Large.File
S: LIST V
R: +PS: <MKL>
Small.File 1 69(7) P775240 2-Aug-84 20:08 MKL
Large.File 100 255999(8) P770000 9-Dec-84 06:04 MKL
S: RETR SMALL.FILE
R: 69
S: SEND
R: This is a small file, the file is sent without
a terminating null.
S: DONE
R: +MIT-XX closing connection
<span class="grey">Lottor [Page 13]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-14" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
EDITORS NOTE
Mark Lotter receives full credit for all the good ideas in this memo.
As RFC editor, i have made an number of format changes, a few wording
changes, and one or two technical changes (mostly in the TYPEs). I
accept full responsibility for any flaws i may have introduced.
A draft form of this memo was circulated for comments. I will
attempt to list the issues raised and summarize the pros and cons,
and resolution for each.
ASCII Commands vs Binary Operation Codes
The ASCII command style is easier to debug, the extra
programming cost in minimal, the extra transmission cost is
trivial.
Binary operation codes are more efficient, and a few days of
debugging should not out weigh years of use.
Resolution: I have kept the ASCII Commands.
Additional Modes
Pro: For some machines you can't send all the bits in a word
using this protocol. There should be some additional mode to
allow it.
Con: Forget it, this is supposed to be SIMPLE file transfer.
If you need those complex modes use real FTP.
Resolution: I have added the Continuous mode.
<span class="grey">Lottor [Page 14]</span></pre>
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-15" ></span>
<span class="grey"><a href="./rfc913">RFC 913</a> September 1984</span>
Simple File Transfer Protocol
CRLF Conversion
Pro: In ASCII type, convert the local end of line indicator to
CRLF on the way out of the host and onto the network.
Con: If you require that you have to look at the bytes as you
send them, otherwise you can just send them. Most of the time
both sides will have the same end of line convention anyway.
If someone needs a conversion it can be done with a TECO macro
separately.
Resolution: I have required CRLF conversion in ASCII type. If
you have the same kind of machines and the same end of line
convention you can avoid the extra cost of conversion by using
the binary or continuous type.
TCP Urgent
Pro: Use TCP Urgent to abort a transfer, instead of aborting
the connection. Then one could retry the file, or try a
different file without having to login again.
Con: That would couple SFTP to TCP too much. SFTP is supposed
to be able to be work over any reliable 8-bit data stream.
Resolution: I have not made use of TCP Urgent.
Random Access
Pro: Wouldn't it be nice if (WIBNIF) SFTP had a way of
accessing parts of a file?
Con: Forget it, this is supposed to be SIMPLE file transfer.
If you need random access use real FTP (oops, real FTP doesn't
have random access either -- invent another protocol?).
Resolution: I have not made any provision for Random Access.
-- jon postel.
Lottor [Page 15]
</pre>
|