⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftphelper.cpp

📁 一套完整的ftp应用程序API接口
💻 CPP
字号:

#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -