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

📄 ftpexampleengine.cpp

📁 Symbian智能手机操作系统源代码值的参考_网络ftp
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CFtpExampleEngine from FtpExampleEngine.cpp
*  Part of  : FtpExample
*  Created  : 03/11/2005 by Forum Nokia
*  Version  : 1.0
*  Copyright: Nokia Corporation
* ============================================================================
*/

// INCLUDE FILES
#include <in_sock.h> //TInetAddr
#include "FtpExampleEngine.h"

// ================= MEMBER FUNCTIONS =======================

// destructor
CFtpExampleEngine::~CFtpExampleEngine()
	{
	delete iFtpSession;
	}
	
// ----------------------------------------------------------
// CFtpExampleEngine::NewL()
// Two-phased constructor.
// ----------------------------------------------------------
//
CFtpExampleEngine* CFtpExampleEngine::NewL(MFtpSessionNotifier* aNotifier)
	{
	CFtpExampleEngine* self = new (ELeave) CFtpExampleEngine;
	CleanupStack::PushL(self);
	self->ConstructL(aNotifier);
	CleanupStack::Pop(self);
	return self;
	}
	
// ----------------------------------------------------------
// CFtpExampleEngine::ConstructL()
// Symbian OS default constructor can leave.
// ----------------------------------------------------------
//	
void CFtpExampleEngine::ConstructL(MFtpSessionNotifier* aNotifier)
	{
	iFtpSession = CFTPSession::NewL(aNotifier);
	}

// ----------------------------------------------------------
// CFtpExampleEngine::ConnectL()
// Creates a connection to an FTP server.
// ----------------------------------------------------------
//	
void CFtpExampleEngine::ConnectL(	const TDesC& aHostName,
									const TDesC& aUserName,
									const TDesC& aPassword,
									const CFTPSession::TConnectionMode& aConnectionMode)
	{
	HBufC8* userName = HBufC8::NewLC(aUserName.Length());
	TPtr8 un(userName->Des());
	un.Copy(aUserName);

	HBufC8* password = HBufC8::NewLC(aPassword.Length());
	TPtr8 pw(password->Des());
	pw.Copy(aPassword);

	TInetAddr serverAddress;
	if(serverAddress.Input(aHostName) == KErrNone)
		{
		serverAddress.SetPort(KDefaultServerPiPort);
		iFtpSession->Connect(serverAddress,un,pw, aConnectionMode);
		}
	else 
		{
		iFtpSession->Connect(aHostName,un,pw, aConnectionMode);
		}
	
	CleanupStack::PopAndDestroy(password);
	CleanupStack::PopAndDestroy(userName);
	}
	
// ----------------------------------------------------------
// CFtpExampleEngine::Disconnect()
// Disconnects from the FTP server.
// ----------------------------------------------------------
//
void CFtpExampleEngine::Disconnect()
	{
	iFtpSession->Close();
	}

// ----------------------------------------------------------
// CFtpExampleEngine::ListDirectoryL()
// Lists the files in a directory on the remote file system.
// Implements the dir command in FTP.
// ----------------------------------------------------------
//
void CFtpExampleEngine::ListDirectoryL(const TDesC& aDir, TDes8& aFileList)
	{
	HBufC8* dir = HBufC8::NewLC(aDir.Length());
	TPtr8 d(dir->Des());
	d.Copy(aDir);
	
	iFtpSession->ListDirectory(d, aFileList);
	
	CleanupStack::PopAndDestroy(dir);
	}

// ----------------------------------------------------------
// CFtpExampleEngine::ChangeDirectoryL()
// Sets the current directory on the remote file system.
// Implements the cd command in FTP.
// ----------------------------------------------------------
//	
void CFtpExampleEngine::ChangeDirectoryL(const TDesC& aDir)
	{
	HBufC8* dir = HBufC8::NewLC(aDir.Length());
	TPtr8 d(dir->Des());
	d.Copy(aDir);
	iFtpSession->ChangeDirectory(d);
	CleanupStack::PopAndDestroy(dir);
	}

// ----------------------------------------------------------
// CFtpExampleEngine::CurrentDirectory()
// Gets the client's current directory on the remote file 
// system. Implements the pwd command in FTP.
// ----------------------------------------------------------
//	
void CFtpExampleEngine::CurrentDirectory()
	{
	iFtpSession->GetCurrentDirectory();
	}

