0% found this document useful (0 votes)
90 views19 pages

Description For Implementation of Globus-C Program To Check The Valid "Grid

The document describes 3 Globus-C programs: 1. Checks the validity of a Grid Proxy and displays the time remaining until expiration. 2. Performs GRAM authentication with a remote site and displays the authentication status. 3. Submits the "/bin/hostname" job to a remote site, displays the job status using callbacks, and stores the output files locally if successful.

Uploaded by

Viral Parmar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views19 pages

Description For Implementation of Globus-C Program To Check The Valid "Grid

The document describes 3 Globus-C programs: 1. Checks the validity of a Grid Proxy and displays the time remaining until expiration. 2. Performs GRAM authentication with a remote site and displays the authentication status. 3. Submits the "/bin/hostname" job to a remote site, displays the job status using callbacks, and stores the output files locally if successful.

Uploaded by

Viral Parmar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Program 1

Description for implementation of Globus-C program to check the valid "Grid Proxy"

Objective Write a simple Globus-C program to verify the "Grid Proxy " using Globus C APIs.

Description Check the validity of Grid Proxy.

Output Display the validity of Grid Proxy and prints the time left for the validity for the proxy.

Source Code
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "globus_common.h" #include "globus_gram_client.h" #define array_size 300 #define simple_job "/bin/hostname" #define remote_host "sparrow" #define remote_host_wk_dir "/tmp" //#define remote_host "pigeon" typedef struct { globus_mutex_t mutex; globus_cond_t cond; globus_bool_t done; } monitor_t; static void callback_func(void * user_callback_arg,char * job_contact,int state,int errorcode); int main(int argc, char *argv[]) { char rsl[array_size],rm_contact[array_size]; globus_libc_printf("\n\t\t DESCRIPTION : Program submiting a simple job to remote site .."); globus_libc_printf("\n\t\t Running Job [%s] at ",simple_job,remote_host); /* Preparing the rsl script */ strcpy(rsl,"&(directory="); strcat(rsl, remote_host_wk_dir); %s

