FTP客戶端程式

2021-05-25 13:02:58 字數 4061 閱讀 9565

ftp客戶端程式,vc6.0下除錯通過

client.c

#include "client.h"

#define sol_socket      0xffff   

int fill_host_addr(char *host_ip_addr,struct sockaddr_in *host,int port)

else

return 253;

}return 1;

}int xconnect(struct sockaddr_in *saddr,int type)

s= socket(af_inet, sock_stream, 0);

if (type == 1)

else

set = setsockopt(s, sol_socket, 0, &outtime, sizeof(outtime));

if(set == 0)

//connect to the server

if(connect(s, (struct sockaddr_in *)saddr, sizeof(struct sockaddr_in)))

else

printf("successfully connect to server /n");

return s;

}//send command to server with sock_fd

int ftp_send_cmd(const char* s1,const char* s2,int sock_fd)

else

strcat(send_buf,"/r/n");

len=strlen(send_buf);

send_err=send(sock_fd,send_buf,len,0);

}if(send_err<0)

printf("send error/n");

return send_err;

}//get the server's reply message for sock_fd

int ftp_get_reply(int sock_fd)

return reply_code;

}int get_port()

return 0;

}int xconnect_ftpdata()

}void get_user()

void get_pass()

int ftp_login()

return 1;

}else

int ftp_usr_cmd(char * cmd)

void ftp_cmd_filename(char * usr_cmd, char * src_file, char * dst_file)

else

if(cmd_src == null || cmd_src == '/0')

else

if((*(cmd_src+i)) == '//' && (*(cmd_src+i+1)) !=' ')

if((*(cmd_src+i)) == ' ' && (*(cmd_src+i-1)) != '//')

if((*(cmd_src+i)) == '//' && (*(cmd_src+i+1)) == ' ')

i++;}}

if(flag == 0)

strcpy(dst_file, src_file);

else

dst_file[j] = '/0';

}void ftp_bye()

void ftp_get(char*usr_cmd)

get_sock = xconnect_ftpdata(); 

if(get_sock < 0)

set = sizeof(local_host);

ftp_send_cmd("type i", null, sock_control);

ftp_get_reply(sock_control);

ftp_send_cmd("retr ", src_file, sock_control);

if(mode)

}fclose(local_file);

close(get_sock);

ftp_get_reply(sock_control); }}

void ftp_put(char*usr_cmd)

file_put_sock=xconnect_ftpdata();

if(file_put_sock<0)

set=sizeof(local_host);

k = ftp_send_cmd("stor ",dst_file,sock_control);

printf("mode = %d/n ", mode);

if(mode==1)

}fclose(local_file);

close(file_put_sock);

printf("sock_control =%d/n",sock_control);

ftp_get_reply(sock_control); }}

int run(char * server_ip,int port)

while(1)        }}

int main(int argc,char *argv)

client.h標頭檔案

#ifndef client_h

#define client_h

#include

#include

#include

#include

#include

#include "io.h"

//#include "unistd.h"

#include

#include

#include

//#include"echo.h"

#define default_port 21

//extern cfile cfile;

#pragma comment(lib,"ws2_32.lib")

char user[64];

char password[40];

struct sockaddr_in ftp_server,local_host;

struct hostent * server_hostent;

int sock_control = 0;

int mode=1;//1--pasv 0--port

//void cmd_err_exit(char* error_message,int error_code);

//相當於setaddress()

int fill_host_addr(char *host_ip_addr,struct sockaddr_in *host,int port);

int xconnect(struct sockaddr_in *saddr,int type);

//send command to server with sock_fd

int ftp_send_cmd(const char* s1,const char* s2,int sock_fd);

//get the server's reply message for sock_fd

int ftp_get_reply(int sock_fd);

int get_port();

int rand_local_port();

int xconnect_ftpdata();

void get_user();

void get_pass();

int ftp_login();

void ftp_bye();

void ftp_get(char*usr_cmd);

int ftp_usr_cmd(char * cmd);

void ftp_cmd_filename(char * usr_cmd, char * src_file, char * dst_file);

void ftp_put(char*usr_cmd);

int run(char * server_ip,int port);

#endif

ftp客戶端程式

include include include include include pragma comment lib,ws2 32.lib file fp socket client,upload wsadata wsadata int wsareturn int portnum char spor...

Python編寫FTP客戶端

之前寫過一篇ftp服務端的文章,這篇介紹一下客戶端吧。在使用虛擬機器的時候,由於虛擬機器工具沒安裝成功,所以我決定用ftp在主機與虛擬機器之間傳送檔案,在虛擬機器上開啟ftp服務,然後把客戶端放在主機上,當然也可以顛倒過來。服務端請參考 python實現ftp伺服器 import ftplib im...

ftp客戶端 學習筆記

檔案傳輸協議 ftp 作為網路共享檔案的傳輸協議,在網路應用軟體中具有廣泛的應用。ftp的目標是提高檔案的共享性和可靠高效地傳送資料。在傳輸檔案時,ftp 客戶端程式先與伺服器建立連線,然後向伺服器傳送命令。伺服器收到命令後給予響應,並執行命令。ftp 協議與作業系統無關,任何作業系統上的程式只要符...