#include <string.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <unistd.h>#include <ctype.h>#include <stdio.h>#include <time.h>#include "misc.h"#include "main.h"#include "ftp.h"#include "listparse.h"#include "tty.h"Functions | |
| hostent * | testhost (char *host) |
| int | testport (char *port) |
| int | ftp_connect (struct sock_hostport hostport) |
| char * | ftp_read (int sockfd) |
| char * | ftp_nread (int sockfd, int *size) |
| void | ftp_write (int sockfd, char *msg) |
| void | ftp_nwrite (int sockfd, char *msg, int length) |
| int | pasv_connect (char *output, struct sock_hostport pasv_info) |
| int | ftp_cwd (int sockfd, struct sock_hostport info, char *newdir) |
| void | ftp_retr (int sockfd, struct sock_hostport info, struct listparse *lp) |
| int | ftp_stor (int sockfd, struct sock_hostport info, FILE *fd, char *path, long int gsize) |
| char * | send_cmd (int sockfd, char *msg) |
| void | v_send_cmd (int sockfd, char *msg) |
| int ftp_connect | ( | struct sock_hostport | hostport | ) |
Connects to a host and port given in the struct.
| hostport | Where the host and port are to be found. |
| int ftp_cwd | ( | int | sockfd, | |
| struct sock_hostport | info, | |||
| char * | newdir | |||
| ) |
Change working directory on the server.
| sockfd | FTP socket descriptor. | |
| info | Hostname and port information. | |
| newdir | The directory we'd like to change to. |
| char* ftp_nread | ( | int | sockfd, | |
| int * | size | |||
| ) |
Like ftp_read, but also gives the amount of data read.
| sockfd | FTP socket descriptor. | |
| size | A pointer wherein will be placed the number of bytes read. |
| void ftp_nwrite | ( | int | sockfd, | |
| char * | msg, | |||
| int | length | |||
| ) |
Like ftp_write, but with length parameter.
| sockfd | FTP socket descriptor. | |
| msg | The data to send. | |
| length | The length of the data. |
| char* ftp_read | ( | int | sockfd | ) |
Reads 4 kilobytes from the socket given by sockfd. Puts this data into a char which is malloc'd. Thus, the pointer should be freed after use.
| sockfd | FTP socket descriptor. |
| void ftp_retr | ( | int | sockfd, | |
| struct sock_hostport | info, | |||
| struct listparse * | lp | |||
| ) |
Retrieve a file.
| sockfd | FTP socket descriptor. | |
| info | Hostname and port info. | |
| lp | The structure holding file information. |
| int ftp_stor | ( | int | sockfd, | |
| struct sock_hostport | info, | |||
| FILE * | fd, | |||
| char * | path, | |||
| long int | gsize | |||
| ) |
Send a file to the server.
| sockfd | FTP socket descriptor. | |
| info | Hostname and port info. | |
| fd | The descriptor for the file we want to send (on local machine). Note that the file should already be opened. | |
| path | Where we want to put the file on the remote machine. | |
| gsize | The given size of what we're sending, so we can check against it at the end. |
| void ftp_write | ( | int | sockfd, | |
| char * | msg | |||
| ) |
Send some data to the FTP server.
| sockfd | FTP socket descriptor. | |
| msg | The data to send. |
| int pasv_connect | ( | char * | output, | |
| struct sock_hostport | pasv_info | |||
| ) |
Given the output from PASV and the hostent structure, connects to the PASV port and returns the file descriptor for that socket.
| output | The output received from PASV. The format is non-standard, but is assured to begin with 227 and have 6 numbers separated by commas. | |
| pasv_info | Hostname and port information for the PASV address. |
| char* send_cmd | ( | int | sockfd, | |
| char * | msg | |||
| ) |
Saves time by abstraction. Writes to socket, reads from socket, and puts msg in status. Also returns the output in case we want to do something with it.
| sockfd | FTP socket descriptor. | |
| msg | What we want to appear in the status bar. |
| struct hostent* testhost | ( | char * | host | ) |
Tests whether the hostname is valid. Will return a hostent structure if it works out. If not, NULL. This function tries to figure out if something is IP address-like - if so, it'll use inet_aton and gethostbyaddr. If not, it'll use gethostbyname. Obviously if these things fail we'll just return NULL.
| host | The hostname given. |
| int testport | ( | char * | port | ) |
Simliar test as testhost, but for the port number. Much easier. At most 5 digits.
| port | The port number as a string. |
| void v_send_cmd | ( | int | sockfd, | |
| char * | msg | |||
| ) |
Like send_cmd, but doesn't return anything and frees up the memory for us.
| sockfd | FTP socket descriptor. | |
| msg | What we want to appear in the status bar. |
1.4.7.