globus_libc_printf("\n\t\t Running Job [%s] at

%s ",simple_job,remote_host);

/* Preparing the rsl script */ strcpy(rsl,"&(directory="); strcat(rsl, remote_host_wk_dir); strcat(rsl, ")(stdout=gram-simple-job-stdout.txt)(stderr=gram-simple-jobstderr.txt)(executable="); strcat(rsl,simple_job); strcat(rsl,")"); /* Submiting the job to remote sites */ submit_job(remote_host, rsl); globus_libc_printf("\n\t\t NOTE : The Output file (gram-simple-jobstdout.txt) and "); globus_libc_printf("\n\t\t the Error File (gram-simple-jobstderr.txt) of the job are"); globus_libc_printf("\n\t\t stored at working directory defined in the program.\n "); return 0; } /* Function name : submit_job() Desription : This function submits the job. Paramaeters : Require the rsl string and the remote job manager. usage : submit_job(rm_contat_mgr, rsl); */ int submit_job(char *rm_contact, char *rsl) { monitor_t Monitor; char * callback_contact; char * job_contact; int rc,job_state_mask; /* Activating the module GLOBUS_GRAM_CLIENT */ rc=globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE); if(rc != GLOBUS_SUCCESS) { globus_libc_printf("\n\t\t ERROR : gram module activation failed." "\n\t\t ERROR : %d - %s . \n\t\t So Terminating...\n",rc,globus_gram_client_error_string(rc)); return(1); } /* Initialize the monitor function to look for callbacks. It initializes the locking mechanism, and then the condition variable */ globus_mutex_init(&Monitor.mutex, (globus_mutexattr_t *) NULL); globus_cond_init(&Monitor.cond, (globus_condattr_t *) NULL); /* entering the monitor and clearing the flag. Locking the Monitor to prevent anything else from changing the value of Monitor.done */ globus_mutex_lock(&Monitor.mutex); /* Change the value of Monitor.done to false, initializing it */ Monitor.done = GLOBUS_FALSE; /* Releasing the lock on the monitor, letting anything else access it */ globus_mutex_unlock(&Monitor.mutex); /* Setting up the communications port for returning the callback.

globus_mutex_unlock(&Monitor.mutex); /* Setting up the communications port for returning the callback. The callback_contact is the callback identifier returned by the function */ globus_gram_client_callback_allow(callback_func, (void *) &Monitor, &callback_contact); /* Send the GRAM request. The rm_contact, rsl, and job_state_mask were set up. The callback_contact was just returned by globus_gram_client_callback_allow. The job_request is returned by the following function */ job_state_mask = GLOBUS_GRAM_PROTOCOL_JOB_STATE_ALL; rc = globus_gram_client_job_request(rm_contact, rsl, job_state_mask, callback_contact, &job_contact); if (rc != 0) { globus_libc_printf("\n\t\t ERROR : gram error: %d - %s \n\t\t So Terminating.\n", rc,globus_gram_client_error_string(rc)); return(1); } globus_mutex_lock(&Monitor.mutex); while (!Monitor.done) { /* */ globus_cond_wait(&Monitor.cond, &Monitor.mutex); } /* end of while */ globus_mutex_unlock(&Monitor.mutex); /**/ globus_mutex_destroy(&Monitor.mutex); globus_cond_destroy(&Monitor.cond); /* Free up the resources of the job_contact, as the job is over, and the contact is now useless. */ globus_gram_client_job_contact_free(job_contact); /* deactivating the module GLOBUS_GRAM_CLIENT */ globus_module_deactivate(GLOBUS_GRAM_CLIENT_MODULE); return 0; } /* Function name : void callback_func(void * user_callback_arg,char * job_contact,int state,int errorcode) Description : callback_func() is used in submit_job() This is the callback function. This is the function called from the job manager, which provides values for state and errorcode */ static void callback_func(void * user_callback_arg,char * job_contact,int state,int errorcode) { monitor_t * Monitor = (monitor_t *) user_callback_arg; switch(state) { case GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING: globus_libc_printf("\n\t\t Job Status :: PENDING "); break; case GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE: globus_libc_printf("\n\t\t Job Status :: ACTIVE ");

case GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE: globus_libc_printf("\n\t\t Job Status :: ACTIVE "); break; case GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED: globus_libc_printf("\n\t\t Job Status :: FAILED "); globus_mutex_lock(&Monitor->mutex); Monitor->done = GLOBUS_TRUE; globus_cond_signal(&Monitor->cond); globus_mutex_unlock(&Monitor->mutex); break; case GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE: globus_libc_printf("\n\t\t Job Status :: DONE "); globus_mutex_lock(&Monitor->mutex); Monitor->done = GLOBUS_TRUE; globus_cond_signal(&Monitor->cond); globus_mutex_unlock(&Monitor->mutex); break; } /* end of qwitch case */ } /* end of callback_fun() */

Program 2
Description for implementation of Globus-C program to perform the "GRAM Authentication".

Objective Write a simple Globus-C program to perform the "GRAM Authentication " with remote site using Globus C APIs.

Description The example takes the remote site FQDN as input from and performs the GRAM authentication with remote site and display the status of "GRAM Authentication".

Output Display the status of "GRAM Authentication" with each remote site.

Source Code
#include #include #include #include <stdio.h> <stdlib.h> <string.h> "globus_gram_client.h"

