Exemplo n.º 1
0
bool FtpManager::createDirectory(const QString &remoteDir, const QString &directoryName)
{
    if (!_initialized)
        emit requestInitialize();
    if (!_initialized)
        throw FtpException();

    try
    {
        Poco::Timespan time(0, 0, 1, 0, 0);
        std::string host = _url.toStdString();
        std::string uname = _user.toStdString();
        std::string password = _password.toStdString();

        Poco::Net::FTPClientSession session(host);
        session.setTimeout(time);
        session.login(uname, password);
        std::string dir = QString(remoteDir + "/" + directoryName).toStdString();
        session.createDirectory(dir);
        session.close();
        return true;
    }
    catch (Poco::Net::FTPException &ex)
    {
        std::cerr << ex.displayText();
        return false;
    }
}
Exemplo n.º 2
0
QString FtpManager::getCurrentDirectory()
{
    if (!_initialized)
        emit requestInitialize();
    if (!_initialized)
        throw FtpException();

    QString workDir = "";
    try
    {
        Poco::Timespan time(0, 0, 1, 0, 0);
        std::string host = _url.toStdString();
        std::string uname = _user.toStdString();
        std::string password = _password.toStdString();

        Poco::Net::FTPClientSession session(host);
        session.setTimeout(time);
        session.login(uname, password);
        std::string currDir = session.getWorkingDirectory();
        session.close();
        workDir = QString::fromStdString(currDir);
    }
    catch (Poco::Net::FTPException &ex)
    {
        std::cerr << ex.displayText();
    }
    return workDir;
}
Exemplo n.º 3
0
NodeList FtpManager::getDirectoryContents(const QString &remoteDir, const QString &localFolder)
{
    if (!_initialized)
        emit requestInitialize();
    if (!_initialized)
        throw FtpException();

    try
    {
        Poco::Timespan time(0, 0, 1, 0, 0);
        std::string dir = remoteDir.toStdString();
        std::string host = _url.toStdString();
        std::string uname = _user.toStdString();
        std::string password = _password.toStdString();

        Poco::Net::FTPClientSession session(host);
        session.setTimeout(time);
        session.login(uname, password);
        std::istream &is = session.beginList(remoteDir.toStdString(), true);
        std::ostringstream os;
        stream_copy_n(is, 0, os);
        session.endList();
        session.close();
        std::cerr << os.str();
        NodeList dirContents = parseDirectoryContents(os, _isWindows);
        return dirContents;
    }
    catch (Poco::Net::FTPException &ex)
    {
        std::cerr << ex.displayText();
        return NodeList::create();
    }
}
Exemplo n.º 4
0
bool FtpManager::changeDirectory(const QString &remoteDir)
{
    if (!_initialized)
        emit requestInitialize();
    if (!_initialized)
        throw FtpException();

    //TODO: implement it
    return false;
}
Exemplo n.º 5
0
bool FtpManager::downloadFile(const QString &remoteDir, const QString &filename, const QString &localFolder)
{
    if (!_initialized)
        emit requestInitialize();
    if (!_initialized)
        throw FtpException();

    try
    {
        Poco::Timespan time(0, 0, 1, 0, 0);
        std::string dir = remoteDir.toStdString();
        std::string file = filename.toStdString();
        std::string host = _url.toStdString();
        std::string uname = _user.toStdString();
        std::string password = _password.toStdString();

        Poco::Net::FTPClientSession session(host);
        session.setTimeout(time);
        session.login(uname, password);
        session.setWorkingDirectory(dir);
        session.setFileType(Poco::Net::FTPClientSession::TYPE_BINARY);
        std::istream& is = session.beginDownload(file);
        std::ofstream ofs;

        QString completePath;
        if (remoteDir.endsWith("/"))
            completePath = localFolder + remoteDir + filename;
        else
            completePath = localFolder + remoteDir + "/" + filename;
        ofs.open(completePath.toStdString(), std::ofstream::out | std::ofstream::app | std::ofstream::binary);
        stream_copy_n(is, is.gcount(), ofs);
        ofs.close();
        session.endDownload();
        session.close();
        QFile f(completePath);
        f.setPermissions(QFileDevice::Permission::ReadGroup
                         | QFileDevice::Permission::ReadOther
                         | QFileDevice::Permission::ReadOwner
                         | QFileDevice::Permission::ReadUser);
        return true;
    }
    catch (Poco::Net::FTPException &ex)
    {
        std::cerr << ex.displayText();
        return false;
    }
}
Exemplo n.º 6
0
bool FtpManager::fileExists(const QString &remoteDir, const QString &filename)
{
    if (!_initialized)
        emit requestInitialize();
    if (!_initialized)
        throw FtpException();

    try
    {
        Poco::Timespan time(0, 0, 1, 0, 0);
        std::string dir = (remoteDir + filename).toStdString();
        std::string host = _url.toStdString();
        std::string uname = _user.toStdString();
        std::string password = _password.toStdString();

        Poco::Net::FTPClientSession session(host);
        session.setTimeout(time);
        session.login(uname, password);
        std::istream &is = session.beginList(dir, true);
        std::ostringstream os;
        stream_copy_n(is, 0, os);
        session.endList();
        session.close();
        std::cerr << os.str();
        NodeList dirContents = parseDirectoryContents(os, _isWindows);
        return dirContents->count() > 0;
    }
    catch (Poco::Net::FTPException &ex)
    {
        std::cerr << ex.displayText();
        std::cerr << ex.message();
        if (ex.code() == 550)
        {
            return false;
        }
        throw ex;
    }
    return false;
}
Exemplo n.º 7
0
bool FtpManager::uploadFile(const QString &remoteDir, const QString &filename, const QString &localFilename)
{
    if (!_initialized)
        emit requestInitialize();
    if (!_initialized)
        throw FtpException();

    try
    {
        Poco::Timespan time(0, 0, 1, 0, 0);
        std::string dir = remoteDir.toStdString();
        std::string file = filename.toStdString();
        std::string host = _url.toStdString();
        std::string uname = _user.toStdString();
        std::string password = _password.toStdString();

        Poco::Net::FTPClientSession session(host);
        session.setTimeout(time);
        session.login(uname, password);
        session.setWorkingDirectory(dir);
        session.setFileType(Poco::Net::FTPClientSession::TYPE_BINARY);
        std::ostream& os = session.beginUpload(file);
        std::ifstream ifs;

        ifs.open(localFilename.toStdString(), std::ifstream::in | std::ifstream::app | std::ifstream::binary);

        stream_copy_n(ifs, ifs.gcount(), os);
        ifs.close();
        session.endDownload();
        session.close();
        return true;
    }
    catch (Poco::Net::FTPException &ex)
    {
        std::cerr << ex.displayText();
        return false;
    }
}
Exemplo n.º 8
0
	c22->setPen(static_cast<QColor>(Qt::black));
	c22->attach(s22);




}