// ----------------------------------------------------------
// CFtpExampleEngine::RetrieveL()
// Transfers a file from the FTP server.
// Implements the get command in FTP.
// ----------------------------------------------------------
//
void CFtpExampleEngine::RetrieveL(	const TDesC& aRemoteFileName,
									const TDesC& aLocalFileName,
									const TBool& aBinary)
	{
	HBufC8* remoteFile = HBufC8::NewLC(aRemoteFileName.Length());
	TPtr8 rf(remoteFile->Des());
	rf.Copy(aRemoteFileName);
	if (aBinary)
		{
		iFtpSession->Retrieve(rf, aLocalFileName);
		}
	else
		{
		iFtpSession->Retrieve(rf, aLocalFileName, CFTPSession::EOverwrite, CFTPSession::EASCII);
		}
	CleanupStack::PopAndDestroy(remoteFile);
	}
	
// ----------------------------------------------------------
// CFtpExampleEngine::StoreL()
// Transfers a file to the FTP server.
// Implements the put command in FTP.
// ----------------------------------------------------------
//
void CFtpExampleEngine::StoreL(	const TDesC& aLocalFileName,
								const TDesC& aRemoteFileName,
								const TBool& aBinary)
	{
	HBufC8* remoteFile = HBufC8::NewLC(aRemoteFileName.Length());
	TPtr8 rf(remoteFile->Des());
	rf.Copy(aRemoteFileName);
	if (aBinary)
		{
		iFtpSession->Store(aLocalFileName, rf);
		}
	else
		{
		iFtpSession->Store(aLocalFileName, rf, CFTPSession::EOverwrite, CFTPSession::EASCII);
		}
	CleanupStack::PopAndDestroy(remoteFile);
	}			

// ----------------------------------------------------------
// CFtpExampleEngine::CreateDirectoryL()
// Creates a directory on the remote file system.
// Implements the mkdir command in FTP.
// ----------------------------------------------------------
//	
void CFtpExampleEngine::CreateDirectoryL(const TDesC& aDirectoryName)
	{
	HBufC8* dirName = HBufC8::NewLC(aDirectoryName.Length());
	TPtr8 dn(dirName->Des());
	dn.Copy(aDirectoryName);
	iFtpSession->CreateDirectory(dn);
	CleanupStack::PopAndDestroy(dirName);
	}	

// ----------------------------------------------------------
// CFtpExampleEngine::DeleteDirectoryL()
// Deletes a directory on the remote file system.
// Implements the rmdir command in FTP.
// ----------------------------------------------------------
//
void CFtpExampleEngine::DeleteDirectoryL(const TDesC& aDirectoryName)
	{
	HBufC8* dirName = HBufC8::NewLC(aDirectoryName.Length());
	TPtr8 dn(dirName->Des());
	dn.Copy(aDirectoryName);
	iFtpSession->DeleteDirectory(dn);
	CleanupStack::PopAndDestroy(dirName);
	}	

// ----------------------------------------------------------
// CFtpExampleEngine::RenameFileL()
// Renames a file on the remote file system.
// Implements the rename command in FTP.
// ----------------------------------------------------------
//
void CFtpExampleEngine::RenameFileL(const TDesC& aRemoteFileName, const TDesC& aNewRemoteFileName)
	{
	HBufC8* fileName = HBufC8::NewLC(aRemoteFileName.Length());
	TPtr8 fn(fileName->Des());
	fn.Copy(aRemoteFileName);
	
	HBufC8* newFileName = HBufC8::NewLC(aNewRemoteFileName.Length());
	TPtr8 nfn(newFileName->Des());
	nfn.Copy(aNewRemoteFileName);
	
	iFtpSession->RenameFile(fn, nfn);
	
	CleanupStack::PopAndDestroy(newFileName);
	CleanupStack::PopAndDestroy(fileName);
	}

// ----------------------------------------------------------
// CFtpExampleEngine::DeleteFileL()
// Deletes a file on the remote file system.
// Implements the delete command in FTP.
// ----------------------------------------------------------
//	
void CFtpExampleEngine::DeleteFileL(const TDesC& aFileName)
	{
	HBufC8* fileName = HBufC8::NewLC(aFileName.Length());
	TPtr8 fn(fileName->Des());
	fn.Copy(aFileName);
	iFtpSession->DeleteFile(fn);
	CleanupStack::PopAndDestroy(fileName);
	}		

// ----------------------------------------------------------
// CFtpExampleEngine::Cancel()
// Cancels the currently ongoing operation.
// ----------------------------------------------------------
//	
void CFtpExampleEngine::Cancel()
	{
	iFtpSession->Cancel();
	}
	
// End of File

⌨️ 快捷键说明

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