programming projects
That's exactly what we don't need on wrongplanet @NeantHumain; Hostiliy and sarcasm. That's what I lIke about WP, we can be ourselves without worry of redicule! Comments like that, make it hard to talk freely without worry of someone like you being hostile or replying sarcastically. We get that enough from the real world and all over the Internet. This is the last place we should have to worry about it. I don't know if that is how MyFutureSelfNMe feels but I do. That's what I took from your comment. If I am wrong, I apologize.
I don't read it as hostile or sarcastic, amboxer21.
The fact is that ftp isn't new and exciting; it's extremely well known and standardised - solutions implementing it practically drop out of the woodwork and if the only requirement was to throw a few files from A to B then clearly, there's no reason to write your own ftp client/server.
So writing an ftp server from the ground up using just the protocol documentation would be done for the joy of learning how it all works and fits together, something which wouldn't be possible by just using existing code - therefore it's an extremely valuable programming experience to have.
That's all NeantHumain is saying.
_________________
Giraffe: a ruminant with a view.
I did and I didn't ask you did I? Moderator or not.
The fact is that ftp isn't new and exciting; it's extremely well known and standardised
Sure FTP isn't new. As far as exciting goes, it is exciting to me! I love network programming! I love programming period!
Solutions implementing it do not drop out of the woodwork. For one, network programming is very fickle and one small mistake will cause the whole thing to not work! So one solution is not standard!
How else would one write a sever?? From the documentation of course. You implement specific function and add error handling. Then once the server has established a connection it does something that you specify. The documentation is only good for showing you how to create a socket. Not what to do after. That is up to the programmer. Weather the server/communication be synchronous or asynchronous, nothing will be the same as the last! You haven't done much network coding have you?
Who needs just experiences? Why not do it just to code it? Just because it is fun? That is why it is a hobby. I have a lot of network programming experience and have coded an FTP server before. I have written synchronous chat server/clients more times than i can count! I do it because I enjoy it and it is fun!
[/quote]
Lets hear that from NeantHumain then.
You talk like you can write one in no time. Hey maybe we should team up and make one with a UI? You don't sound like someone who enjoys programming though.
Dear oh dear. I'm really not sure why you've gone off like that but it seems rather hostile and quite unnecessary,
You gave your opinion on a public forum and I gave mine. That's all.
Solutions implementing ftp do in fact practically drop out of the woodwork - by which I mean, any OS is likely to have an ftp client available "out the box" and in many cases, an ftp server too.
The reason why ftp is so readily available for immediate use with no coding involved is because it's been standardised for quite a few years and consequently, many perfectly stable implementations of the protocol are available as client and server.
But that's the "easy" way of doing it.
Much more of a challenge - and so much more interesting - to write your own.
Of course that's correct: writing your own client/server is a different thing altogether and I quite agree; it can be very tricky
How else would one write a sever?? From the documentation of course. You implement specific function and add error handling. Then once the server has established a connection it does something that you specify. The documentation is only good for showing you how to create a socket. Not what to do after. That is up to the programmer. Weather the server/communication be synchronous or asynchronous, nothing will be the same as the last! You haven't done much network coding have you?
I also think you've misunderstood what I mean by protocol documentation. Establishing a connection via sockets is merely a prerequisite to enabling the ftp protocol to function, and of course there has to be documentation describing how ftp itself works - but this is above and beyond simply dealing with sockets and represents a whole new layer of challenges and fun.
So yes: first learn how to translate the socket documentation into an active connection - and then learn how to translate the ftp documentation into a functional ftp session. Two different tasks and both extremely interesting and great fun.
Who needs just experiences? Why not do it just to code it? Just because it is fun? That is why it is a hobby. I have a lot of network programming experience and have coded an FTP server before. I have written synchronous chat server/clients more times than i can count! I do it because I enjoy it and it is fun!
It's fun. It's an enjoyable and valuable programming experience to successfully convert a written description into functional code.
You seem to be saying the same thing.
_________________
Giraffe: a ruminant with a view.
You gave your opinion on a public forum and I gave mine. That's all.
Solutions implementing ftp do in fact practically drop out of the woodwork - by which I mean, any OS is likely to have an ftp client available "out the box" and in many cases, an ftp server too.
The reason why ftp is so readily available for immediate use with no coding involved is because it's been standardised for quite a few years and consequently, many perfectly stable implementations of the protocol are available as client and server.
But that's the "easy" way of doing it.
Much more of a challenge - and so much more interesting - to write your own.
Of course that's correct: writing your own client/server is a different thing altogether and I quite agree; it can be very tricky
How else would one write a sever?? From the documentation of course. You implement specific function and add error handling. Then once the server has established a connection it does something that you specify. The documentation is only good for showing you how to create a socket. Not what to do after. That is up to the programmer. Weather the server/communication be synchronous or asynchronous, nothing will be the same as the last! You haven't done much network coding have you?
I also think you've misunderstood what I mean by protocol documentation. Establishing a connection via sockets is merely a prerequisite to enabling the ftp protocol to function, and of course there has to be documentation describing how ftp itself works - but this is above and beyond simply dealing with sockets and represents a whole new layer of challenges and fun.
So yes: first learn how to translate the socket documentation into an active connection - and then learn how to translate the ftp documentation into a functional ftp session. Two different tasks and both extremely interesting and great fun.
Who needs just experiences? Why not do it just to code it? Just because it is fun? That is why it is a hobby. I have a lot of network programming experience and have coded an FTP server before. I have written synchronous chat server/clients more times than i can count! I do it because I enjoy it and it is fun!
It's fun. It's an enjoyable and valuable programming experience to successfully convert a written description into functional code.
You seem to be saying the same thing.
I would like to apologize. After calming down, I have realized I was hostile. Contradicting the original post i made that started this in the first pace. I am sorry Cornflake!! !! ! I don't want to argue. I guess I became used to being attacked on other boards; So I automatically go in defense mode and get hostile. that is not an excuse. Again, I am sorry!
Side note: I am tired of being attacked and pushed out by the regular boards(NON-ASPIE BOARDS). I am afraid to post anywhere. I will try to not let that follow me here!
For instance, One of those posts. It happens everywhere. I am tired of it!
BTW, I do not write my code from examples nor do I reference documentation. It's all up in my noggin. What i have learned from repitition and practice.
But the documentation is where i began and learned. I could whip up a chat server AND client in 30 minutes. Synchronous of course.

