Beispiel #1
0
int
ftp_put(void * pio)
{
   FC_MENULOG();
   return ftp_move(pio,0);
}
Beispiel #2
0
void libmftp_main_test(char *host, unsigned int port, char *user, char *pw, char *workingdirectory)
{
	int success = 0;
	ftp_file *f = NULL, *g = NULL;
	ftp_content_listing *cl = NULL, *cl2 = NULL;
	ftp_date d;
	char *buf = NULL;
	ftp_connection *c = ftp_open(host, port, tls == 0 ? ftp_security_none : ftp_security_always);

	/*c->_current_features->use_mlsd = ftp_bfalse;*/

	if (!c) {
		printf("Could not connect. Error: %i\n",ftp_error);
		if (ftp_error == FTP_ESECURITY) {
			printf("This server does not support a TLS connection. FTP_ESECURITY\n");
		}
		goto end;
	}

	if (ftp_auth(c, user, pw, ftp_btrue) != FTP_OK) {
		printf("Could not authenticate. Error: %i\n", c->error);
		goto end;
	}

	if (ftp_change_cur_directory(c, workingdirectory) != FTP_OK) {
		printf("Could not cwd. Error: %i\n", c->error);
		goto end;
	}

	if (ftp_reload_cur_directory(c) != FTP_OK) {
		printf("Could not reload wd. Error: %i\n", c->error);
		goto end;
	}

	if (strcmp(workingdirectory, c->cur_directory) != 0) {
		printf("Warning: Working dir (%s) does not match ftp dir (%s)! Continue? (y/n)\n",workingdirectory,c->cur_directory);
		if (getchar() != 'y') {
			goto end;
		}
	}

	char *test = "This is a test string that will be written to the server.";
	size_t test_len = strlen(test);

	//TEST UPLOAD 1

	f = ftp_fopen(c, "testfile.test", FTP_WRITE, 0);
	if (!f) {
		printf("Could not fopen to write. Error: %i\n", c->error);
		goto end;
	}

	if (ftp_fwrites(test, f) != test_len) {
		printf("Could not write test string. Error: %i\n", *(f->error));
		goto end;
	}

	ftp_fclose(f);
	f = NULL;

	//TEST CONTENT LISTING

	int entry_count;
	cl = ftp_contents_of_directory(c, &entry_count);

	if (!cl) {
		printf("Could not get content listing. Error: %i\n", c->error);
		goto end;
	}

	if (entry_count != 1 || cl->next) {
		printf("More than 1 entry in content listing.\n");
		goto end;
	}

	if (!ftp_item_exists_in_content_listing(cl, "testfile.test", &cl2)) {
		printf("Could not find previously generated file in content listing.\n");
		goto end;
	}

	if (!cl2) {
		printf("Did not get a pointer to the content listing entry.\n");
		goto end;
	}

	if (!cl2->facts.given.modify) {
		printf("Warning: Remote host does not provide modification date information! Continue? (y/n)\n");
		if (getchar() != 'y') {
			goto end;
		}
	} else {
		time_t cur = time(NULL);
		struct tm *curtm = localtime(&cur);
		if (curtm->tm_year + 1900 != cl2->facts.modify.year) {
			printf("Warning: Modification year of remote file (%i) does not equal local year (%i). Continue? (y/n)\n",cl2->facts.modify.year,curtm->tm_year + 1900);
			if (getchar() != 'y') {
				goto end;
			}
		}
	}

	//TEST SIZE

	size_t srv_size;
	if (ftp_size(c, "testfile.test", &srv_size) != FTP_OK) {
		printf("Could not get file size. Error: %i\n", c->error);
		goto end;
	}

	if (srv_size != test_len) {
		printf("Remote file size (%lu) differs from local file size (%lu).\n",srv_size,test_len);
		goto end;
	}

	//TEST READ

	f = ftp_fopen(c, "testfile.test", FTP_READ, 0);
	if (!f) {
		printf("Could not fopen to read. Error: %i\n", c->error);
		goto end;
	}

	buf = malloc(srv_size + 1);

	if (ftp_fread(buf, 1, srv_size, f) != srv_size) {
		printf("Could not read file. Error: %i\n", *(f->error));
		goto end;
	}

	ftp_fclose(f);
	f = NULL;

	*(buf+srv_size) = '\0';
	if (strcmp(test, buf) != 0) {
		printf("Remote file content differs from local file content.\n");
		goto end;
	}

	//TEST UPLOAD 2 (SIMULTANEOUS)

	f = ftp_fopen(c, "testfile1.txt", FTP_WRITE, 0);
	if (!f) {
		printf("Could not fopen to write 2 (1). Error: %i\n", c->error);
		goto end;
	}
	g = ftp_fopen(c, "testfile2.txt", FTP_WRITE, 0);
	if (!g) {
		printf("Could not fopen to write 2 (2). Error: %i\n", c->error);
		goto end;
	}
	if (ftp_fwrites(test, f) != test_len) {
		printf("Could not write test string 2 (1). Error: %i\n", *(f->error));
		goto end;
	}
	if (ftp_fwrites(test, g) != test_len) {
		printf("Could not write test string 2 (2). Error: %i\n", *(g->error));
		goto end;
	}
	ftp_fclose(f);
	ftp_fclose(g);
	f = g = NULL;

	//TEST SIZE 2

	size_t srv_size2;
	if (ftp_size(c, "testfile1.txt", &srv_size) != FTP_OK) {
		printf("Could not get file size 2 (1). Error: %i\n", c->error);
		goto end;
	}
	if (ftp_size(c, "testfile2.txt", &srv_size2) != FTP_OK) {
		printf("Could not get file size 2 (2). Error: %i\n", c->error);
		goto end;
	}
	if (srv_size != test_len || srv_size2 != test_len) {
		printf("Remote file size 2 differs from local file size.\n");
		goto end;
	}

	//TEST FOLDERS

	if (ftp_create_folder(c, "testfolder") != FTP_OK) {
		printf("Could not create folder. Error: %i\n", c->error);
		goto end;
	}

	if (ftp_move(c, "testfile1.txt", "testfolder/testfile1.txt")) {
		printf("Could not move file. Error: %i\n", c->error);
		goto end;
	}

	if (ftp_change_cur_directory(c, "testfolder") != FTP_OK) {
		printf("Could not cwd 2. Error: %i\n", c->error);
		goto end;
	}

	if (!ftp_item_exists(c, "testfile1.txt", NULL)) {
		printf("File does not exist where it was moved to.");
		goto end;
	}

	//TEST DELETE

	if (ftp_delete(c, "testfile1.txt", ftp_bfalse) != FTP_OK) {
		printf("Could not delete file. Error: %i\n", c->error);
		goto end;
	}

	if (ftp_item_exists(c, "testfile1.txt", NULL)) {
		printf("Deleted file still exists.");
		goto end;
	}

	if (ftp_change_cur_directory(c, workingdirectory) != FTP_OK) {
		printf("Could not cwd 3. Error: %i\n", c->error);
		goto end;
	}

	if (ftp_delete(c, "testfolder", ftp_btrue) != FTP_OK) {
		printf("Could not delete folder. Error: %i\n", c->error);
		goto end;
	}

	if (ftp_item_exists(c, "testfolder", NULL)) {
		printf("Deleted folder still exists.");
		goto end;
	}

	if (ftp_delete(c, "testfile.test", ftp_bfalse) != FTP_OK || ftp_delete(c, "testfile2.txt", ftp_bfalse) != FTP_OK) {
		printf("Could not clean up. Error: %i\n", c->error);
		goto end;
	}

	success = 1;
end:
	if (cl) ftp_free(cl);
	if (f) ftp_fclose(f);
	if (g) ftp_fclose(g);
	if (c) ftp_close(c);
	if (buf) free(buf);
	if (!success) {
		printf("Test was NOT successful. :-(\n");
	} else {
		printf("Test was successful! :-)\n");
	}
}
Beispiel #3
0
int
ftp_get(void * pio)
{
   FC_MENULOG();
   return ftp_move(pio,1);
}
Beispiel #4
0
/*------------------------------------------------------------------*/
INT md_file_wclose(INT handle, INT type, INT data_fmt, char *destination)
/********************************************************************
Routine: external md_file_wclose
Purpose: Close a data file used for replay for the given data format
Input:
INT data_fmt :  YBOS or MIDAS 
Output:
none
Function value:
status : from lower function
*******************************************************************/
{
   INT status;

   status = SS_SUCCESS;
   switch (type) {
   case LOG_TYPE_TAPE:
      /* writing EOF mark on tape Fonly */
      status = ss_tape_write_eof(handle);
      ss_tape_close(handle);
      break;
   case LOG_TYPE_DISK:
      /* close file */
      if (handle != 0)
#ifdef OS_WINNT
         CloseHandle((HANDLE) handle);
#else
         close(handle);
#endif
      break;
   case LOG_TYPE_FTP:
#ifdef HAVE_FTPLIB
      {
      char *p, filename[256];
      int  i;

      ftp_close(ftp_con);

      /* 
         destination should have the form:
         host, port, user, password, directory, run%05d.mid, file_mode, command, ...
      */
      p = destination;
      for (i=0 ; i<5 && p != NULL ; i++) {
         p = strchr(p, ',');
         if (*p == ',')
            p++;
      }
      if (p != NULL) {
         strlcpy(filename, p, sizeof(filename));
         if (strchr(filename, ','))
            *strchr(filename, ',') = 0;
      } else
         strlcpy(filename, destination, sizeof(filename));

      /* if filename starts with a '.' rename it */
      if (filename[0] == '.')
         ftp_move(ftp_con, filename, filename+1);

      ftp_bye(ftp_con);
      }
#endif
      break;
   }
   if (status != SS_SUCCESS)
      return status;
   return (MD_SUCCESS);
}