int main(int argc, char *argv[]) { char *remote_site; globus_result_t status; printf("\n\t\t DESCRIPTION : Program to check Mutual Authentication \n\t\t\t\t between client and server. "); /* Check for the arguments */ if(argc != 2) { printf("\n\t ERROR : Invalid Argumetns. "); printf("\n\t Usage : <bin_name> <remote site FQDN> \n"); return 1; } /* Get the remote site hostnam / FQDN */ remote_site = (char*)malloc(strlen(argv[1])*sizeof(char)); if(remote_site == NULL) { printf("\n\t ERROR : Failed to create memeory. "); return 1; } strcpy(remote_site,argv[1]);

globus_libc_printf("\n\t Authentication with the remote site : %s ", remote_site); status = globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE); if(status = GLOBUS_SUCCESS) {

if(status = GLOBUS_SUCCESS) { globus_libc_printf("\n\t ERROR : GLOBUS_GRAM_CLIENT_MODULE activation failed. \n\t ERROR : %s\n",globus_gram_client_error_string(status)); return 1; } status = globus_gram_client_ping(remote_site); if(status == 0) { globus_libc_printf("\n\t %s : AUTHENTICATION Sucessful: Available to run jobs.",remote_site); } else { globus_libc_printf("\n\t %s : AUTHENTICATION Failure: ", remote_site); globus_libc_printf("\n\t ERROR : %s .\n",globus_gram_client_error_string(status)); /* return 1;*/ } /* Freeing the dynamically allocated memory */ if(remote_site!= NULL) free(remote_site); globus_libc_printf("\n"); return 0; }

Program 3
Description for implementation of Globus-C program to submit a simple job to remote site.

Objective Write a simple Globus-C program to submit job /bin/hostname to remote site and get the status of the job usingGRAM module .

Description The example submits simple job /bin/hostname to remote site FQDN and gets the status of the job. If the job is executed successfully then the output and error files are stored in the /tmp i> directory of the remote site.

Output Display the status of the job execution.

Source Code <stdio.h> #include


#include <stdlib.h> #include <string.h> #include "globus_common.h" #include "globus_gram_client.h" #define array_size 300 #define simple_job "/bin/hostname" #define remote_host "sparrow" #define remote_host_wk_dir "/tmp" //#define remote_host "pigeon" typedef struct { globus_mutex_t mutex; globus_cond_t cond; globus_bool_t done; } monitor_t; static void callback_func(void * user_callback_arg,char * job_contact,int state,int errorcode); int main(int argc, char *argv[]) { char rsl[array_size],rm_contact[array_size]; globus_libc_printf("\n\t\t DESCRIPTION : Program submiting a simple job to remote site .."); globus_libc_printf("\n\t\t Running Job [%s] at %s ",simple_job,remote_host); /* Preparing the rsl script */ strcpy(rsl,"&(directory=");

