// Common, groups Files and Communication
// Copyright Alexander Liss
#ifndef __FTP_H__
#define __FTP_H__
#include "win0.h"
#include <wininet.h>
#include <tchar.h>
#include "strbuf.h"
struct FtpIntercept
{
virtual int respond(
DWORD dwStatus,
LPVOID lpvStatusInfo,
DWORD dwStatusInfoLength)=0;
};
class FtpSession
{
FtpSession(const FtpSession&);
FtpSession& operator=(const FtpSession&);
public:
FtpSession();
~FtpSession();
bool objok(){return status==0;}
BOOL set_login(
HINTERNET internet_handle, // FROM internet_open()
LPCTSTR server, // CAN BE IP ADDRESS
LPCTSTR user = _T("anonymous"),
LPCTSTR password = _T("")
);
BOOL start();
void stop();
BOOL create_directory(const char *name);
BOOL set_current_directory(const char *name);
BOOL get_current_directory(StrBuffer& name);
int set(FtpIntercept& z);
int stop_intercept();
BOOL put(LPCTSTR lpsLocalFile,
LPCTSTR lpsNewRemoteFile,
DWORD dwFlags = FTP_TRANSFER_TYPE_BINARY
);
BOOL remove(LPCTSTR lpsRemoteFile);
private:
int status;
HINTERNET internet,session;
StrBuffer server,user,password;
FtpIntercept *intercept;
static VOID CALLBACK callback(
HINTERNET h,
DWORD dwContext,
DWORD dwInternetStatus,
LPVOID lpvStatusInformation,
DWORD dwStatusInformationLength
);
};
HINTERNET internet_open(
LPCTSTR lpsFtpSweepAgent = _T(""),
DWORD dwAccessType = INTERNET_OPEN_TYPE_DIRECT ,
LPCTSTR lpsFtpSweepProxyName = 0,
LPCTSTR lpsFtpSweepProxyBypass = 0,
DWORD dwFlags = 0
);
void internet_close_handle(HINTERNET handle);
struct FunctionInternet
{
HINTERNET handle;
FunctionInternet(){handle=internet_open();}
~FunctionInternet(){internet_close_handle(handle);}
};
#endif