I was trying to work out what on earth I'd done to make you so angry!
_________________
Giraffe: a ruminant with a view.

I was trying to work out what on earth I'd done to make you so angry!
I got angry because I get attacked so much on regular forums because what is normal to me isn't to everyone else and I get ridiculed for it. I feel like that nerd/small guy in school who is always getting swirlied/bullied and can't do anything about it. It just happened again on a forum 30 minutes ago or so Here I'm codecaine21. So I thought maybe this was one of those times again. I'm sick of it and just trying to be apart of some community. Not only am I an outsider and loner in the real world but apparently on the internet too. <sighs>
I understand completely!
Lol I wish it was that simple. I spent a week on a UI. I had a problem with converting an ascii file into utf-8 before it would load into a textview widget. If code only feel into place haha
Anywho, if anyone wants to join; I fixed the ftp serve and client. It is up and running. No more data transfer issues. Just have to add to it now. Hopefully I can have someone on board by the time I get to the UI.
FTP_SERVER.c
#include <netdb.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc, char *argv[]) {
int sockfd, newsockfd, portno, binder, listener;
ssize_t bytes_read;
struct sockaddr_in serv_addr, cli_addr;
struct hostent *server;
socklen_t clilen;
char data[4096];
if(argc < 3) {
printf("Usage: %s ip address + port number.\n", argv[0]);
exit(EXIT_FAILURE);
}
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0) {
printf("SOCKET(-1) error ---> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
server = gethostbyname(argv[1]);
if(server == NULL) {
fprintf(stderr, "No such host.\n");
printf("%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
bzero((char *)&serv_addr, sizeof(serv_addr));
portno = atoi(argv[2]);
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(portno);
binder = bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
if(binder < 0) {
printf("BIND(-1) error ---> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
else if(socket) {
do {
{
printf("Waiting for a connection.\n");
}
}while(!accept);
}
listener = listen(sockfd, 20);
if(listener < 0) {
printf("LISTEN(-1) error ---> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
if(newsockfd == 0) {
printf("ACCEPT(0) error ---> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
if(newsockfd < 0) {
printf("ACCEPT(-1) error ---> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
if(accept) {
{
printf("Received connection from %s.\n", inet_ntoa(cli_addr.sin_addr));
}
}
FILE *file = fopen("file_in.txt", "wb");
if(file == NULL) {
printf("FOPEN(NULL) error --> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
bytes_read = read(newsockfd, data, sizeof(data));
if(bytes_read < 0) {
printf("READ(-1) error ---> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
else {
fprintf(file, "%s", data);
}
printf("File successfully recieved.\n");
close(newsockfd);
close(sockfd);
return 0;
}
FTP_CLIENT.c
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
int main(int argc, char *argv[]) {
int sockfd, portno, count = 0;
ssize_t /*bytes_read,*/ bytes_written;
struct hostent *server;
struct sockaddr_in serv_addr/*, cli_addr*/;
char buffer[4096];
if(argc < 4)
{
fprintf(stderr, "Ussage: %s + IP Address + port number + file path.\n", argv[0]);
exit(0);
}
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0) {
printf("SOCKET(-1) error ---> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
server = gethostbyname(argv[1]);
if(server == NULL) {
fprintf(stderr, "No such host.\n");
printf("%s\n", strerror(errno));
exit(EXIT_FAILURE);
}
portno = atoi(argv[2]); //Grabbing the port number from the command line
serv_addr.sin_family = AF_INET;
memcpy(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length);
serv_addr.sin_port = htons(portno);
if(connect(sockfd, (const struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
fprintf(stderr, "%s. CONNECT()\n", strerror(errno));
exit(EXIT_FAILURE);
}
else {
printf("Made a connection to %s\n", inet_ntoa(serv_addr.sin_addr));
}
FILE *file = fopen(argv[3], "rb");
fseek(file, 0, SEEK_END);
const int size = ftell(file);
fseek(file, 0, SEEK_SET);
if(file == NULL) {
printf("! FOPEN(NULL) error --> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
if(file < 0) {
printf("! FOPEN(-1) error --> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
else if(file) {
printf("File opened successfully.\n");
while(count < size) {
int bytes = fread(buffer, size, 1, file);
if(bytes < 0) {
printf("FREAD(-1) error --> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
count++;
}
}
if(count == size) {
printf("File was successfully sent.\n");
}
bytes_written = write(sockfd, buffer, strlen(buffer));
if(bytes_written < 0) {
printf("! WRITE(-1) error --> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
if(bytes_written == 0) {
printf("! WRITE(0) error --> %s.\n", strerror(errno));
exit(EXIT_FAILURE);
}
//}
close(sockfd);
return 0;
}
I have thought about that just so I can loop the server without having to use asynchronous calls like poll or select but being that the first arg of fopen relies on a CLI; It is making a little difficult for me to do so. I have always everything in main ever since i started and have become comfortable this way. I do not think maintainability will be a problem for me.
So pass it as a parameter to your function(s).
When you begin to work on larger projects you will quickly change your tune.
So pass it as a parameter to your function(s).
When you begin to work on larger projects you will quickly change your tune.
Yeah I've only been coding for a few years; 3 or 4. My usual projects are never more than 400 lines of code. I haven't had to worry about that yet.
I guess I could store the variables in a global struct and access them that way if I am going to make a separate function for my data handle. I'll fix it tomorrow. It's 3:30am and my laptop is away already. Plus I'm jamming out on the iPod laying down feeling lazy and tired.
I really don't think I'll be doing much more to it. It's a really simple program. As for the GUI, I have never worked with sockets and UI programming in the same project. For the first time I use those 2 together I think I want to add the UI to a synchronous chat. You know, a scrollable textview widget that takes in the data from the buffer. Not sure if conversion would be needed or not. I know if you are taking in a regular file, it would need to be converted because GTK uses UTF-8 by default.
I honk the actual challenge would be the creation of the socket. Since its not a UI but would have to coding using GTK functions. I have more experience with synchronous chat server/clients. So id start the socket/UI project there.
As far as the FTP server/client if that's the only suggestion you have, I am going to move on after that.
Update: I mean I could add little stuff like mallocing the array and using realloc if more than the allocated size is used. But I am bored with it.
No I find it interesting, I wrote a simple HTTP server a couple years ago and then wired it into the Ruby MRI for Ruby-esque "active server pages". 1400 lines total. Way more efficient than the mess that is Apache/PHP, with the notable exception that Ruby is a slow language. Wasn't a serious issue for what I was doing, which was to add a web based UI to what was effectively a desktop app.
Try not to have globals, especially when writing network software. They're something to be generally avoided, but especially with multithreaded software, which network software tends to be.
Try not to have globals, especially when writing network software. They're something to be generally avoided, but especially with multithreaded software, which network software tends to be.
I had no idea you were so good. A few years ago; I could only image what you could do now! I have always liked ruby. I've been meaning to check it out more! That's what all of those metasploit modules are written in too. It's a choice between ruby and Haskell.
But yeah man, I guess I have to step my game up a notch. Instead of writing these small UI's, and useless servers and clients; I need something bigger. A summer project. You know something that'll take me a few months.
Thanks for the advice btw!