/* Preparing the rsl script */ strcpy(rsl,"&(directory="); strcat(rsl, remote_host_wk_dir); strcat(rsl, ")(stdout=gram-simple-job-stdout.txt)(stderr=gram-simple-jobstderr.txt)(executable="); strcat(rsl,simple_job); strcat(rsl,")"); /* Submiting the job to remote sites */ submit_job(remote_host, rsl); globus_libc_printf("\n\t\t NOTE : The Output file (gram-simple-jobstdout.txt) and "); globus_libc_printf("\n\t\t the Error File (gram-simple-jobstderr.txt) of the job are"); globus_libc_printf("\n\t\t stored at working directory defined in the program.\n "); return 0; } /* Function name : submit_job() Desription : This function submits the job. Paramaeters : Require the rsl string and the remote job manager. usage : submit_job(rm_contat_mgr, rsl); */ int submit_job(char *rm_contact, char *rsl) { monitor_t Monitor; char * callback_contact; char * job_contact; int rc,job_state_mask; /* Activating the module GLOBUS_GRAM_CLIENT */ rc=globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE); if(rc != GLOBUS_SUCCESS) { globus_libc_printf("\n\t\t ERROR : gram module activation failed." "\n\t\t ERROR : %d - %s . \n\t\t So Terminating...\n",rc,globus_gram_client_error_string(rc)); return(1); } /* Initialize the monitor function to look for callbacks. It initializes the locking mechanism, and then the condition variable */ globus_mutex_init(&Monitor.mutex, (globus_mutexattr_t *) NULL); globus_cond_init(&Monitor.cond, (globus_condattr_t *) NULL); /* entering the monitor and clearing the flag. Locking the Monitor to prevent anything else from changing the value of Monitor.done */ globus_mutex_lock(&Monitor.mutex); /* Change the value of Monitor.done to false, initializing it */ Monitor.done = GLOBUS_FALSE; /* Releasing the lock on the monitor, letting anything else access it */ globus_mutex_unlock(&Monitor.mutex); /* Setting up the communications port for returning the callback. The callback_contact is the callback identifier returned by the function */ globus_gram_client_callback_allow(callback_func,

/* Setting up the communications port for returning the callback. The callback_contact is the callback identifier returned by the function */ globus_gram_client_callback_allow(callback_func, (void *) &Monitor, &callback_contact); /* Send the GRAM request. The rm_contact, rsl, and job_state_mask were set up. The callback_contact was just returned by globus_gram_client_callback_allow. The job_request is returned by the following function */ job_state_mask = GLOBUS_GRAM_PROTOCOL_JOB_STATE_ALL; rc = globus_gram_client_job_request(rm_contact, rsl, job_state_mask, callback_contact, &job_contact); if (rc != 0) { globus_libc_printf("\n\t\t ERROR : gram error: %d - %s \n\t\t So Terminating.\n", rc,globus_gram_client_error_string(rc)); return(1); } globus_mutex_lock(&Monitor.mutex); while (!Monitor.done) { /* */ globus_cond_wait(&Monitor.cond, &Monitor.mutex); } /* end of while */ globus_mutex_unlock(&Monitor.mutex); /**/ globus_mutex_destroy(&Monitor.mutex); globus_cond_destroy(&Monitor.cond); /* Free up the resources of the job_contact, as the job is over, and the contact is now useless. */ globus_gram_client_job_contact_free(job_contact); /* deactivating the module GLOBUS_GRAM_CLIENT */ globus_module_deactivate(GLOBUS_GRAM_CLIENT_MODULE); return 0; } /* Function name : void callback_func(void * user_callback_arg,char * job_contact,int state,int errorcode) Description : callback_func() is used in submit_job() This is the callback function. This is the function called from the job manager, which provides values for state and errorcode */ static void callback_func(void * user_callback_arg,char * job_contact,int state,int errorcode) { monitor_t * Monitor = (monitor_t *) user_callback_arg; switch(state) { case GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING: globus_libc_printf("\n\t\t Job Status :: PENDING "); break; case GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE: globus_libc_printf("\n\t\t Job Status :: ACTIVE "); break; case GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED: globus_libc_printf("\n\t\t Job Status :: FAILED "); globus_mutex_lock(&Monitor->mutex); Monitor->done = GLOBUS_TRUE;

case GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED: globus_libc_printf("\n\t\t Job Status :: FAILED "); globus_mutex_lock(&Monitor->mutex); Monitor->done = GLOBUS_TRUE; globus_cond_signal(&Monitor->cond); globus_mutex_unlock(&Monitor->mutex); break; case GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE: globus_libc_printf("\n\t\t Job Status :: DONE "); globus_mutex_lock(&Monitor->mutex); Monitor->done = GLOBUS_TRUE; globus_cond_signal(&Monitor->cond); globus_mutex_unlock(&Monitor->mutex); break; } /* end of qwitch case */ } /* end of callback_fun() */

Program 4
Description for implementation of Globus-C program to perform the client to server data transfer .

Objective Write a simple Globus-C program to transfer the data file from client to each server using Globus GridFTPmodule .

