#include <stdio.h> #include <stdlib.h> int main() { FILE *fp; char ch; char pRetMsg[128]; int msg_len=0; memset(pRetMsg, 0, sizeof(pRetMsg)); if((fp=fopen("test.txt","r"))==NULL) { printf("Error! "); exit(0); } if(fgets(pRetMsg,sizeof(pRetMsg),fp)!=NULL) { printf("FTP cmd Fail...:%s",pRetMsg); //print all info if(strncmp("cannot connect to remote host",pRetMsg+8,strlen("cannot connect to remote host"))==0) { printf("FTP ServerIp Error. "); } else if(strncmp("unexpected server response to PASS",pRetMsg+8,strlen("unexpected server response to PASS"))==0) { printf("FTP User or passwd error. "); } else if(strncmp("write error: No space left on device",pRetMsg+8,strlen("write error: No space left on device"))==0) { printf(" No space left on device "); } else if(strncmp("unexpected server response to RETR",pRetMsg+8,strlen("unexpected server response to RETR"))==0) { printf("FTP Download path error "); } else if(strncmp("can't open",pRetMsg+8,strlen("can't open"))==0) { printf("FTP upload file not exit "); } else{ printf("Other ftp fail reason,see ftp.log"); } } else{ printf("Content of file is null,ftp cmd success!!! "); } fclose(fp); return 0; }
#include "stdio.h" #include <string.h> int main() { char userName[16]; char passwd[16]; char ftp_server_ip[16]; char srcPath[128]; char str[128]; sprintf(str,"%s","zhangling@192.168.240.50/FTP_Download/"); sscanf(str,"%[^@]",userName); sscanf(str,"%*[^@]@%[^/]",ftp_server_ip); //need test sscanf(str,"%*[^/]%s",srcPath); printf("userName=%s ",userName); printf("ftp_server_ip=%s ",ftp_server_ip); printf("srcPath=%s ",srcPath); return 0; }
#include "stdio.h" #include <string.h> /* just get lastest info */ int _System(const char * cmd, char *pRetMsg, int msg_len) { FILE *fp; char *p = NULL; int res = -1; if (cmd == NULL || pRetMsg == NULL || msg_len < 0) { printf("Param Error! "); return -1; } if ((fp = popen(cmd, "r") ) == NULL) { printf("Popen Error! "); return -2; } else { memset(pRetMsg, 0, msg_len); //get lastest result while(fgets(pRetMsg, msg_len, fp) != NULL) { printf("Msg@_@:%s",pRetMsg); //print all info } if ( (res = pclose(fp)) == -1) { printf("close popenerror! "); return -3; } pRetMsg[strlen(pRetMsg)-1] = '