ps:
1.使用netkit-ftp-0.17交叉编译出来的ftp客户端,
2.然后写上传代码,调用ftp传服务器;
3.最好使用bin二进制文件形式传输;
4.ftp客户端和Ubuntu自带的ftp工具其实是同一个,只是需要切换下编译器重新编译个arm平台的;
5.代码把关键的上传部分写好了,可以参考下;
#include "stdio.h"
#include <time.h>
#include <dirent.h>
#include "ctype.h"
#include <errno.h>
#include <unistd.h>
#include "log_struct.h"
#include <linux/rtc.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int logtar(char *tar_path,char *filename)
{
char mbackupcmd[LOG_LEN]={0};
char timeinfo[LOG_LEN]={0};
int pos=0;
//char dirname[256];//获取当前目录并打印
chdir(Log_Local_Root); //必须用这个切换路径,system不能用cd切换
//getcwd(dirname,256);
//printf("The current directory is : %s \n",dirname);
getcurrenttimeforfilename(timeinfo);
pos=0;
sprintf(filename,"dilog%s.tar",timeinfo);
sprintf(mbackupcmd+pos,"busybox tar -cf %s%s LOG zdi_log",tar_path,filename);
system(mbackupcmd);
return 0;
}
int logsaveremote(int argc, char *argv[])
{
FILE *fp;
int i,pos;
char filename[100],file_path[100];;
char rmcmd[LOG_LEN]={0};
logtar("/media/mtdblock3/",filename);
sprintf(file_path,"/media/mtdblock3/%s",filename);
if(access(file_path, F_OK) != 0)
{
printf("log autobackup tar err \n ");
return 2;
}
if((fp=popen("ftp -n","w"))==NULL)
{
printf("Run ftp fail !");
return 3;
}
//while ((fgets(str,255,fp))!=NULL) puts(str);
fprintf(fp,"open %s\n",argv[3]);
fprintf(fp,"user %s %s\n",argv[4],argv[5]);
fprintf(fp,"prompt\n");
fprintf(fp,"lcd /media/mtdblock3\n");
fprintf(fp,"cd /\n");
fprintf(fp,"binary /\n"); //二进制格式传输,否则打包的压缩包上传之后无法打开
fprintf(fp,"put *%s\n",filename);
fprintf(fp,"bye\n");
pclose(fp);
sprintf(rmcmd,"rm /media/mtdblock3/%s",filename);
system(rmcmd);
printf("%s backup to ftp server success \n",filename);
return 0;
}