// KlassenMethodenKonsole.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
/////////////////////////////////////////////////////////
//Block zum Aufbauen der Verbindung
/////////////////////////////////////////////////////////
//Bibliotheken für FTP-Session
#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <stdio.h>
int warte;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL,
::GetCommandLine(), 0))
{
return -1;
}
//Objekt session wird erzeugt
CInternetSession session(_T("My FTP Session",1, INTERNET_OPEN_TYPE_DIRECT));
//Zeiger auf CFtpConnection
CFtpConnection *connection;
//Deklarationen für GetFtpConnection Member-Funktion
char servername[100]="beispielserver";
LPCTSTR pstrServer;
pstrServer = (LPCTSTR)servername;
LPCTSTR login = (LPCTSTR)"user";
LPCTSTR passwd = (LPCTSTR)"password";
INTERNET_PORT port = 21;
BOOL bPassive = FALSE;
cout << "Verbinde mit " << servername << " ...\n";
try
{
//FTP-Verbindung wird eröffnet,Methode GetFtpConnection wird auf session angewandt, connection wird auf zurückgegeben Zeiger gesetzt
if(connection = session.GetFtpConnection(pstrServer, login, passwd, port, bPassive))
{
cout << "Verbindung wurde aufgebaut";
}
}
catch (CInternetException* pEx)
{
cout<<"FEHLER : "<<GetLastError()<<endl;
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf_s("ERROR! %S\n", sz);
pEx->Delete();
}
cin >> warte;
return 0;
}