Description The example prepares source url ( Full path of the file to be transferred) and destination url (gsiftp://remoteSiteFQDN/fullpathforrecievingthefile) and transfer the data file from client site to remote site and display the status of file transfer.

Output Display the status of the file transfer.

Source Code
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "globus_common.h" #include "globus_ftp_client.h" #define #define #define #define array_size 300 BUFFER_SIZE 20480 src "/tmp/gridftp_client_server_file_transfer.txt" dst "parrot/tmp/gridftp_client_server_file_transfer.txt"

globus_mutex_t lock; globus_cond_t cond; globus_bool_t done; int grid_ftp_client_server_put(char * ,char *); static void data_callback(void *, globus_ftp_client_handle_t *, globus_object_t *, globus_byte_t *, globus_size_t ,globus_off_t, globus_bool_t); void callback_function(void *, globus_ftp_client_handle_t *, globus_object_t *); int create_datafile(char *,char *); int main(int argc, char *argv[]) { char src_url[array_size],dst_url[array_size]; globus_libc_printf("\n\t\t DESCRIPTION : Program for file transfer between

client and server using the GridFTP "); /* Generation of the data file at the client */ /* Prepration of the src_url string */ strcpy(src_url,src); if(create_datafile(src_url,"gridftp-client-server-data-file.txt") == 1) { globus_libc_printf("\n\t\t ERROR : Failed to create the Data file for the transfer."); return 1; } /* The client to remote server copy */ /* Prepration of the dst_url string */ strcpy(dst_url,"gsiftp://"); strcat(dst_url, dst); globus_libc_printf("\n\t\t --> Data file %s is transferred \n\t\t to %s ",src_url,dst_url); grid_ftp_client_server_put(src_url,dst_url); globus_libc_printf("\n"); return 0; }/* End of main */ int grid_ftp_client_server_put(char *src_url,char *dst_url) { FILE *file; globus_ftp_client_handle_t handle; globus_byte_t gbuffer[BUFFER_SIZE]; int result; /*open the local source file*/ file = fopen(src_url,"r"); if (file == NULL) { globus_libc_printf("\n\t\t ERROR : Can't Open file: %s\n",src_url); return 1; } result = globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); if (result != GLOBUS_SUCCESS) { globus_libc_printf("\n\t\t ERROR : Failed to load the Globus FTP Client Module\n "); return 1; } globus_ftp_client_handle_init(&handle, GLOBUS_NULL); /* globus_ftp_client_put starts the protocol exchange on the control channel Note : This does NOT start moving data over the data channel */ done = GLOBUS_FALSE; result = globus_ftp_client_put(&handle,dst_url,GLOBUS_NULL,GLOBUS_NULL,callback_function,0 ); if (result != GLOBUS_SUCCESS) { globus_object_t * err; err = globus_error_get(result); globus_libc_printf( "\n ERROR : %s", globus_object_printable_to_string(err));

done = GLOBUS_TRUE; } else { int rc; /* Note : This is where the data movement over the data channel is initiated. Read a buffer, and call register_write. This is an asynch call which returns immediately. When it is finished writing the buffer, it calls the data callback (defined above) which reads another buffer & calls register_write again. The data callback will also indicate hit of eof Note that eof on the data channel does not mean the control channel protocol exchange is complete. This is indicated by the done callback being called.*/ rc = fread(gbuffer, 1, BUFFER_SIZE, file); globus_ftp_client_register_write(&handle,gbuffer,rc,0,feof(file) != 0,data_callback,(void *) file); } /* Lock on condition until the function is completed */ globus_mutex_lock(&lock); while(!done) { /* Atomically release mutex and wait on cond. When the function returns, mutex has been reacquired */ globus_cond_wait(&cond, &lock); } /* Unlock the mutual exclusion lock, mutex, enabling another thread to acquire the mutex */ globus_mutex_unlock(&lock); /*Destroy the ftp client handle */ globus_ftp_client_handle_destroy(&handle); /* Deactivate the modules */ globus_module_deactivate_all(); return 0; } /* data_callback : read or write operation in the FTP Client library is asynchronous.A callback of this type is passed to such data operation function calls. It is called when the user supplied buffer has been successfully transferred to the kernel. Note: That does not mean it has been successfully transmitted,instead it just reads the next block of data and calls register_write/register_read again. static void data_callback(void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err, globus_byte_t * buffer, globus_size_t length, globus_off_t offset, globus_bool_t eof) { if (err) { globus_libc_printf("%s", globus_object_printable_to_string(err)); }

*/

else { if (!eof) { FILE *fd = (FILE *) user_arg; int rc; rc = fread(buffer, 1, BUFFER_SIZE, fd); if (ferror(fd) != 0) { globus_libc_printf("ERROR : function data_callback; errno = %d\n", errno); } /* Register the data buffer to handle a part of the FTP data transfer slight recursive thing going on here */ globus_ftp_client_register_write(handle,buffer,rc,offset + length,feof(fd) != 0, data_callback,(void *) fd); } } /* end of else */ }/*End of data_callback*/

