Program 1,2,3,4,5

download Program 1,2,3,4,5

of 19

Transcript of Program 1,2,3,4,5

  • 7/31/2019 Program 1,2,3,4,5

    1/19

    Program 1

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

    Proxy"

    ObjectiveWrite a simple Globus-C program to verify the "Grid Proxy " using Globus C

    APIs.

    DescriptionCheck the validity of Grid Proxy.

    OutputDisplay the validity of Grid Proxy and prints the time left for the validity for

    the proxy.

    Source Code

    #include #include #include

    #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,intstate,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 jobto remote site ..");

  • 7/31/2019 Program 1,2,3,4,5

    2/19

    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-job-stderr.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-job-stdout.txt) and ");

    globus_libc_printf("\n\t\t the Error File (gram-simple-job-stderr.txt) of the job are");

    globus_libc_printf("\n\t\t stored at working directory defined inthe 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 theMonitor to prevent anything else from changing the value ofMonitor.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 */

  • 7/31/2019 Program 1,2,3,4,5

    3/19

    globus_mutex_unlock(&Monitor.mutex);/* Setting up the communications port for returning the callback.

    The callback_contact is the callback identifier returned by thefunction */

    globus_gram_client_callback_allow(callback_func,(void *) &Monitor,&callback_contact);

    /* Send the GRAM request. The rm_contact, rsl, andjob_state_mask were set up. The callback_contact wasjust 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,intstate,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 ");

  • 7/31/2019 Program 1,2,3,4,5

    4/19

    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() */

  • 7/31/2019 Program 1,2,3,4,5

    5/19

    Program 2

    Description for implementation of Globus-C program to perform the "GRAM

    Authentication".

    ObjectiveWrite a simple Globus-C program to perform the "GRAM Authentication " with

    remote site using Globus C APIs.

    DescriptionThe example takes the remote site FQDN as input from and performs the

    GRAM authentication with remote site and display the status of"GRAM

    Authentication".

    OutputDisplay the status of"GRAM Authentication" with each remote site.

    Source Code

    #include #include #include #include "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\tbetween client and server. ");

    /* Check for the arguments */if(argc != 2){ printf("\n\t ERROR : Invalid Argumetns. ");printf("\n\t Usage : \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);

  • 7/31/2019 Program 1,2,3,4,5

    6/19

    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 rujobs.",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;

    }

  • 7/31/2019 Program 1,2,3,4,5

    7/19

    Program 3

    Description for implementation of Globus-C program to submit a simple job to

    remote site.

    ObjectiveWrite a simple Globus-C program to submit job/bin/hostname to remote site

    and get the status of the job usingGRAMmodule .

    DescriptionThe 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 errorfiles are stored in the/tmp i> directory of the remote site.

    OutputDisplay the status of the job execution.

    Source Code#include #include #include

    #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,intstate,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 jobto remote site ..");

  • 7/31/2019 Program 1,2,3,4,5

    8/19

  • 7/31/2019 Program 1,2,3,4,5

    9/19

    /* 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, andjob_state_mask were set up. The callback_contact wasjust 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 calledfrom 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;

  • 7/31/2019 Program 1,2,3,4,5

    10/19

    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() */

  • 7/31/2019 Program 1,2,3,4,5

    11/19

    Program 4

    Description for implementation of Globus-C program to perform

    the clientto serverdata transfer .

    ObjectiveWrite a simple Globus-C program to transfer the data file from clientto

    each serverusing Globus GridFTPmodule .

    DescriptionThe example prepares source url ( Full path of the file to be transferred) and

    destination url (gsiftp://remoteSiteFQDN/fullpathforrecievingthefile) and

    transfer the data file from clientsite to remote site and display the status of file

    transfer.

    OutputDisplay the status of the file transfer.

    Source Code

    #include #include

    #include

    #include "globus_common.h"#include "globus_ftp_client.h"

    #define array_size 300#define BUFFER_SIZE 20480#define src "/tmp/gridftp_client_server_file_transfer.txt"#define 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

  • 7/31/2019 Program 1,2,3,4,5

    12/19

    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 thetransfer.");

    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 ClientModule\n ");

    return 1;}

    globus_ftp_client_handle_init(&handle, GLOBUS_NULL);

    /* globus_ftp_client_put starts the protocol exchange on the control channelNote : 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));

  • 7/31/2019 Program 1,2,3,4,5

    13/19

    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 whichreturns immediately. When it is finished writing the buffer, it callsthe data callback (defined above) which reads another buffer & calls

    register_write again. The data callback will also indicate hit of eofNote that eof on the data channel does not mean the control channelprotocol exchange is complete. This is indicated by the done callbackbeing 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 acquirethe 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 libraryis asynchronous.A callback of this type is passedto such data operation function calls. It is calledwhen the user supplied buffer has been successfullytransferred to the kernel.

    Note: That does not mean it has been successfully transmitted,insteadit just reads the next block of data and callsregister_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));}

  • 7/31/2019 Program 1,2,3,4,5

    14/19

    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 datatransfer

    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 calledwhen the transfer is completely finished, i.e. both thedata channel and control channel exchange. Here it simplysets a global variable (done) to true so the main programwill 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 onthis

    condition .If no thread are suspended on this condition ,this call willhave noeffect.*/

    globus_cond_signal(&cond);

    /*Unlock the mutual exclusion lock ,mutex , enabling another thread toacquire the mutex */

    globus_mutex_unlock(&lock);return;

    }

  • 7/31/2019 Program 1,2,3,4,5

    15/19

    /*Function name : create_datafile(char *src_url,int num)Description : Function to create the data file at the client Usage :

    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] ",msg);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 %s.\n",src_url);return 1;}

    fprintf(file," \n Welcome to Grid Workshop GRIPSI 2007 \n ");

    fprintf(file," \n File_Name : %s",msg);fprintf(file," \n Note : This file serves as the data file for File Transfer.");

    fprintf(file," \n i.e the program (client_2_server_gridftp.c)transfers ");

    fprintf(file," \n this file from the client to server using gridftpmodule. ");

    fprintf(file,"\n ");fprintf(file,"\n");fclose(file);globus_libc_printf("\n\t\t Generation of the Data File completed.");return 0;}

  • 7/31/2019 Program 1,2,3,4,5

    16/19

    Program 5

    Description for implementation of Globus-C program to perform

    the serverto clientdata transfer .

    ObjectiveWrite a simple Globus-C program to Transfer the data file

    from serverto clientsite using Globus GridFTPmodule .

    DescriptionThe example prepare the source url (

    gsiftp://remoteSiteFQDN/fullpathofthefile) and destination url ( Full path of

    directory to receive) and transfer data file from serverto clientsite and display

    the status of file transfer.

    OutputDisplay the status of the file transfer whether the file transfer is successful /

    Failed.

    Source Code

    #include #include #include

    #include "globus_common.h"#include "globus_ftp_client.h"

    #define array_size 300#define BUFFER_SIZE 20480#define remote_host "parrot.stp.cdac.ernet.in"#define get_file "/etc/grid-security/grid-mapfile"#define 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 *);

  • 7/31/2019 Program 1,2,3,4,5

    17/19

    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 toclient site using GridFTP\n");

    /* Prepare the url to get the contents of the file */

    strcpy(file_path, "gsiftp://");strcat(file_path, remote_host);strcat(file_path, 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 serverto client.Prior intialize the FTP handle,set operation attribute,create the handle. GridFTP API returns GLOBUS_SUCCESS/ERROR,If GLOBUS_SUCESS then may begin callingglobus_ftp_client_register_read(), inturn returns the finalstatus of the get. After the completion of the get operationdestroy 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 Clientmodule\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 clienthandleattr\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

  • 7/31/2019 Program 1,2,3,4,5

    18/19

    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 thefunction 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");}

  • 7/31/2019 Program 1,2,3,4,5

    19/19

    /*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 onthis

    condition .If no thread are suspended on this condition ,this call willhave no

    effect.*/globus_cond_signal(&cond);

    /* Unlock the mutual exclusion lock, mutex, enablinganother 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);

    }}