void MainWindow::setupSignalsAndSlots()
{
	connect(ui->doInitialize, SIGNAL(clicked(bool)), this, SLOT(onInitializeToggled(bool)));
	connect(ui->runToggle, SIGNAL(clicked(bool)), this, SLOT(onRunToggled(bool)));

	// MainWindow to VNALibrary
	connect(this, SIGNAL(requestLoadDLL(QString)), &lib, SLOT(loadAsync(QString)));
	connect(this, SIGNAL(requestInitialize(QtTaskHandle, Qtvoidptr)), &lib, SLOT(initializeAsync(QtTaskHandle, Qtvoidptr)));
	connect(this, SIGNAL(requestStart(QtTaskHandle)), &lib, SLOT(startAsync(QtTaskHandle)));
	connect(this, SIGNAL(requestStop(QtTaskHandle)), &lib, SLOT(stopAsync(QtTaskHandle)));
	connect(this, SIGNAL(requestUtilPingUnit(QtTaskHandle)), &lib, SLOT(utilPingUnitAsync(QtTaskHandle)));
	connect(this, SIGNAL(requestMeasureUncalibrated(QtTaskHandle,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData)),
			&lib, SLOT(measureUncalibratedAsync(QtTaskHandle, QtComplexData, QtComplexData, QtComplexData, QtComplexData, QtComplexData)));
	connect(this, SIGNAL(requestMeasure2PortCalibrated(QtTaskHandle,QtComplexData,QtComplexData,QtComplexData,QtComplexData)),
			&lib, SLOT(measure2PortCalibratedAsync(QtTaskHandle, QtComplexData, QtComplexData, QtComplexData, QtComplexData)));
	connect(this, SIGNAL(requestMeasureCalibrationStep(QtTaskHandle,QtCalibrationStep)),
			&lib, SLOT(measureCalibrationStepAsync(QtTaskHandle, QtCalibrationStep)));
	connect(this, SIGNAL(requestImportCalibrationAsync(QtTaskHandle,const double*,uint,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData)),
			&lib, SLOT(importCalibrationAsync(QtTaskHandle,const double*,uint,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData,QtComplexData)));
	connect(this, SIGNAL(requestClearCalibration(QtTaskHandle)), &lib, SLOT(clearCalibrationAsync(QtTaskHandle)));

	// VNALibrary to MainWindow
	connect(&lib, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));