/* callback_function : A pointer to this function is passed to operation function calls to know when the operation is complete.It is called when the transfer is completely finished, i.e. both the data channel and control channel exchange. Here it simply sets a global variable (done) to true so the main program will exit the while loop. */ void callback_function(void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err) { if(err) { globus_libc_printf("\n\t\t ERROR : %s", globus_object_printable_to_string(err)); } else { globus_libc_printf("\n\t\t Status : File Transferred Successfully."); } /* block until the mutual exclusion lock ,mutex is acquired */ globus_mutex_lock(&lock); done = GLOBUS_TRUE; /* signal the specifide condition ,waking up one thread that is suspended on this condition .If no thread are suspended on this condition ,this call will have no effect.*/ globus_cond_signal(&cond); /*Unlock the mutual exclusion lock ,mutex , enabling another thread to acquire the mutex */ globus_mutex_unlock(&lock); return; }

/* Function name : create_datafile(char *src_url,int num) Description : Function to create the data file at the client create_datafile(url,4); Parameters : require the URL and the number of test case. */ int create_datafile(char *src_url,char *msg) { char buffer[BUFFER_SIZE]; time_t ist_time; FILE *file; ist_time = time(GLOBUS_NULL); globus_libc_printf("\n\t\t Generating Data File [%s] globus_libc_ctime_r(&ist_time,&buffer,BUFFER_SIZE); file = fopen(src_url, "w"); if(file == NULL) { globus_libc_printf("\n\t\t Error: Can't open return 1; } fprintf(file," \n Welcome to Grid Workshop GRIPSI fprintf(file," \n File_Name : %s",msg); fprintf(file," \n Note : This file serves as the data "); fprintf(file," \n i.e the program (client_2_server_gridftp.c) transfers "); fprintf(file," \n this file from the client to server using gridftp module. "); fprintf(file,"\n "); fprintf(file,"\n"); fclose(file); globus_libc_printf("\n\t\t Generation of the Data File completed."); return 0; } Usage :

",msg);

%s.\n",src_url); 2007 \n ");

file for File Transfer.

Program 5
Description for implementation of Globus-C program to perform the server to client data transfer .

Objective Write a simple Globus-C program to Transfer the data file from server to client site using Globus GridFTPmodule .

Description The example prepare the source url ( gsiftp://remoteSiteFQDN/fullpathofthefile) and destination url ( Full path of directory to receive) and transfer data file from server to client site and display the status of file transfer.

Output Display the status of the file transfer whether the file transfer is successful / Failed.

Source Code
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "globus_common.h" #include "globus_ftp_client.h" #define #define #define #define #define array_size 300 BUFFER_SIZE 20480 remote_host "parrot.stp.cdac.ernet.in" get_file "/etc/grid-security/grid-mapfile" curr_wr_dir "/tmp/"

globus_mutex_t lock; globus_cond_t cond; globus_bool_t done; char get_outfile[array_size]; void get_file_data_cb(void* ,globus_ftp_client_handle_t* ,globus_object_t* ,globus_byte_t*, globus_size_t ,globus_off_t ,globus_bool_t); int get_file_done_cb(void* ,globus_ftp_client_handle_t* ,globus_object_t* ); int grid_ftp_get_server_file(char *);

int main(int argc, char *argv[]) { char file_path[array_size]; printf("\n\t\t DESCRIPTION : Program to get the file fron the remote server to client site using GridFTP\n"); /* Prepare the url strcpy(file_path, strcat(file_path, strcat(file_path, to get the contents of the file */ "gsiftp://"); remote_host); get_file);

