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

📄 ftpput.cpp

📁 在VC++6.0的开发平台上
💻 CPP
字号:
// FtpPut.cpp: implementation of the CFtpPut class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FTP.h"
#include "FtpPut.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFtpPut::CFtpPut()
{
// get the name of the app
	strAppName.LoadString(AFX_IDS_APP_TITLE);

	// create an internet session
	pInternetSession = new CInternetSession(strAppName,
		INTERNET_OPEN_TYPE_PRECONFIG);

	// if Not good, show message + return
	// should never failed anyway
	if(!pInternetSession)
	{
		AfxMessageBox("Can't start internet session");
		return;
	}
}

CFtpPut::~CFtpPut()
{
// close the internet session
	pInternetSession->Close();
	// delete the session
	if(pInternetSession != NULL)
		delete pInternetSession;
}


// function, in logical order

bool CFtpPut::SetAccessRight(CString userName,
							 CString userPass)
{
	// simply get username and password
	strPass = userPass;
	strUser = userName;
	if( (strPass == "") || (strUser == ""))
		return 0;

	return 1;
}

bool CFtpPut::OpenConnection(CString server)
{
	if(server == "")
		return 0;

	// put the server name in the CFtpGet class
	strServerName = server;

	try {
		// try to connect to a ftp server
		pFtpConnection = pInternetSession->GetFtpConnection(strServerName,
			strUser,
			strPass);
	} catch (CInternetException* pEx) 
	{
		// if failed, just show the error

		// Oops! We failed to connect!
		TCHAR szErr[1024];
		pEx->GetErrorMessage(szErr, 1024);
		TRACE(szErr);
		AfxMessageBox(szErr);
		pEx->Delete();
		return 0;// return 1 but previous  box have been showed
	}
           return 1;

}	

bool CFtpPut::PutFile(CString remoteFile,
					  CString localFile)
{
	// Try to put the file
	BOOL bPutFile = pFtpConnection->PutFile(remoteFile,
		localFile);

	return bPutFile ? 1 : 0 ;
	// if bPutFile is 0 ( FALSE ), return 0
	// if bPutFile is 1 ( TRUE  ), return 1
}


bool CFtpPut::CloseConnection()
{
	// close the connection to server, you can reconnect latter
	if(pFtpConnection == NULL)
		return 0;
	try{
		pFtpConnection->Close();
	}catch(...)
	{
		return 0;
	}
	if(pFtpConnection != NULL)
		delete pFtpConnection;

	return 1;
}

⌨️ 快捷键说明

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