检查文件是否存在,将结果通过ftp上传
2011-04-08 14:56
381 查看
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <time.h> #define UP_FTP_NAME "up_ftp.txt" #define COUNT 2 int n=0; void handle_file(char *file) { char c; int ret; FILE *s_fp1,*d_fp2; char hostname[128]; char writefile[128]; char nowtime[128]; struct tm *p1; time_t timep; timep=time(NULL); p1=localtime(&timep); // cygwin env char cygwin[128]; sprintf(cygwin,"set CYGWIN=nodosfilewarning"); system(cygwin); gethostname(hostname,sizeof(hostname)); // printf("%s/n",hostname); sprintf(nowtime,"%d-%02d-%02d-%02d-%02d/n",1900+p1->tm_year,(1+p1->tm_mon),p1->tm_mday,p1->tm_hour,p1->tm_min,p1->tm_sec); sprintf(writefile,"%s_%d-%02d-%02d-%02d-%02d.txt",hostname,1900+p1->tm_year,(1+p1->tm_mon),p1->tm_mday,p1->tm_hour,p1->tm_min,p1->tm_sec); // printf("%s/n",writefile); d_fp2=fopen(writefile,"a+"); if(d_fp2==NULL) { fprintf(stderr,"fopen %s error./n",writefile); exit(-1); } if(n++==0) { fprintf(d_fp2,"%s/n",nowtime); fprintf(d_fp2,"%s/n/n",hostname); } s_fp1=fopen(file,"r"); if(s_fp1==NULL) { fprintf(stderr,"warning!! %s not exist./n",file); fprintf(d_fp2,"warning!! %s not exist./n",file); } else { fprintf(stderr,"ok!! %s exitst./n",file); fprintf(d_fp2,"ok!! %s exitst./n",file); ret=fseek(s_fp1,0,SEEK_SET); if(ret==-1) { fprintf(stderr,"fseek error./n"); } if(fscanf(s_fp1,"%c",&c)==EOF) { fprintf(stderr,"warning!! %s size is 0./n",file); fprintf(d_fp2,"warning!! %s size is 0./nn",file); } else { fprintf(stderr,"ok!! %s size is not 0./n",file); fprintf(d_fp2,"ok!! %s size is not 0./n",file); } } ret=fclose(s_fp1); if(ret==EOF) { fprintf(stderr,"fclose %s error./n",file); exit(-1); } ret=fclose(d_fp2); if(ret==EOF) { fprintf(stderr,"fclose %s error./n",file); exit(-1); } } ftp_up_cmd() { //----------ftp define---------------------- FILE *ftp_fp; int i=0,ret; char *up_ftp_parm[9]={"open 127.0.0.1","xunjian","123456","cd shipinshangchuan","bin","put GATEWAY1*","!rm GATEWAY1*","close","bye"}; char ftp_cmd[128]; //------------------------------------------ //---------------------------------------------------------------------- ftp_fp=fopen(UP_FTP_NAME,"a"); if(ftp_fp==NULL) { fprintf(stderr,"fopen %s error./n",UP_FTP_NAME); exit(-1); } for(i=0;i<9;i++) { ret=fprintf(ftp_fp,"%s/n",up_ftp_parm[i]); if(ret<0) { fprintf(stderr,"fprintf error./n"); exit(-1); } } ret=fclose(ftp_fp); if(ret==EOF) { fprintf(stderr,"fclose %s error./n",UP_FTP_NAME); exit(-1); } ret=sprintf(ftp_cmd,"ftp -s:%s",UP_FTP_NAME); if(ret<0) { fprintf(stderr,"sprintf ftp_cmd error./n"); exit(-1); } // popen(ftp_cmd); // for system system(ftp_cmd); unlink(UP_FTP_NAME); //---------------------------------------------------------------------- } int main(void) { int i; struct tm *p1; time_t timep; char openfile1[128]; char openfile2[128]; char *openfile[COUNT]; timep=time(NULL); p1=localtime(&timep); /* sprintf(openfile[0],"d://oracle_exp_bak//bwdasic-%d-%02d-%02d.dmp",1900+p1->tm_year,(1+p1->tm_mon),p1->tm_mday); sprintf(openfile[1],"e://orabak//bwdasic-%d-%02d-%02d.dmp",1900+p1->tm_year,(1+p1->tm_mon),p1->tm_mday); */ sprintf(openfile1,"d://oracle_exp_bak//bwdasic-%d-%02d-%02d.dmp",1900+p1->tm_year,(1+p1->tm_mon),p1->tm_mday); sprintf(openfile2,"e://orabak//bwdasic-%d-%02d-%02d.dmp",1900+p1->tm_year,(1+p1->tm_mon),p1->tm_mday); // printf("%s/n",openfile1); // handle_file(openfile); // handle file cmd handle_file(openfile1); handle_file(openfile2); // execute ftp up cmd ftp_up_cmd(); unlink(UP_FTP_NAME); exit(0); }
相关文章推荐
- 动软中,在连接服务器时,出现“添加服务器配置失败,请检查是否有写入权限或文件是否存在“错误
- 检查某个文件或目录是否存在的函数
- MFC 创建目录、检查目录和文件是否存在
- 动软中,在连接服务器时,出现“添加服务器配置失败,请检查是否有写入权限或文件是否存在“错误
- php中检查文件或目录是否存在的代码小结
- 手动通过Lucene判断该pom文件中jar是否存在,子依赖没判断
- 自动化测试:k8s环境下,通过检测文件是否存在来自动启停tomcatapp的方法_20160316_七侠镇莫尛貝
- 通过文件锁实现,程序开始运行时,先判断文件是否存在,若存在则表明该程序已经在运行了,如果不存在就用open函数创建该文件,程序退出时关闭文件并删除文件
- 设置窗体的起始位置,并检查配置文件是否存在,存在使用配置文件,不存在创建配置文件,在每次打开窗体时保持窗体上一次关闭的位置。
- 检查当前目录下是否存在指定的文件,如果存在就重新命名
- iOS 检查本地是否存在某个文件
- php检查上传文件是否已存在或同名
- php检查上传文件是否已存在或同名
- 自动化测试:k8s环境下,通过检测文件是否存在来自动启停tomcatapp的方法_20160316_七侠镇莫尛貝
- ios 文件操作 检查文件是否存在 创建文件目录 iphone
- MFC/C++检查文件是否存在
- 通过md5值检查文件信息是否相同
- c#检查网络文件是否存在
- 使用Bash Shell检查文件是否存在的方法