利用ftp功能通过脚本的形式进行批量处理,代码示范如下:
1、Windows环境
// ftp命令形式实现
string commandFilePath = strShScriptFile + ".tmp";
FILE *file = fopen(commandFilePath.c_str(), "w");
if (file)
{
fprintf(file, "open %s %s\n"
"USER %s\n"
"%s\n"
"cd %s\n"
"binary\n"
"prompt n\n"
"mput %s\n"
"quit\n"
,FTPServer, FTPPort, FTPUsername, FTPPassword, uploadDirectory, "*.txt");
fclose(file);
// FTP*的参数名表示远程FTP主机的相关参数;
// 其中uploadDirectory表示目的目录;
// "*.txt"表示批量上传本地txt文件,当然可以指定具体目录上传指定文件
ShScript = strShScriptFile + ".bat";
file = fopen(ShScript.c_str(), "w");
if (file)
{
fprintf(file, "ftp.exe -n -s:%s\n"
"del %s\n"
, commandFilePath.c_str()
,"*.txt");
fclose(file);
// 调