Add a Secure Folder
The following code sample illustrates how to add a secure folder.
Code Sample
See the C++ environment settings for details on setting the project environment.
<cpp_adminlocal_addsecurefolder.cpp>
/*****************************************************************************************
*
* cpp_adminlocal_addsecurefolder.cpp
*
*
******************************************************************************************/
#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin_local.h"
#include "teadmin_efefs.h"
#include "teefefs_securefolder.h"
using namespace ERUCES;
using namespace std;
int main()
{
string strServer = "localhost"; // this is the remote engine, not the TE server.
long nPort = 5050; // this is the local admin port.
string strUser = "ls"; // this is a normal TE user, not necessarily a TE admin user.
string strPswd = "password";
try
{
// Connect to local server
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strUser);
ctx->setPasswd(strPswd);
ctx->setMode(2); // set to 2 if going to call setConfiguration().
conn->open(strServer, nPort, *ctx.operator->());
cout << "Connected to " << strServer << " as " << strUser
<< " at port " << nPort << endl;
// Efefs administrator
TEAdminEfefs adminEfefs;
adminEfefs.attachConnection(conn.operator->());
// List secure folders before adding secure folder
TEObjectContainer cont;
adminEfefs.getSecureFolder(cont);
cout << "Before adding secure folder, number of secure folders = " << cont.size() << endl;
int i;
for (i=0; i < cont.size(); ++i)
{
TEEfefsSecureFolder *secureFolder = (TEEfefsSecureFolder*)cont[i];
cout << endl;
cout << "\tSource: " << secureFolder->getSource() << endl;
cout << "\tDestination: " << secureFolder->getDestination() << endl;
cout << "\tUser: " << secureFolder->getUser() << endl;
}
TEEfefsSecureFolder newSecureFolder;
newSecureFolder.setSource("C:\\Temp");
newSecureFolder.setDestination("C:\\Temp");
adminEfefs.updateSecureFolder(newSecureFolder);
// List secure folders after adding secure folder
cont.clear();
adminEfefs.getSecureFolder(cont);
cout << "After adding secure folder, number of secure folders = " << cont.size() << endl;
for (i=0; i < cont.size(); ++i)
{
TEEfefsSecureFolder *secureFolder = (TEEfefsSecureFolder*)cont[i];
cout << endl;
cout << "\tSource: " << secureFolder->getSource() << endl;
cout << "\tDestination: " << secureFolder->getDestination() << endl;
cout << "\tUser: " << secureFolder->getUser() << endl;
}
adminEfefs.detachConnection();
// Disconnect from local server
conn->close();
cout << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}
Output
Connected to localhost as ls at port 5050
Before adding secure folder, number of secure folders = 0
After adding secure folder, number of secure folders = 1
Source: C:\Temp\
Destination: C:\Temp\
User:
Disconnected from localhost
Press any key to continue