int main() { ftp_init(); struct ftp_connect client; memcpy(client.hostname, "192.168.0.107", sizeof(client.hostname)); client.control_port = 21; memcpy(client.username, "odin", sizeof(client.username)); memcpy(client.password, "odin", sizeof(client.password)); client.mode = 0; struct file_description file; memcpy(file.remote_dir, "/test/X00/192.168.0.188/20121128/09", sizeof(file.remote_dir)); memcpy(file.file_name, "a.txt", sizeof(file.file_name)); int size = 1024 * 1024; char *ptr = (char *)malloc(size * sizeof(char)); file.file_buffer = ptr; file.file_size = size; if (ftp_open(&client) == FTP_OK) { ftp_upload(&client, &file); } ftp_close(&client); free(ptr); ptr = NULL; ftp_release(); return 0; }
int SentToFTP(char *strFileName) { int ret = -1, len=0; char filename[64] = {0}; if(NULL == strFileName) { return -1; } if(g_changDate == 1) { len = databaseOperate(SDK_MAIN_MSG_FTP, SDK_PARAM_GET, NULL, 0, &g_ftp_cfg, sizeof(sdk_ftp_config)); if(len != sizeof(sdk_ftp_config)) { return -1; } g_changDate = 0; } if(0==g_ftp_cfg.bFtpEnable) { return 0; } if(AnalysisSendFile(strFileName, filename) == -1) { return -1; } //FTP·¢ËÍ ret = ftp_upload(g_ftp_cfg.servier_ip,g_ftp_cfg.port,g_ftp_cfg.foldername,\ g_ftp_cfg.username,g_ftp_cfg.password,strFileName, filename); if(ret == 0) { Printf("=======ftp upload successful=======\n\n"); } else { Printf("=======ftp upload fail %d=======\n\n", ret); } return ret; }
/* Amongst all the fluff, this is the bit that does the actual work. */ static void do_shot(void *data) { char *sys; char qual_buf[5]; char *filename_buf; char frame_buf[10]; char beep_buf[20]; char import_buf[50]; char *script_buf = NULL; char *view_buf = NULL; char *filename = NULL; Esnprintf(qual_buf, sizeof(qual_buf), "%d", opt.quality); filename = _Strjoin(NULL, opt.dir, opt.file_prefix, opt.file_stamp, ".", opt.file_type, NULL); filename_buf = _Strjoin(NULL, "SCRTEMP=\"", filename, "\"", NULL); if (!strcmp(opt.grabber, "import")) { if ((opt.frame) && (opt.win)) Esnprintf(frame_buf, sizeof(frame_buf), "-frame"); else frame_buf[0] = '\0'; if (opt.beep) beep_buf[0] = '\0'; else Esnprintf(beep_buf, sizeof(beep_buf), "-silent"); if (opt.win) Esnprintf(import_buf, sizeof(import_buf), "import"); else Esnprintf(import_buf, sizeof(import_buf), "import -window root"); if (opt.run_script) script_buf = _Strjoin(" ", "&&", opt.script, "$SCRTEMP", NULL); else script_buf = _Strdup(" "); if (opt.view_shot) view_buf = _Strjoin(" ", "&&", opt.viewer, "$SCRTEMP", NULL); else view_buf = _Strdup(" "); sys = _Strjoin(" ", opt.do_ftp ? "" : "(", filename_buf, "&&", import_buf, beep_buf, frame_buf, "-quality", qual_buf, "$SCRTEMP", script_buf, view_buf, opt.do_ftp ? "" : ")&", NULL); } else if (!strcmp(opt.grabber, "scrot")) { char delay_buf[20]; if (opt.delay > 0) Esnprintf(delay_buf, sizeof(delay_buf), "-d %.0f", opt.delay); else delay_buf[0] = '\0'; if ((opt.frame) && (opt.win)) Esnprintf(frame_buf, sizeof(frame_buf), "-b"); else frame_buf[0] = '\0'; if (opt.win) Esnprintf(import_buf, sizeof(import_buf), "scrot -s"); else Esnprintf(import_buf, sizeof(import_buf), "scrot"); if (opt.run_script) script_buf = _Strjoin(" ", "&&", opt.script, "$SCRTEMP", NULL); else script_buf = _Strdup(" "); if (opt.view_shot) view_buf = _Strjoin(" ", "&&", opt.viewer, "$SCRTEMP", NULL); else view_buf = _Strdup(" "); sys = _Strjoin(" ", opt.do_ftp ? "" : "(", filename_buf, "&&", import_buf, delay_buf, frame_buf, "--quality", qual_buf, "$SCRTEMP", script_buf, view_buf, opt.do_ftp ? "" : ")&", NULL); } else { printf("don't know how to handle grabber %s\n", opt.grabber); return; } system(sys); if (opt.do_ftp) { if (!ftp_connected) ftp_connect(opt.ftp_host, opt.ftp_user, opt.ftp_pass, opt.ftp_dir); ftp_upload(filename, opt.ftp_file, opt.ftp_temp); } free(sys); free(script_buf); free(view_buf); free(filename_buf); free(filename); return; data = NULL; }