Ejemplo n.º 1
0
int
UploadFiles(const char *cookie, int projID, int expID, int trialID, File *theFile, const char *path, int basePath) 
{
  int res =0;

  if (theFile == 0)
    return 0;



  const char *fileName = theFile->getName();

  if (theFile->isDir() == true) {

    res = neesADD_TrialAnalysisDir(cookie, projID, expID, trialID, &path[basePath], fileName);

    FileIter theDirFiles = theFile->getFiles();
    File *theDirFile;

    if (res < 0) {
      opserr << "ERROR: SimulationInformation.cpp - uploadFiles() - failed to add directory: " << fileName 
	     << " to path: " << &path[basePath] << endln;
      return res;
    }

    while ((theDirFile = theDirFiles()) != 0) {
      res = UploadFiles(cookie, projID, expID, trialID, theDirFile, theFile->getDescription(), basePath);
      if (res < 0)
	return res;
    }      

  } else {

    res =  neesADD_TrialAnalysisFile(cookie,
				     projID,
				     expID,
				     trialID,
				     path,
				     basePath,
				     theFile->getName(),
				     theFile->getDescription());    

    if (res < 0) {
      opserr << "ERROR: SimulationInformation.cpp - uploadFiles() - failed to add file: " << fileName 
	     << " to path: " << &path[basePath] << endln;
      return res;
    }
  }

  return 0;
}
Ejemplo n.º 2
0
int PostProc_UploadReport( const char *uploadURL, int deletereport, int zipreport, char *reportLocation )
{
	if ( gFopenHistoryPtr && !IsStopped() )
	{
		char	sourcepath[256];
		char	server[256], ftppath[256], name[64], passwd[32];
		char	*source;
		void	*fs;

		if ( IsURL( uploadURL ) )
		{
			char msg[256];
			ExtractUserFromURL( (char*)uploadURL, server, name, passwd, ftppath );
			DateFixFilename( ftppath, 0 );
			fs = (void*)FtpServerOpen( server, name, passwd );
			if ( fs ){
				sprintf( msg, "FTP %s@%s/%s", name,server,ftppath );
				StatusSet( msg );
			} else 
			{
				FtpServerOpenError( server );
				return 1;
			}
		}

		PathFromFullPath( reportLocation, sourcepath );
		DateFixFilename( sourcepath, 0 );

		// ---------------- UPLOAD ALL INDIVIDUAL FILES
		if ( !zipreport )
		{
			long files;
			files = UploadFiles( fs, (char*)uploadURL, sourcepath, ftppath, deletereport );
			if ( files>0 )
				OutDebugs( "%d files uploaded.", files );
			else
				OutDebugs( "Upload canceled" );

			FtpClose( fs );
			OutDebugs( "Ftp Site Closed" );
		} else
		// ----------------- UPLOAD SINGLE ZIP REPORT
		{
			long	uploadStatus = 0;
			char	srczipname[256];
			char	newfilename[256];

			mystrcpy( srczipname, reportLocation );
			DateFixFilename( srczipname, 0 );
			PathFromFullPath( srczipname, sourcepath );

			if ( !strstr( srczipname, ".zip" ) )
			{
				source = strrchr( srczipname, '.' );
				if ( source )
					mystrcpy( source, ".zip" );
				else
					return 3;
			}
			source = srczipname;

			// Find the FILENAME Component
			if ( strstr( srczipname, sourcepath ) )
			{
				source += strlen( sourcepath );
			}

			// generate remote full path PATH+NAME
			CopyFilenameUsingPath( newfilename, (char*)uploadURL, source );

			// Ok things are ok, lets now upload the zip file
			if ( IsURL( uploadURL ) )
			{
				char fullURLPath[256];
				sprintf( fullURLPath, "%s%s", ftppath, source );

				// upload the zip file
				uploadStatus = FtpFileUpload( fs, srczipname, fullURLPath, source );
				if ( uploadStatus == FTPERR_CANTMAKEDIR )
					ErrorMsg( "Could not make directory %s on ftp server .\nMaybe path does not exist?", ftppath );

				FtpClose( fs );
			}

			if( deletereport && uploadStatus == FTPERR_COMPLETE )
			{
				OutDebugs( "Deleting local zip file %s", srczipname );
				remove( srczipname );
			}
		}
	}
	return 0;
}
Ejemplo n.º 3
0
int 
SimulationInformation::neesUpload(const char *username, 
				  const char *passwd, 
				  int projID, 
				  int expID)
{
#ifdef _HTTPS

  // call endTime if not already called
  if (strcmp(endTime, " ") == 0)
    this->end();

  int res =0;
  int trialID =0;
  char *cookie = 0;

  //
  // we first need to login
  //

  if (username == 0 || passwd== 0) {
    opserr << "ERROR: SimulationInformation::neesUpload()  could not login to nees central no username or passwd provided\n";
    return -1;
  }

  res = neesLogin(username, passwd, &cookie);
  if (res != 0) {
    if (cookie != 0)
      free(cookie);

    opserr << "ERROR: SimulationInformation::neesUpload() - failed to login check username: "******" & password: "******"\n";
    return -1;
  }

  if (cookie != 0) 
    opserr << "SimulationInformation::neesUpload() - information about cookie: " << cookie << endln;
  
  //
  // we first add trial to the projects experiment
  //

  trialID = neesADD_Trial(cookie, projID, expID, title, title, " ", description);

  if (trialID < 0) {
    if (cookie != 0) 
      free(cookie);
    
    opserr << "SimulationInformation::neesUpload() - failed to create new Trial in project: "
	   << projID << " experiment: " << expID << "\n";

    return -2;
  }

  //
  // we now add the files
  // first determine root dir for project in nees central, lowest branch with multiple dir os a file
  //

  File *startLoadingDir = theFiles;

  int foundRoot = false;
  while (foundRoot == false) {
    if (startLoadingDir->isDir() == true && startLoadingDir->getNumFiles() == 1) {
      FileIter theDirFiles = startLoadingDir->getFiles();
      startLoadingDir = theDirFiles();
    } else
      foundRoot = true;
  }

  if (startLoadingDir->isDir() == false)
    startLoadingDir = startLoadingDir->getParentDir();

  //
  // now call UploadFiles on this root directory
  //

  const char *path = startLoadingDir->getDescription();
  int pathLength = strlen(path)-1;

  FileIter theDirFiles = startLoadingDir->getFiles();
  File *theDirFile;
  while ((theDirFile = theDirFiles()) != 0) 
      res += UploadFiles(cookie, projID, expID, trialID, theDirFile, startLoadingDir->getDescription(), pathLength);





  free(cookie);
  return res;

#else
  opserr << "ERROR: SimulationInformation::neesUpload() - not available in this build\n";
  return -1;

#endif
}