Please see the standalone blog page: http://1.oliverwang.sinaapp.com/?p=40
/*The MIT License (MIT) Copyright (c) <2014> <[email protected]>permission is hereby granted, free of charge Obtaining a copyof This software and associated documentation files (the "software") to Dealin the Softwa Re without restriction, including without limitation the Rightsto use, copy, modify, merge, publish, distribute, Sublicens E, and/or sellcopies of the software, and to permit persons to whom the software isfurnished to doing so, subject to the Foll Owing conditions:the above copyright notice and this permission notice shall be included inall copies or substantial Porti ONS of the Software.the software is provided ' as is ', without WARRANTY of any KIND, EXPRESS orimplied, including and not L Imited to the warranties of merchantability,fitness for A particular PURPOSE and noninfringement. In NO EVENT shall theauthors or COPYRIGHT holders is liable for any CLAIM, damages OR otherliability, WHETHER in an ACTION of contract, TORT OR OTHERWISE, arising From,ouT of OR in CONNECTION with the software or the same or other dealings inthe software. */#ifndef Ftpclient_h#defineFtpclient_h#include"curl/curl.h"#include<string>#include<iostream>#include<fstream>using namespacestd;/*represent a ftp file*/structFtpfile {stringFileName/*Name*/ stringPath/*Where to save*/FILE*stream;/*Stream*/};/*File Type*/typedefenum{bin_t=2,/*Firmware in *.bin*/hex_t=3,/*Firmware in *.hex*/yaml_t=4 /*Yaml configuration file*/} efiletype;typedefintfile_t;/*File Type*/classftpclient{ Public: FtpClient (); Virtual~ftpclient (); voidSetftpaddress (Const string&url);/*Set The FTP server address, must call before using*/ voidSetauthorityaccount (Const string&user,Const string&PWR);/*Set the FTP account*/ voidSetrelativepath (Const string&path_yaml,Const string&PATH_FW); BOOLFtpdownloadfile (Const string&filename, file_t type);/*Download a file from server*/ BOOLFtpuploadfile (Const string&filename);/*Upload A file to the server*/ Static BOOLIsvalidip (Char*ip,intLen); stringGetrelativepath (file_t type); /*For Test*/ voidUnittest_get (); voidUnittest_post (); voidUnittest_print (); Private: stringFtpurl;/*FTP Server Address*/ stringUserName;/*Ftp Server Account Username*/ stringPassWord;/*Ftp Server Account Password*/ stringRelativepathyaml;/*File Save Yaml*/ stringRELATIVEPATHFW;/*File Save Bin*/ Staticsize_t Yaml_fwrite (void*buf, size_t _size, size_t nmemb,void*stream);};#endif //Ftpclient_h
Libcurl and FTP to build small file transfer service