Reputation:
I am creating an FTP server as a school project, most of the commands are working and I almost nailed PORT
(active mode for data transfer).
Launching my server using ftp like such:
ftp localhost 4242 // where 4242 is the port on which my server is listening
And using the command ls
after logging in, I receive a working ls
output followed by this message:
WARNING! 8 bare linefeeds received in ASCII mode File may not have transferred correctly.
Please note that when using ls
in ftp
, it switches automatically to Active Mode before using the LIST
command.
What does this error signify?
Full output:
200 Active Mode Enabled.
150 Directory listing.
total 56
drwxrwxr-x 4 kade_c kade_c 4096 mai 12 15:24 .
drwxr-xr-x 38 kade_c kade_c 4096 mai 12 14:58 ..
drwxrwxr-x 8 kade_c kade_c 4096 mai 12 15:17 .git
-rw-rw-r-- 1 kade_c kade_c 1726 mai 11 10:35 Makefile
-rw-rw-r-- 1 kade_c kade_c 161 mai 11 11:43 README.txt
-rwxrwxr-x 1 kade_c kade_c 29368 mai 12 15:24 server
drwxrwxr-x 4 kade_c kade_c 4096 mai 2 18:40 server_src
WARNING! 8 bare linefeeds received in ASCII mode
File may not have transferred correctly.
226 LIST complete.
And finally, here is the part of the code that creates, and connects to the socket and does the ls -la
:
server_write(client, "150 Directory listing.\r\n");
if (connect_data(client) == -1) // Creates socket and connects to it
{
server_write(client, "520 Impossible to reach client.\r\n");
return;
}
ofd = xdup(1);
xdup2(client->data.socket, 1);
system("ls -la");
xdup2(ofd, 1);
server_write(client, "226 LIST complete.\r\n");
close_data(client, -1);
Upvotes: 4
Views: 12560
Reputation: 71
This issue is because you are downloading files in ASCII mode. Switching to binary mode will make the warning disappear.
Once you login to the FTP server, type binary
and then start downloading.
ftp> binary
200 Type set to I.
You only have to run this command once per FTP session.
Upvotes: 6
Reputation: 202682
I'd guess that you send LF's to the client, and the client (rightly) expects CRLF's and warns about those missing CR's.
According to FTP specification, RFC 959, section 3.4. Transmission modes, in the ASCII mode, you need to use CRLF exclusively:
For the purpose of standardized transfer, the sending host will translate its internal end of line or end of record denotation into the representation prescribed by the transfer mode and file structure, and the receiving host will perform the inverse translation to its internal denotation. ... End-of-line in an ASCII file with no record structure should be indicated by
<CRLF>
Upvotes: 1