ftphelper.cpp

来自「一套完整的ftp应用程序API接口」· C++ 代码 · 共 76 行

CPP
76
字号

#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>

#include <sys/time.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>

#include "ftplib.h"
#include "common.h"
#include "ftpHelper.h"

UINT32 FtpLogIn(FTPINFO* ftpinfo,char *host,char* name,char* password)
{
	ftpinfo->debug=ON;
	// the remote FTP server serves on a non-standard port
	ftp_setport(0);
       // connect to peer at remote host (on the non-standard port)
	DebugPrint(g_DbgLevel,g_fpLogFile,"\n---------ftpLogIn..----------\n");
	if (ftp_prconnect ( ftpinfo,host ) < 0)
	{
		DebugPrint(g_DbgLevel,g_fpLogFile,"error: ftp_prconnect failed.\n");
		return check_n_close (ftpinfo, ABNORMAL );
	}
	// use ftp_login to login into the remote FTP server
	if (ftp_login ( ftpinfo, host, name,password, NULL ) < 0)
	{
		DebugPrint(g_DbgLevel,g_fpLogFile,"error: ftp_login failed.\n");
		return check_n_close (ftpinfo, ABNORMAL );
	}
	//set transfer mode to BINARY mode
	if (ftp_settype ( ftpinfo, BINARY) < 0)
	{
		DebugPrint(g_DbgLevel,g_fpLogFile,"error: ftp_settype failed in ascii mode.\n");
		return check_n_close (ftpinfo, ABNORMAL );
	}
	return 0;
}

UINT32 FtpGetFile(FTPINFO* ftpinfo,char *host,char* remotefile,char* localfile)
{
	
	// do a 'get' from the remote host
	if (ftp_getfile ( ftpinfo, remotefile,localfile)< 0)
	{
		DebugPrint(g_DbgLevel,g_fpLogFile,"error: ftp_getfile failed.\n");
		return check_n_close ( ftpinfo, ABNORMAL );
	}
	//quit the FTP session decently
	else
	{
		DebugPrint(g_DbgLevel,g_fpLogFile,"ftp transfer success,filename is %s\n\n",remotefile);
		return 0;
	}
}
UINT32 FtpLogOut(FTPINFO* ftpinfo)
{
	if (ftp_bye(ftpinfo ) < 0) 
	{
		DebugPrint(g_DbgLevel,g_fpLogFile,"error: ftp_bye failed.\n");
		return check_n_close (ftpinfo, ABNORMAL );
  }
  else
  {
		DebugPrint(g_DbgLevel,g_fpLogFile,"\n---------ftpLogOut..----------\n");
		return 0;
	}
}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?