반응형

[퍼옴] : http://xtelite.blogspot.kr/2007/04/mfc-ftp.html


CInternetSession m_Session;
CFtpConnection *m_pConnection;
CFtpFileFind *m_pFileFind;


생성자 함수에서 포인터 초기화

m_pFileFind = NULL;
m_pConnection = NULL;


Stdafx.h 제일 아래에 다음 추가(direct.h는 디렉토리 관련 함수 호출을 위한 것임.)

#include "afxsock.h"
#include "afxinet.h"
#include "direct.h"


InitInstance 함수에서 AfxSocketInit() 호출

CWinApp::InitInstance();
  if (!AfxSocketInit()) {
  AfxMessageBox(_T("소켓 초기화 실패"));
  return FALSE;
}
...


이제 연결을 합니다.

BeginWaitCursor();

// 이미 연결된 것이 있으면 해제
if (m_pConnection != NULL) {
  m_pConnection->Close();
  delete m_pConnection;
  m_pConnection = NULL;
}
... 


// 연결하고자 하는 FPT 서버의 IP 주소와 사용자명, 암호 입력
m_pConnection = m_Session.GetFtpConnection(sIpAddress, sUsername, sPassword);

// 연결이 안됐을 경우
if (!m_pConnection) {
  AfxMessageBox(_T("Error"));
  m_pConnection = NULL;
  return;
}

// 현재 디렉토리를 얻음
m_pConnection->GetCurrentDirectory(sRomoteDir);

// 이미 사용하고 있으면 해제
if (m_pFileFind) delete m_pFileFind;

// FTP 서버의 파일명을 읽어 옴
m_pFileFind = new CFtpFileFind(m_pConnection);

...

EndWaitCursor();


m_pFileFind는 다음과 같이 사용함.
먼저 디렉토리를 넘겨 주고 FileFind 한 번 호출, 그런 다음 FindNextFile 함수가 FALSE를 넘겨 줄 때까지 GetFileName 함수를 반복해서 호출한다.

m_pFileFind->FindFile(sRemoteDir);
...
while (bContinue) {
  bContinue = m_pFileFind->FindNextFile();
  sFileName = m_pFileFind->GetFileName();
...
}

m_pFileFind->IsDirectory()를 호출하면 디렉토리인지 폴더인지 확인 가능하다.

기타

m_pConnection->SetCurrentDirectory(sRemoteDir);
m_pConnection->GetCurrentDirectory(sRemoteDir);


등이 사용된다.
파일의 업로드/다운로드는

m_pConnection->PutFile(sLocalFile, sRemotePath);
m_pConnection->GetFile(sPath, sRemotePath)

반응형

'MFC > FTP' 카테고리의 다른 글

FTP) FTP란?  (0) 2016.12.19
MFC) FTP 필수 클래스 - CFtpFileFind  (2) 2016.10.24
MFC) FTP 필수 클래스 - CFtpConnection  (0) 2016.10.24
MFC) FTP 필수 클래스 - CInternetSession  (0) 2016.10.24
Posted by tislqhf

블로그 이미지
개인적인 공부자료 정리하는 공간
tislqhf

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.3
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함