-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,8 @@ modules.order | |
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
.directory | ||
.clang-format | ||
.projectile | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
all: ftp | ||
|
||
#The following lines contain the generic build options | ||
CC=gcc | ||
CPPFLAGS= | ||
CFLAGS=-g -Werror-implicit-function-declaration | ||
|
||
#List all the .o files here that need to be linked | ||
OBJS=ftp.o network.o | ||
|
||
|
||
network.o: network.c network.h common.h | ||
|
||
ftp.o: ftp.c ftp.h common.h network.h | ||
|
||
|
||
ftp: $(OBJS) | ||
$(CC) -o ftp $(OBJS) $(CLIBS) | ||
|
||
clean: | ||
rm -f *.o | ||
rm -f ftp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef __COMMON_H__ | ||
#define __COMMON_H__ | ||
|
||
|
||
#define BUF_SIZE 1024 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#include "ftp.h" | ||
#include "network.h" | ||
#include <strings.h> | ||
unsigned int sfd; // Control Connection fd | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
char line[MAX_LINE]; // stores terminal commands | ||
char *command, *parameter; | ||
int c; | ||
// 1 program | ||
// 2 server | ||
// 3 port | ||
if (argc < 2 || argc > 3) { | ||
fprintf (stderr, "Usage: %s <host> <port>\n", argv[0]); | ||
fprintf (stderr, " <host> The address of the ftp server.\n"); | ||
fprintf (stderr, " <port> Optional: Specifies the port the client should initiate connection on.\n"); | ||
return -1; | ||
} | ||
|
||
const char *port = argc == 3 ? argv[2] : DEFAULT_PORT; | ||
|
||
sfd = create_connection (argv[1], port); | ||
|
||
if (sfd < 0) | ||
exit (EXIT_FAILURE); | ||
|
||
char buffer[BUFSIZ]; | ||
memset (buffer, 0, BUFSIZ); | ||
|
||
if (read_response (buffer) <= 0) | ||
exit (EXIT_FAILURE); | ||
|
||
printf ("--> %s", buffer); | ||
|
||
while (1) { | ||
// show prompt, but only if input comes from a terminal | ||
if (isatty (STDIN_FILENO)) | ||
printf ("> "); | ||
|
||
if (!fgets (line, sizeof (line), stdin)) | ||
break; | ||
|
||
if (!strchr (line, '\n')) { | ||
while ((c = fgetc (stdin)) != EOF && c != '\n') | ||
; | ||
if (c == '\n') { | ||
//printErrorCommmandTooLong(stdout); | ||
fprintf (stdout, "%s", "ok"); | ||
continue; | ||
} | ||
} | ||
|
||
command = strtok (line, " \t\n\f\r\v"); | ||
if (!command) | ||
continue; // ignore blank lines; | ||
|
||
// get parameters if provided | ||
parameter = strtok (NULL, "\n\r"); | ||
|
||
int scode = executeCommand (command, parameter); | ||
} | ||
return 0; | ||
} | ||
|
||
int executeCommand (const char *command, const char *parameter) | ||
{ | ||
if (strcasecmp (command, "quit") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "user") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "pass") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "get") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "features") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "cd") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "nlist") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "pwd") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "put") == 0) { | ||
// todo | ||
} | ||
else if (strcasecmp (command, "delete") == 0) { | ||
// todo | ||
} | ||
else { | ||
// todo | ||
} | ||
} | ||
|
||
int send_msg (const char *msg) | ||
{ | ||
} | ||
|
||
int read_response (char *buf) | ||
{ | ||
ssize_t length = read (sfd, buf, BUFSIZ); | ||
return length; | ||
} | ||
|
||
// pasvr_t getPasvData() | ||
// { | ||
// } | ||
|
||
// void flush() | ||
// { | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef __FTCLIENT_H__ | ||
#define __FTCLIENT_H__ | ||
|
||
#define DEFAULT_PORT "21" | ||
#define MAX_LINE 256 | ||
|
||
typedef struct pasv_response { | ||
|
||
} pasvr_t; | ||
|
||
int read_response (char *buf); | ||
int send_msg(const char *msg); | ||
int executeCommand(const char *command, const char *parameter); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "network.h" | ||
#include "common.h" | ||
|
||
int create_connection (const char *host, const char *port) | ||
{ | ||
struct addrinfo hints; | ||
struct addrinfo *result, *rp; | ||
int sfd, s, j; | ||
size_t len; | ||
ssize_t nread; | ||
char buf[BUF_SIZE]; | ||
|
||
/* Obtain address(es) matching host/port */ | ||
memset (&hints, 0, sizeof (struct addrinfo)); | ||
hints.ai_family = PF_INET; /* Allow IPv4 */ | ||
hints.ai_socktype = SOCK_STREAM; | ||
hints.ai_flags = 0; | ||
hints.ai_protocol = 0; /* Any protocol */ | ||
|
||
s = getaddrinfo (host, port, &hints, &result); | ||
if (s != 0) { | ||
fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s)); | ||
return -1; | ||
} | ||
|
||
/* getaddrinfo() returns a list of address structures. | ||
Try each address until we successfully connect(2). | ||
If socket(2) (or connect(2)) fails, we (close the socket | ||
and) try the next address. */ | ||
|
||
for (rp = result; rp != NULL; rp = rp->ai_next) { | ||
sfd = socket (rp->ai_family, rp->ai_socktype, | ||
rp->ai_protocol); | ||
if (sfd == -1) | ||
continue; | ||
|
||
if (connect (sfd, rp->ai_addr, rp->ai_addrlen) != -1) | ||
break; /* Success */ | ||
|
||
close (sfd); | ||
} | ||
|
||
if (rp == NULL) { /* No address succeeded */ | ||
fprintf (stderr, "Could not connect\n"); | ||
return -1; | ||
} | ||
|
||
freeaddrinfo (result); /* No longer needed */ | ||
|
||
return sfd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef __NETWORK_H__ | ||
#define __NETWORK_H__ | ||
|
||
#include <netdb.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
int create_connection (const char *host, const char *port); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|