strcpy(get_outfile, curr_wr_dir); strcat(get_outfile,"gridftp-server-client-gridmapfile.txt"); globus_libc_printf("\n\t\t --> Getting the contents of a file %s from %s",get_file,remote_host); printf(" \n\t\t and writting into : %s ",get_outfile); /* Getting the contents of the file from Remote sites*/ grid_ftp_get_server_file(file_path); globus_libc_printf("\n"); return 0; } /* End of main */ /* grid_ftp_get_server_file: This function starts a "get" file transfer from a remote server to client.Prior intialize the FTP handle,set operation attribute, create the handle. GridFTP API returns GLOBUS_SUCCESS/ERROR, If GLOBUS_SUCESS then may begin calling globus_ftp_client_register_read(), inturn returns the final status of the get. After the completion of the get operation destroy the FTP handle */ int grid_ftp_get_server_file(char *url) { globus_ftp_client_handle_t handle; globus_ftp_client_handleattr_t hattr; globus_ftp_client_operationattr_t oattr; globus_byte_t buffer[BUFFER_SIZE]; /* Activate the client module */ if (globus_module_activate(GLOBUS_FTP_CLIENT_MODULE) != GLOBUS_SUCCESS) { globus_libc_printf("\n\t\t ERROR : Failed to activate the FTP Client module\n"); return 1; } /* Initialize the handle attribute */ if (globus_ftp_client_handleattr_init(&hattr) != GLOBUS_SUCCESS) { globus_libc_printf("\n\t\t ERROR : Failed to activate the ftp client handleattr\n"); return 1; } /* Initialize the operation attribute */ if (globus_ftp_client_operationattr_init(&oattr) != GLOBUS_SUCCESS) { globus_libc_printf("\n\t\t ERROR : Failed to initialize

operationattr\n"); return 1; } /* Initalize the handle */ if (globus_ftp_client_handle_init(&handle,&hattr) != GLOBUS_SUCCESS) { globus_libc_printf("\n\t\t ERROR : Failed to initialize the handle\n"); return 1; } done=GLOBUS_FALSE; /* Get a file from an FTP sever */ if (globus_ftp_client_get(&handle,url,&oattr,0,get_file_done_cb,0)!= GLOBUS_SUCCESS) { globus_libc_printf("\n\t\t ERROR : Failed to start file get\n"); done=GLOBUS_TRUE; } else { /* Register a data buffer to handle a part of the FTP data transfer */ globus_ftp_client_register_read(&handle,buffer,BUFFER_SIZE,get_file_data_cb,0); } /* Block until the mutual exclusion lock, mutex, is acquired */ globus_mutex_lock(&lock); while (!done) { /* Atomically release mutex and wait on cond. When the function returns, mutex has been reacquired*/ globus_cond_wait(&cond, &lock); } /* Unlock the mutual exclusion lock, mutex, enabling another thread to acquire the mutex */ globus_mutex_unlock(&lock); /* Destroy the ftp client handle */ globus_ftp_client_handle_destroy(&handle); /* Deactivate the client module */ globus_module_deactivate(GLOBUS_FTP_CLIENT_MODULE); return 0; }

int get_file_done_cb(void* user_arg, globus_ftp_client_handle_t* handle,globus_object_t* err) { char *tmp; if (err != GLOBUS_SUCCESS) { tmp = globus_object_printable_to_string(err); globus_libc_fprintf(stderr,"\n\t\t Error in callback : %s\n",tmp); } else { globus_libc_printf(" \n\t\t Status : File get successful"); }

/*Block until the mutual exclusion lock, mutex, is acquired*/ globus_mutex_lock(&lock); done=GLOBUS_TRUE; /* signal the specifide condition ,waking up one thread that is suspended on this condition .If no thread are suspended on this condition ,this call will have no effect.*/ globus_cond_signal(&cond); /* Unlock the mutual exclusion lock, mutex, enabling another thread to acquire the mutex.*/ globus_mutex_unlock(&lock); return 0; } void get_file_data_cb(void* user_arg ,globus_ftp_client_handle_t* handle , globus_object_t* err , globus_byte_t* buffer_t, globus_size_t length , globus_off_t offset , globus_bool_t eof) { /*Open a file to redirect the data into the file */ FILE *fp; fp=fopen(get_outfile,"w"); fwrite(buffer_t, 1, length,fp); if (!eof ) { /* Register the data buffer to handle a part of the FTP data transfer slight recursive thing going on here */ globus_ftp_client_register_read(&handle, buffer_t, BUFFER_SIZE, get_file_data_cb, 0); } else { printf("\n\t\t Contents of a file in %s \n\t\t are stored in %s",get_file,get_outfile); } }

You might also like