当前位置: 技术问答>linux和unix
关于solaris ftp 上传文件至服务器的问题,急!!!!!!
来源: 互联网 发布时间:2015-11-23
本文导语: 同样的代码,我上传至windows的ftp服务器是可以的。但是上传至solaris ftp服务器就无法上传,请大侠指点,这是什么问题啊。。。。???? #include #include #include #include #include #include #include #include #include ...
同样的代码,我上传至windows的ftp服务器是可以的。但是上传至solaris ftp服务器就无法上传,请大侠指点,这是什么问题啊。。。。????
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ELOG __FILE__,__LINE__
#define FAIL 0
#define SUCCESS 1
#define FTPFIELD "FTPCONFIG"
#define HOSTADDR "HOST"
#define FTPPORT "PORT"
#define USERNAME "USERNAME"
#define PASSWORD "PASSWORD"
#define LOCALPATH "LOCALPATH"
#define REMOTEPATH "REMOTEPATH"
extern int h_errno;
char user[64]; //ftp usr
char passwd[64]; //ftp passwd
//ftp server address
struct sockaddr_in ftp_server, local_host;
struct hostent * server_hostent;
int sock_control;
int mode = 1; //ftp mode, 0 is PORT, 1 is PASV;
int printinfo(char * filename, int line, const char *format, ...)
{
va_list args;
va_start(args, format);
printf("%st%dt:", filename, line);
vprintf(format, args);
va_end(args);
return 0;
}
/*-------------------------------------------------------*/
/* ridtail -- get rid of a string's newline character */
/*-------------------------------------------------------*/
char *ridtail(char *c_buffer)
{
char *ctmp;
int ilength;
int len;
len = strlen(c_buffer);
ctmp = (char*)malloc(len);
if (ctmp == NULL) {
printf("f_ridtail::malloc fail!n");
return c_buffer;
}
memset(ctmp, 0, len);
if (*(c_buffer+len-1) == 0x0a) {
if (*(c_buffer+len-2) == 0x0d)
ilength = 2;
else
ilength = 1;
} else {
if (*(c_buffer+len-1) == 0x0d)
ilength = 1;
else
ilength = 0;
}
memcpy(ctmp, c_buffer, len-ilength);
memset(c_buffer, 0, len);
memcpy(c_buffer, ctmp, len-ilength);
free(ctmp);
return c_buffer;
}
/*-----------------------------------------------------------*/
/* rridtabspc -- get rid of the right tab of string*/
/*-----------------------------------------------------------*/
char * rridtabspc(char *as_string)
{
int li_i;
for( li_i = strlen(as_string) - 1 ; li_i >= 0; li_i -- ) {
if ((*(as_string + li_i) == ' ')||(*(as_string + li_i) == 0x09)) {
*(as_string + li_i) = '';
continue;
} else
break;
}
return as_string;
}
/*----------------------------------------*/
/* Read ini file to get private information */
/* 0 -- success, -1 -- failure */
/*----------------------------------------*/
int getprotocol(char *filename, char* cfldname, char* ckey, char* cvalue)
{
FILE *fp;
char crecord[1024];
char cfld[70];
char *p = NULL;
char *s = NULL;
char *e = NULL;
char skey[20];
char ctmp[500], ctmp2[500];
int ilen;
int ifind = FAIL;
rridtabspc(cfldname);
rridtabspc(ckey);
if ((fp = fopen(filename, "rb")) == NULL) {
perror("open file failed!n");
return -1;
}
while(!feof(fp)) {
memset(crecord, '', sizeof(crecord));
memset(skey, '', sizeof(skey));
if ( fgets(crecord, 100, fp) == NULL ) {
perror("read protocol error:");
fclose(fp);
return -1;
}
ridtail(crecord);
rridtabspc(crecord);
/*search field*/
if (ifind == FAIL) {
/*check for field*/
if ( (crecord[0] != '[')||(crecord[strlen(crecord)-1] != ']') )
continue;
else {
memset(cfld, 0, sizeof(cfld));
memcpy(cfld,crecord+1,((sizeof(cfld)sin_family = AF_INET;
if(inet_addr(host_ip_addr) != -1)
{
host->sin_addr.s_addr = inet_addr(host_ip_addr);
}
else
{
if((server_hostent = gethostbyname(host_ip_addr)) != 0)
{
memcpy(&host->sin_addr, server_hostent->h_addr,
sizeof(host->sin_addr));
}
else return 253;
}
host->sin_port = htons(port);
return 1;
}
int rand_local_port()
{
int local_port;
srand((unsigned)time(NULL));
local_port = rand() % 40000 + 1025;
return local_port;
}
void cmd_err_exit(char * err_msg, int err_code)
{
printinfo(ELOG, "%sn", err_msg);
exit(err_code);
}
//get the server's reply message from sock_fd
int ftp_get_reply(int sock_fd)
{
static int reply_code = 0,count=0;
char rcv_buf[512];
count=read(sock_fd, rcv_buf, 510);
if(count > 0)
reply_code = atoi(rcv_buf);
else
return 0;
/***while(1)
{
if(count
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ELOG __FILE__,__LINE__
#define FAIL 0
#define SUCCESS 1
#define FTPFIELD "FTPCONFIG"
#define HOSTADDR "HOST"
#define FTPPORT "PORT"
#define USERNAME "USERNAME"
#define PASSWORD "PASSWORD"
#define LOCALPATH "LOCALPATH"
#define REMOTEPATH "REMOTEPATH"
extern int h_errno;
char user[64]; //ftp usr
char passwd[64]; //ftp passwd
//ftp server address
struct sockaddr_in ftp_server, local_host;
struct hostent * server_hostent;
int sock_control;
int mode = 1; //ftp mode, 0 is PORT, 1 is PASV;
int printinfo(char * filename, int line, const char *format, ...)
{
va_list args;
va_start(args, format);
printf("%st%dt:", filename, line);
vprintf(format, args);
va_end(args);
return 0;
}
/*-------------------------------------------------------*/
/* ridtail -- get rid of a string's newline character */
/*-------------------------------------------------------*/
char *ridtail(char *c_buffer)
{
char *ctmp;
int ilength;
int len;
len = strlen(c_buffer);
ctmp = (char*)malloc(len);
if (ctmp == NULL) {
printf("f_ridtail::malloc fail!n");
return c_buffer;
}
memset(ctmp, 0, len);
if (*(c_buffer+len-1) == 0x0a) {
if (*(c_buffer+len-2) == 0x0d)
ilength = 2;
else
ilength = 1;
} else {
if (*(c_buffer+len-1) == 0x0d)
ilength = 1;
else
ilength = 0;
}
memcpy(ctmp, c_buffer, len-ilength);
memset(c_buffer, 0, len);
memcpy(c_buffer, ctmp, len-ilength);
free(ctmp);
return c_buffer;
}
/*-----------------------------------------------------------*/
/* rridtabspc -- get rid of the right tab of string*/
/*-----------------------------------------------------------*/
char * rridtabspc(char *as_string)
{
int li_i;
for( li_i = strlen(as_string) - 1 ; li_i >= 0; li_i -- ) {
if ((*(as_string + li_i) == ' ')||(*(as_string + li_i) == 0x09)) {
*(as_string + li_i) = '';
continue;
} else
break;
}
return as_string;
}
/*----------------------------------------*/
/* Read ini file to get private information */
/* 0 -- success, -1 -- failure */
/*----------------------------------------*/
int getprotocol(char *filename, char* cfldname, char* ckey, char* cvalue)
{
FILE *fp;
char crecord[1024];
char cfld[70];
char *p = NULL;
char *s = NULL;
char *e = NULL;
char skey[20];
char ctmp[500], ctmp2[500];
int ilen;
int ifind = FAIL;
rridtabspc(cfldname);
rridtabspc(ckey);
if ((fp = fopen(filename, "rb")) == NULL) {
perror("open file failed!n");
return -1;
}
while(!feof(fp)) {
memset(crecord, '', sizeof(crecord));
memset(skey, '', sizeof(skey));
if ( fgets(crecord, 100, fp) == NULL ) {
perror("read protocol error:");
fclose(fp);
return -1;
}
ridtail(crecord);
rridtabspc(crecord);
/*search field*/
if (ifind == FAIL) {
/*check for field*/
if ( (crecord[0] != '[')||(crecord[strlen(crecord)-1] != ']') )
continue;
else {
memset(cfld, 0, sizeof(cfld));
memcpy(cfld,crecord+1,((sizeof(cfld)sin_family = AF_INET;
if(inet_addr(host_ip_addr) != -1)
{
host->sin_addr.s_addr = inet_addr(host_ip_addr);
}
else
{
if((server_hostent = gethostbyname(host_ip_addr)) != 0)
{
memcpy(&host->sin_addr, server_hostent->h_addr,
sizeof(host->sin_addr));
}
else return 253;
}
host->sin_port = htons(port);
return 1;
}
int rand_local_port()
{
int local_port;
srand((unsigned)time(NULL));
local_port = rand() % 40000 + 1025;
return local_port;
}
void cmd_err_exit(char * err_msg, int err_code)
{
printinfo(ELOG, "%sn", err_msg);
exit(err_code);
}
//get the server's reply message from sock_fd
int ftp_get_reply(int sock_fd)
{
static int reply_code = 0,count=0;
char rcv_buf[512];
count=read(sock_fd, rcv_buf, 510);
if(count > 0)
reply_code = atoi(rcv_buf);
else
return 0;
/***while(1)
{
if(count