ftp.h File Reference

Go to the source code of this file.

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)
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)


Detailed Description

The FTP backend.

Function Documentation

int ftp_connect ( struct sock_hostport  hostport  ) 

Connects to a host and port given in the struct.

Parameters:
hostport Where the host and port are to be found.
Returns:
The file descriptor of the socket used to connect.

int ftp_cwd ( int  sockfd,
struct sock_hostport  info,
char *  newdir 
)

Change working directory on the server.

Parameters:
sockfd FTP socket descriptor.
info Hostname and port information.
newdir The directory we'd like to change to.
Returns:
1 for success, else 0.

char* ftp_nread ( int  sockfd,
int *  size 
)

Like ftp_read, but also gives the amount of data read.

Parameters:
sockfd FTP socket descriptor.
size A pointer wherein will be placed the number of bytes read.
Returns:
The data read, or NULL if none was read.

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.

Parameters:
sockfd FTP socket descriptor.
Returns:
Whatever was read, or NULL if nothing was read.

void ftp_retr ( int  sockfd,
struct sock_hostport  info,
struct listparse lp 
)

Retrieve a file.

Parameters:
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.

Parameters:
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.
Returns:
1 if we were able to upload it (but not necessarily all the way), 0 if the server refused it or encountered some other problem.

void ftp_write ( int  sockfd,
char *  msg 
)

Send some data to the FTP server.

Parameters:
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.

Parameters:
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.
Returns:
A new file descriptor for the PASV socket.

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.

Parameters:
sockfd FTP socket descriptor.
msg What we want to appear in the status bar.
Returns:
Data read from socket.

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.

Parameters:
host The hostname given.
Returns:
A hostent structure with the appropriate fields filled in.

int testport ( char *  port  ) 

Simliar test as testhost, but for the port number. Much easier. At most 5 digits.

Parameters:
port The port number as a string.
Returns:
The port number as an int if it is valid, or 0 if not.

void v_send_cmd ( int  sockfd,
char *  msg 
)

Like send_cmd, but doesn't return anything and frees up the memory for us.

Parameters:
sockfd FTP socket descriptor.
msg What we want to appear in the status bar.


Generated by  doxygen 1.4.7.
SourceForge.net Logo