Versie 3.10: FTP object toegevoegd
svn path=/Slnkdwf/trunk/; revision=20044
This commit is contained in:
200
SlnkDWFCom/FTP.cpp
Normal file
200
SlnkDWFCom/FTP.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
// FTP.cpp : Implementation of CFTP
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "FTP.h"
|
||||
|
||||
#pragma comment(lib, "wininet.lib")
|
||||
|
||||
#define FTPAGENT "FACILITOR"
|
||||
// CFTP
|
||||
|
||||
CFTP::~CFTP()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
STDMETHODIMP CFTP::InterfaceSupportsErrorInfo(REFIID riid)
|
||||
{
|
||||
static const IID* arr[] =
|
||||
{
|
||||
&IID_IFTP
|
||||
};
|
||||
|
||||
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
|
||||
{
|
||||
if (InlineIsEqualGUID(*arr[i],riid))
|
||||
return S_OK;
|
||||
}
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
STDMETHODIMP CFTP::get_Proxyname(BSTR* pVal)
|
||||
{
|
||||
*pVal = m_Proxyname.AllocSysString();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::put_Proxyname(BSTR newVal)
|
||||
{
|
||||
m_Proxyname = CString(newVal);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::get_Hostname(BSTR* pVal)
|
||||
{
|
||||
*pVal = m_Hostname.AllocSysString();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::put_Hostname(BSTR newVal)
|
||||
{
|
||||
m_Hostname = CString(newVal);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::get_Port(LONG* pVal)
|
||||
{
|
||||
*pVal = m_Port;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::put_Port(LONG newVal)
|
||||
{
|
||||
m_Port = (INTERNET_PORT)newVal;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::get_Username(BSTR* pVal)
|
||||
{
|
||||
*pVal = m_Username.AllocSysString();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::put_Username(BSTR newVal)
|
||||
{
|
||||
m_Username = CString(newVal);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::get_Password(BSTR* pVal)
|
||||
{
|
||||
*pVal = m_Password.AllocSysString();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::put_Password(BSTR newVal)
|
||||
{
|
||||
m_Password = CString(newVal);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::get_Flags(LONG* pVal)
|
||||
{
|
||||
*pVal = m_Flags;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHODIMP CFTP::put_Flags(LONG newVal)
|
||||
{
|
||||
m_Flags = newVal;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CString inetError(CString method, CString func)
|
||||
{
|
||||
DWORD errcode = GetLastError();
|
||||
CString err;
|
||||
|
||||
if (errcode != ERROR_INTERNET_EXTENDED_ERROR)
|
||||
{
|
||||
err.Format("%s\nCould not %s (%d): %s", method, func, errcode, myGetLastErrorMsg());
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD dwInetError;
|
||||
DWORD dwExtLength = 8192;
|
||||
TCHAR errmsg[8192];
|
||||
int returned = InternetGetLastResponseInfo( &dwInetError, errmsg, &dwExtLength );
|
||||
err.Format("%s\ndwInetError: (%d)\n%s", method, dwInetError, errmsg);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
STDMETHODIMP CFTP::Open()
|
||||
{
|
||||
if (m_hInternetConnect)
|
||||
{
|
||||
InternetCloseHandle(m_hInternetConnect);
|
||||
m_hInternetConnect = NULL;
|
||||
}
|
||||
|
||||
if (!m_hInternetOpen)
|
||||
{
|
||||
m_hInternetOpen = InternetOpen(FTPAGENT,
|
||||
m_Proxyname==""?0:1, /*UseProxy*/
|
||||
m_Proxyname, /*ProxyName*/
|
||||
NULL, /*ProxyBypass*/
|
||||
0); /*Flags*/
|
||||
|
||||
if (!m_hInternetOpen)
|
||||
return AtlReportError (GetObjectCLSID(), inetError("CFTP::Open", "InternetOpen"));
|
||||
}
|
||||
|
||||
m_hInternetConnect = InternetConnect(m_hInternetOpen,
|
||||
m_Hostname, m_Port,
|
||||
m_Username, m_Password,
|
||||
INTERNET_SERVICE_FTP, m_Flags, NULL);
|
||||
if (!m_hInternetConnect)
|
||||
return AtlReportError (GetObjectCLSID(), inetError("CFTP::Open", "InternetConnect"));
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CFTP::SetCurrentDir(BSTR Directory)
|
||||
{
|
||||
if (!m_hInternetConnect)
|
||||
return AtlReportError (GetObjectCLSID(), "\nCFTP::PutFileFromTextData open first");
|
||||
|
||||
BOOL success = FtpSetCurrentDirectory(m_hInternetConnect, CString(Directory));
|
||||
if (!success)
|
||||
return AtlReportError (GetObjectCLSID(), inetError("CFTP::PutFileFromTextData", "InternetWriteFile"));
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CFTP::PutFileFromTextData(BSTR remoteFileName, BSTR data)
|
||||
{
|
||||
if (!m_hInternetConnect)
|
||||
return AtlReportError (GetObjectCLSID(), "\nCFTP::PutFileFromTextData open first");
|
||||
|
||||
CString sData(data);
|
||||
HINTERNET hFile = FtpOpenFile(m_hInternetConnect, CString(remoteFileName),
|
||||
GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0);
|
||||
if (!hFile)
|
||||
return AtlReportError (GetObjectCLSID(), inetError("CFTP::PutFileFromTextData", "FtpOpenFile"));
|
||||
|
||||
DWORD written;
|
||||
BOOL success = InternetWriteFile(hFile, sData, sData.GetLength(), &written);
|
||||
if (!success)
|
||||
return AtlReportError (GetObjectCLSID(), inetError("CFTP::PutFileFromTextData", "InternetWriteFile"));
|
||||
|
||||
//Log2File 1, "Transfer file size: " & Len(body) & " written: " & written
|
||||
//SendFileFTP = True
|
||||
InternetCloseHandle (hFile);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CFTP::Close()
|
||||
{
|
||||
if (m_hInternetConnect)
|
||||
InternetCloseHandle(m_hInternetConnect);
|
||||
m_hInternetConnect = NULL;
|
||||
|
||||
if (!m_hInternetOpen)
|
||||
InternetCloseHandle(m_hInternetOpen);
|
||||
m_hInternetOpen = NULL;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
85
SlnkDWFCom/FTP.h
Normal file
85
SlnkDWFCom/FTP.h
Normal file
@@ -0,0 +1,85 @@
|
||||
// FTP.h : Declaration of the CFTP
|
||||
|
||||
#pragma once
|
||||
#include "resource.h" // main symbols
|
||||
|
||||
#include "SLNKDWF.h"
|
||||
|
||||
#include "Wininet.h"
|
||||
|
||||
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
|
||||
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// CFTP
|
||||
|
||||
class ATL_NO_VTABLE CFTP :
|
||||
public CComObjectRootEx<CComSingleThreadModel>,
|
||||
public CComCoClass<CFTP, &CLSID_FTP>,
|
||||
public ISupportErrorInfo,
|
||||
public IDispatchImpl<IFTP, &IID_IFTP, &LIBID_SLNKDWFLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
|
||||
{
|
||||
public:
|
||||
CFTP(): m_hInternetOpen(NULL), m_hInternetConnect(NULL), m_Username("anonymous"), m_Flags(0)
|
||||
{
|
||||
}
|
||||
~CFTP(void);
|
||||
|
||||
DECLARE_REGISTRY_RESOURCEID(IDR_FTP)
|
||||
|
||||
|
||||
BEGIN_COM_MAP(CFTP)
|
||||
COM_INTERFACE_ENTRY(IFTP)
|
||||
COM_INTERFACE_ENTRY(IDispatch)
|
||||
COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
||||
END_COM_MAP()
|
||||
|
||||
// ISupportsErrorInfo
|
||||
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
|
||||
|
||||
|
||||
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||
|
||||
HRESULT FinalConstruct()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void FinalRelease()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
STDMETHOD(get_Proxyname)(BSTR* pVal);
|
||||
STDMETHOD(put_Proxyname)(BSTR newVal);
|
||||
STDMETHOD(get_Hostname)(BSTR* pVal);
|
||||
STDMETHOD(put_Hostname)(BSTR newVal);
|
||||
STDMETHOD(get_Port)(LONG* pVal);
|
||||
STDMETHOD(put_Port)(LONG newVal);
|
||||
STDMETHOD(get_Username)(BSTR* pVal);
|
||||
STDMETHOD(put_Username)(BSTR newVal);
|
||||
STDMETHOD(get_Password)(BSTR* pVal);
|
||||
STDMETHOD(put_Password)(BSTR newVal);
|
||||
STDMETHOD(get_Flags)(LONG* pVal);
|
||||
STDMETHOD(put_Flags)(LONG newVal);
|
||||
|
||||
STDMETHOD(Open)();
|
||||
STDMETHOD(SetCurrentDir)(BSTR Directory);
|
||||
STDMETHOD(PutFileFromTextData)(BSTR remoteFileName, BSTR data);
|
||||
STDMETHOD(Close)();
|
||||
|
||||
private:
|
||||
HINTERNET m_hInternetOpen;
|
||||
HINTERNET m_hInternetConnect;
|
||||
|
||||
CString m_Proxyname;
|
||||
CString m_Hostname;
|
||||
INTERNET_PORT m_Port;
|
||||
CString m_Username;
|
||||
CString m_Password;
|
||||
DWORD m_Flags;
|
||||
};
|
||||
|
||||
OBJECT_ENTRY_AUTO(__uuidof(FTP), CFTP)
|
||||
26
SlnkDWFCom/FTP.rgs
Normal file
26
SlnkDWFCom/FTP.rgs
Normal file
@@ -0,0 +1,26 @@
|
||||
HKCR
|
||||
{
|
||||
SLNKDWF.FTP.1 = s 'FTP Class'
|
||||
{
|
||||
CLSID = s '{C91E5330-FEC4-42CC-A8F0-304A82F3551B}'
|
||||
}
|
||||
SLNKDWF.FTP = s 'FTP Class'
|
||||
{
|
||||
CLSID = s '{C91E5330-FEC4-42CC-A8F0-304A82F3551B}'
|
||||
CurVer = s 'SLNKDWF.FTP.1'
|
||||
}
|
||||
NoRemove CLSID
|
||||
{
|
||||
ForceRemove {C91E5330-FEC4-42CC-A8F0-304A82F3551B} = s 'FTP Class'
|
||||
{
|
||||
ProgID = s 'SLNKDWF.FTP.1'
|
||||
VersionIndependentProgID = s 'SLNKDWF.FTP'
|
||||
ForceRemove 'Programmable'
|
||||
InprocServer32 = s '%MODULE%'
|
||||
{
|
||||
val ThreadingModel = s 'Apartment'
|
||||
}
|
||||
'TypeLib' = s '{B6FCDE6E-141C-4601-B3AC-4DF4D5F25DF8}'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,6 +391,33 @@ interface ICrypto : IDispatch{
|
||||
[id(4), helpstring("method hex_sha1_file")] HRESULT hex_sha1_file([in] BSTR fname, [out,retval] BSTR* pVal);
|
||||
[id(5), helpstring("method hotp")] HRESULT hotp([in] BSTR hexseed, [in] LONGLONG counter, [in, defaultvalue(6)] BYTE digits, [out,retval] BSTR* pVal);
|
||||
};
|
||||
[
|
||||
object,
|
||||
uuid(5FC1107C-9203-4FEC-92C6-B31135167181),
|
||||
dual,
|
||||
nonextensible,
|
||||
helpstring("IFTP Interface"),
|
||||
pointer_default(unique)
|
||||
]
|
||||
interface IFTP : IDispatch{
|
||||
[id(1), helpstring("method Open")] HRESULT Open();
|
||||
[id(2), helpstring("method SetCurrentDir")] HRESULT SetCurrentDir([in] BSTR Directory);
|
||||
[id(3), helpstring("method PutFileFromTextData")] HRESULT PutFileFromTextData([in] BSTR remoteFileName, [in] BSTR data);
|
||||
[id(4), helpstring("method Close")] HRESULT Close();
|
||||
[propget, id(5), helpstring("property Proxyname")] HRESULT Proxyname([out, retval] BSTR* pVal);
|
||||
[propput, id(5), helpstring("property Proxyname")] HRESULT Proxyname([in] BSTR newVal);
|
||||
[propget, id(6), helpstring("property Hostname")] HRESULT Hostname([out, retval] BSTR* pVal);
|
||||
[propput, id(6), helpstring("property Hostname")] HRESULT Hostname([in] BSTR newVal);
|
||||
[propget, id(7), helpstring("property Port")] HRESULT Port([out, retval] LONG* pVal);
|
||||
[propput, id(7), helpstring("property Port")] HRESULT Port([in] LONG newVal);
|
||||
[propget, id(8), helpstring("property Username")] HRESULT Username([out, retval] BSTR* pVal);
|
||||
[propput, id(8), helpstring("property Username")] HRESULT Username([in] BSTR newVal);
|
||||
[propget, id(9), helpstring("property Password")] HRESULT Password([out, retval] BSTR* pVal);
|
||||
[propput, id(9), helpstring("property Password")] HRESULT Password([in] BSTR newVal);
|
||||
[propget, id(10), helpstring("property Flags")] HRESULT Flags([out, retval] LONG* pVal);
|
||||
[propput, id(10), helpstring("property Flags")] HRESULT Flags([in] LONG newVal);
|
||||
|
||||
};
|
||||
[
|
||||
uuid(B6FCDE6E-141C-4601-B3AC-4DF4D5F25DF8),
|
||||
version(1.0),
|
||||
@@ -550,4 +577,12 @@ library SLNKDWFLib
|
||||
{
|
||||
[default] interface ICrypto;
|
||||
};
|
||||
[
|
||||
uuid(C91E5330-FEC4-42CC-A8F0-304A82F3551B),
|
||||
helpstring("FTP Class")
|
||||
]
|
||||
coclass FTP
|
||||
{
|
||||
[default] interface IFTP;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Zorg dat versies alfabetisch altijd op elkaar volgen!
|
||||
#define SLNK_MAJOR_VERSION 3
|
||||
#define SLNK_MINOR_VERSION 02
|
||||
#define SLNK_MINOR_VERSION 10
|
||||
#define SLNK_BUILD_VERSION 0
|
||||
|
||||
// Define resource strings
|
||||
|
||||
Binary file not shown.
@@ -31,6 +31,7 @@
|
||||
#define IDR_BARCODE 131
|
||||
#define IDR_QRCODE 132
|
||||
#define IDR_CRYPTO 133
|
||||
#define IDR_FTP 134
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
@@ -39,6 +40,6 @@
|
||||
#define _APS_NEXT_RESOURCE_VALUE 201
|
||||
#define _APS_NEXT_COMMAND_VALUE 32768
|
||||
#define _APS_NEXT_CONTROL_VALUE 201
|
||||
#define _APS_NEXT_SYMED_VALUE 134
|
||||
#define _APS_NEXT_SYMED_VALUE 135
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user