
#include <stdio.h>
#include <stdlib.h>
#include "../misc/ftp.h" 
#include <iostream> 
using namespace std; 

#include "db_interface.h"

static int demo() 
{ 
	//µÇÂ¼ 
	CFTP ftpclient; 
	int err; 
	err = ftpclient.ftp_connect("192.168.1.103"); 
	//err = ftpclient.ftp_connect("103.1.168.192"); 
	if(err){ 
		puts("connect ftp server failed"); 
		exit(-1); 
	} 
	puts("connect ok"); 
	err = ftpclient.ftp_login("root","9.9cyj"); 
	if(err){ 
		puts("login failed"); 
		exit(-1); 
	} 
	puts("login ok"); 
	err = ftpclient.ftp_download("loc_download.txt","/etc/jcf_vesion.txt"); 
	if(err){ 
		puts("download failed"); 
		exit(-1); 
	} 
	puts("download ok"); 
	err = ftpclient.ftp_upload("../comtrade/mms2db_template.csv","/22/njcn/","mms2db_template.csv"); 
	if(err){ 
		puts("upload failed"); 
		exit(-1); 
	}   
	remove("");
	puts("upload ok"); 
	err = ftpclient.ftp_quit(); 
	if(err){ 
		puts("quit failed"); 
		exit(-1); 
	} 
	puts("you quit"); 
	return 0; 
} 

int my_ftp_upload(char* ip,char* user,char* pwd, char* localfile,char* remotepath,char* remotefilename) 
{ 
	//µÇÂ¼ 
	CFTP ftpclient; 
	int err; 

	err = ftpclient.ftp_connect(ip); 
	if(err){ 
		puts("connect ftp server failed"); 
		return(-1); 
	} 
	puts("ftp connect ok"); 
	
	//err = ftpclient.ftp_login("njcn","Pq54321");  
	err = ftpclient.ftp_login(user,pwd); 
	if(err){ 
		puts("ftp login failed"); 
		return(-1); 
	} 
	puts("ftp login ok"); 

	err = ftpclient.ftp_upload(localfile,remotepath,remotefilename); 
	if(err){ 
		puts("ftp upload failed"); 
		return(-1); 
	}   
	puts("ftp upload ok"); 

	remove(localfile);

	err = ftpclient.ftp_quit(); 
	if(err){ 
		puts("ftp quit failed"); 
		return(-1); 
	} 
	puts("ftp quit"); 
	return 0; 
} 

 

