Module gridftpClient
[hide private]
[frames] | no frames]

Source Code for Module gridftpClient

   1  """ 
   2  Simple interface to the Globus GridFTP client API. 
   3  """ 
   4  import sys 
   5  import exceptions 
   6  import types 
   7  import gridftpwrapper 
   8   
9 -class GridFTPClientException(exceptions.Exception):
10 """ 11 A simple subclass of Exception. 12 13 Used for errors in the gridftpClient module. 14 """
15 - def __init__(self, args=None):
16 """ 17 Constructs an instance. 18 19 @type args: string 20 @param args: The string to use as the exception message. 21 22 @rtype: instance 23 @return: an instance of the class 24 """ 25 pass
26
27 -class HandleAttr(object):
28 """ 29 A wrapping of the Globus GridFTP API globus_ftp_client_handleattr_t. 30 """
31 - def __init__(self):
32 """ 33 Constructs an instance. A wrapped pointer to the Globus C type 34 that is created is stored as the ._attr attribute to the 35 instance. 36 37 @rtype: instance 38 @return: an instance of the class 39 40 @raise GridFTPClientException: raised if unable to initialize 41 the Globus C type 42 """ 43 44 self._attr = None 45 46 try: 47 self._attr = gridftpwrapper.gridftp_handleattr_init(); 48 except Exception, e: 49 msg = "Unable to initialize a handle attr: %s" % e 50 ex = GridFTPClientException(msg) 51 raise ex
52
53 - def __del__(self):
54 """ 55 Destroy an instance. The wrapped pointer to the Globus C type 56 is used by globus_free() to free all the memory associated 57 with the Globus C type. 58 59 @rtype: None 60 @return: None 61 62 @raise GridFTPClientException: raised if unable to free the 63 memory associated with the Globus C type 64 """ 65 66 if self._attr: 67 try: 68 gridftpwrapper.gridftp_handleattr_destroy(self._attr) 69 except Exception, e: 70 msg = "Unable to destroy an operation attr: %s" % e 71 ex = GridFTPClientException(msg) 72 raise ex
73
74 - def set_cache_all(self):
75 """ 76 Set the cache all connections attribute for an ftp 77 client handle attribute set. 78 79 This attribute allows the user to cause all control 80 connections to be cached between ftp operations. 81 When this is enabled, the user skips the 82 authentication handshake and connection 83 establishment overhead for multiple subsequent ftp 84 operations to the same server. 85 86 @rtype: None 87 @return: None 88 89 @raise GridFTPClientException: raised if unable to 90 set cache all for the handle attribute. 91 92 """ 93 try: 94 gridftpwrapper.gridftp_handleattr_set_cache_all(self._attr, 1) 95 except Exception, e: 96 msg = "Unable to set cache all for handle attr: %s" % e 97 ex = GridFTPClientException(msg) 98 raise ex
99
100 -class OperationAttr(object):
101 """ 102 A wrapping of the Globus GridFTP API globus_ftp_client_operationattr_t. 103 """
104 - def __init__(self):
105 """ 106 Constructs an instance. A wrapped pointer to the Globus C type 107 that is created is stored as the ._attr attribute to the 108 instance. 109 110 @rtype: instance 111 @return: an instance of the class 112 113 @raise GridFTPClientException: raised if unable to initialize 114 the Globus C type 115 """ 116 117 self._attr = None 118 119 try: 120 self._attr = gridftpwrapper.gridftp_operationattr_init(); 121 except Exception, e: 122 msg = "Unable to initialize an operation attr: %s" % e 123 ex = GridFTPClientException(msg) 124 raise ex
125
126 - def __del__(self):
127 """ 128 Destroy an instance. The wrapped pointer to the Globus C type 129 is used by globus_free() to free all the memory associated 130 with the Globus C type. 131 132 @rtype: None 133 @return: None 134 135 @raise GridFTPClientException: raised if unable to free the 136 memory associated with the Globus C type 137 """ 138 139 if self._attr: 140 try: 141 gridftpwrapper.gridftp_operationattr_destroy(self._attr) 142 except Exception, e: 143 msg = "Unable to destroy an operation attr: %s" % e 144 ex = GridFTPClientException(msg) 145 raise ex
146
147 - def set_mode_extended_block(self):
148 """ 149 Set the file transfer mode attribute for an ftp 150 client attribute set to EXTENDED BLOCK MODE. 151 152 Extended block mode is a file transfer mode where 153 data can be sent over multiple parallel connections 154 and to multiple data storage nodes to provide a 155 high-performance data transfer. In extended block 156 mode, data may arrive out-of-order. ASCII type files 157 are not supported in extended block mode. 158 159 @rtype: None 160 @return: None 161 162 @raise GridFTPClientException: raised if unable to 163 set cache all for the handle attribute. 164 165 """ 166 mode = gridftpwrapper.GLOBUS_FTP_CONTROL_MODE_EXTENDED_BLOCK 167 try: 168 gridftpwrapper.gridftp_operationattr_set_mode(self._attr, mode) 169 except Exception, e: 170 msg = "Unable to set mode to extended block on operation attr: %s" % e 171 ex = GridFTPClientException(msg) 172 raise ex
173
174 - def set_parallelism(self, parallelism):
175 """ 176 Set the parallelism attribute for an ftp client 177 attribute set. 178 179 This attribute allows the user to control the level 180 of parallelism to be used on an extended block mode 181 file transfer. Currently, only a "fixed" parallelism 182 level is supported. This is interpreted by the FTP 183 server as the number of parallel data connections to 184 be allowed for each stripe of data. 185 186 To set the number of parallel channels to be used 187 for a transfer create an instance of the Parallelism 188 class and set the mode and size and then use that 189 instance as the argument to this method. 190 191 @param parallelism: An instance of the Parallelism 192 class prepared with the correct mode and size to 193 represent the number of parallel channels to use. 194 @type parallelism: instance of Parallelism 195 196 @return: None 197 @rtype: None 198 199 @raise GridFTPClientException: raised if unable to 200 set the parallelism 201 """ 202 if not isinstance(parallelism, Parallelism): 203 msg = "Argument must be an instance of class Parallelism" 204 ex = GridFTPClientException(msg) 205 raise ex 206 207 try: 208 gridftpwrapper.gridftp_operationattr_set_parallelism(self._attr, parallelism._parallelism) 209 except Exception, e: 210 msg = "Unable to set parallelism on operation attr: %s" % e 211 ex = GridFTPClientException(msg) 212 raise ex
213
214 - def set_tcp_buffer(self, tcpbuffer):
215 """ 216 Set the TCP buffer attribute for an ftp client attribute set. 217 218 This attribute allows the user to control the TCP 219 buffer size used for all data channels used in a 220 file transfer. 221 222 To set the TCP buffer size for a transfer create an 223 instance of the TCPBuffer class and set the mode and 224 size and then use that instance as the argument to 225 this method. 226 227 @param tcpbuffer: An instance of the TcpBuffer class 228 prepared with the correct mode and size to represent 229 the side of the TCP buffer that should be used for 230 the transfer. 231 @type tcpbuffer: instance of TCPBuffer 232 233 @return: None 234 @rtype: None 235 236 @raise GridFTPClientException: raised if unable to 237 set the parallelism 238 239 """ 240 if not isinstance(tcpbuffer, TcpBuffer): 241 msg = "Argument must be an instance of class TcpBuffer" 242 ex = GridFTPClientException(msg) 243 raise ex 244 245 try: 246 gridftpwrapper.gridftp_operationattr_set_tcp_buffer(self._attr, tcpbuffer._tcpbuffer) 247 except Exception, e: 248 msg = "Unable to set tcpbuffer on operation attr: %s" % e 249 ex = GridFTPClientException(msg) 250 raise ex
251
252 -class Parallelism(object):
253 """ 254 A wrapping of the Globus GridFTP API globus_ftp_control_parallelism_t. 255 """
256 - def __init__(self):
257 """ 258 Constructs an instance. A wrapped pointer to the Globus C type 259 that is created is stored as the ._parallelism attribute to the 260 instance. 261 262 @rtype: instance 263 @return: an instance of the class 264 265 @raise GridFTPClientException: raised if unable to initialize 266 the Globus C type 267 """ 268 self._parallelism = None 269 270 try: 271 self._parallelism = gridftpwrapper.gridftp_parallelism_init() 272 except Exception, e: 273 msg = "Unable to create parallelism object: %s" % e 274 ex = GridFTPClientException(msg) 275 raise ex
276
277 - def __del__(self):
278 """ 279 Destroy an instance. The wrapped pointer to the Globus C type 280 is used by globus_free() to free all the memory associated 281 with the Globus C type. 282 283 @rtype: None 284 @return: None 285 286 @raise GridFTPClientException: raised if unable to free the 287 memory associated with the Globus C type 288 """ 289 if self._parallelism: 290 try: 291 gridftpwrapper.gridftp_parallelism_destroy(self._parallelism) 292 except Exception, e: 293 msg = "Unable to destroy parallelism object: %s" % e 294 ex = GridFTPClientException(msg) 295 raise ex
296
297 - def set_mode_fixed(self):
298 """ 299 Sets the mode of parallelism to "fixed" or 300 GLOBUS_FTP_CONTROL_PARALLELISM_FIXED, which is currently the only 301 mode supported. 302 303 @rtype: None 304 @return: None 305 306 @raise GridFTPClientException: raised if unable to set the mode to 307 fixed. 308 """ 309 try: 310 mode = gridftpwrapper.GLOBUS_FTP_CONTROL_PARALLELISM_FIXED 311 gridftpwrapper.gridftp_parallelism_set_mode(self._parallelism, mode) 312 except Exception, e: 313 msg = "Unable to set mode to fixed: %s" % e 314 ex = GridFTPClientException(msg) 315 raise ex
316
317 - def set_size(self, size):
318 """ 319 Sets the number of parallel data connections to be used. 320 321 @param size: the number of parallel data connections 322 @type size: integer 323 324 @rtype: None 325 @return: None 326 327 @raise GridFTPClientException: raised if unable to set the number 328 of parallel data connections 329 """ 330 try: 331 gridftpwrapper.gridftp_parallelism_set_size(self._parallelism, size) 332 except Exception, e: 333 msg = "Unable to set size to %d for parallel data streams: %s" % (size, e) 334 ex = GridFTPClientException(msg) 335 raise ex
336
337 -class TcpBuffer(object):
338 """ 339 A wrapping of the Globus GridFTP API globus_ftp_control_tcpbuffer_t. 340 """
341 - def __init__(self):
342 """ 343 Constructs an instance. A wrapped pointer to the Globus C type 344 that is created is stored as the ._tcpbuffer attribute to the 345 instance. 346 347 @rtype: instance 348 @return: an instance of the class 349 350 @raise GridFTPClientException: raised if unable to initialize 351 the Globus C type 352 """ 353 self._tcpbuffer = None 354 355 try: 356 self._tcpbuffer = gridftpwrapper.gridftp_tcpbuffer_init() 357 except Exception, e: 358 msg = "Unable to create tcpbuffer object: %s" % e 359 ex = GridFTPClientException(msg) 360 raise ex
361
362 - def __del__(self):
363 """ 364 Destroy an instance. The wrapped pointer to the Globus C type 365 is used by globus_free() to free all the memory associated 366 with the Globus C type. 367 368 @rtype: None 369 @return: None 370 371 @raise GridFTPClientException: raised if unable to free the 372 memory associated with the Globus C type 373 """ 374 if self._tcpbuffer: 375 try: 376 gridftpwrapper.gridftp_tcpbuffer_destroy(self._tcpbuffer) 377 except Exception, e: 378 msg = "Unable to destroy tcpbuffer object: %s" % e 379 ex = GridFTPClientException(msg) 380 raise ex
381
382 - def set_mode_fixed(self):
383 """ 384 Sets the mode of the tcp buffer to "fixed" or 385 GLOBUS_FTP_CONTROL_TCPBUFFER_FIXED. 386 387 @rtype: None 388 @return: None 389 390 @raise GridFTPClientException: raised if unable to set the mode to 391 fixed. 392 """ 393 try: 394 mode = gridftpwrapper.GLOBUS_FTP_CONTROL_TCPBUFFER_FIXED 395 gridftpwrapper.gridftp_tcpbuffer_set_mode(self._tcpbuffer, mode) 396 except Exception, e: 397 msg = "Unable to set mode to fixed: %s" % e 398 ex = GridFTPClientException(msg) 399 raise ex
400 401
402 - def set_size(self, size):
403 """ 404 Sets the size of the tcp buffer to be used for the data connections. 405 406 @param size: the size in bytes for the tcp buffer 407 @type size: integer 408 409 @rtype: None 410 @return: None 411 412 @raise GridFTPClientException: raised if unable to set the number 413 of parallel data connections 414 """ 415 try: 416 gridftpwrapper.gridftp_tcpbuffer_set_size(self._tcpbuffer, size) 417 except Exception, e: 418 msg = "Unable to set size to %d for tcpbuffer: %s" % (size, e) 419 ex = GridFTPClientException(msg) 420 raise ex
421 422
423 -class Buffer(object):
424 """ 425 A wrapping of the Globus API globus_byte_t. 426 """
427 - def __init__(self, size):
428 """ 429 Constructs an instance. A wrapped pointer to the Globus C type 430 that is created is stored as the ._buffer attribute to the 431 instance. 432 433 @rtype: instance 434 @return: an instance of the class 435 436 @raise GridFTPClientException: raised if unable to initialize 437 the Globus C type 438 """ 439 self._buffer = None 440 441 try: 442 self._buffer = gridftpwrapper.gridftp_create_buffer(size) 443 except Exception, e: 444 msg = "Unable to create buffer: %s" % e 445 ex = GridFTPClientException(msg) 446 raise ex 447 448 self.size = size
449
450 - def __del__(self):
451 """ 452 Destroy an instance. The wrapped pointer to the Globus C type 453 is used by globus_free() to free all the memory associated 454 with the Globus C type. 455 456 @rtype: None 457 @return: None 458 459 @raise GridFTPClientException: raised if unable to free the 460 memory associated with the Globus C type 461 """ 462 if self._buffer: 463 try: 464 gridftpwrapper.gridftp_destroy_buffer(self._buffer) 465 except Exception, e: 466 msg = "Unable to destroy buffer: %s" % e 467 ex = GridFTPClientException(msg) 468 raise ex
469
470 - def as_string(self, size):
471 """ 472 Return the contents of a buffer as a Python string of length size. 473 474 @param size: the number of bytes to return 475 @type size: integer 476 477 @return: the contents of the buffer as a Python string 478 @rtype: string 479 480 @raise GridFTPClientException: raised if unable to convert the 481 contents of the buffer as a string 482 """ 483 if self._buffer: 484 try: 485 self.string = gridftpwrapper.gridftp_buffer_to_string(self._buffer, size) 486 except Exception, e: 487 msg = "Unable to convert buffer to string: %s" % e 488 ex = GridFTPClientException(msg) 489 raise ex 490 491 return self.string
492
493 -class PerformanceMarkerPlugin(object):
494 """ 495 A wrapping of the Globus GridFTP API globus_ftp_client_plugin_t for use 496 with the performance marker plugin. 497 """
498 - def __init__(self, beginCB, markerCB, completeCB, arg):
499 """ 500 Constructs an instance. A wrapped pointer to the Globus C type 501 that is created is stored as the ._plugin attribute to the 502 instance. A wrapper pointer to the C struct used to hold 503 pointers to the Python callback functions is also stored 504 as the ._callback attribute. 505 506 The callbacks must have the following structure: 507 508 beginCB 509 ======= 510 def callback(arg, handle, src, dst, restart): 511 - arg: the user argument passed in when plugin is created 512 - handle: the wrapped pointer to the client handle 513 - src: the source URL for the transfer 514 - dst: the destination URL for the transfer 515 - restart: an integer indicating if the transfer has been 516 restarted or not 517 518 markerCB 519 ======== 520 def callback(arg, handle, timestamp, timestamp_tenth, stripe_index, num_stripes, nbytes): 521 - arg: the user argument passed in when plugin is created 522 - handle: the wrapped pointer to the client handle 523 - timestamp: integer indicating at which time the nbytes 524 argument is valid 525 - timestamp_tenth: integer indicating the tenth place for 526 the time at which nbytes argument is valid 527 - stripe_index: the stripe for which the marker is valid 528 (note that stripe is not same as parallel connection) 529 - num_stripes: the number of stripes for this transfer 530 - nbytes: the number of bytes transferred so far 531 532 completeCB 533 ========== 534 def callback(arg, handle, success): 535 - arg: the user argument passed in when plugin is created 536 - handle: the wrapped pointer to the client handle 537 - success: integer indicating if the transfer completed 538 successfully with 0 indicating failure 539 540 @rtype: instance 541 @return: an instance of the class 542 543 @param beginCB: the Python function to call when a transfer begins 544 @type beginCB: callable 545 546 @param markerCB: the Python function to call when a performance 547 marker is received 548 @type markerCB: callable 549 550 @param completeCB: the Python function to call when a transfer 551 completes 552 @type completeCB: callable 553 554 @raise GridFTPClientException: raised if unable to initialize 555 the Globus C type 556 """ 557 558 self._plugin = None 559 self._callback = None 560 561 try: 562 self._plugin, self._callback = gridftpwrapper.gridftp_perf_plugin_init(beginCB, markerCB, completeCB, arg) 563 except Exception, e: 564 msg = "Unable to initialize perf plugin: %s" % e 565 ex = GridFTPClientException(msg) 566 raise ex
567
568 - def __del__(self):
569 """ 570 Destroy an instance. The wrapped pointer to the Globus C type 571 is used by globus_free() to free all the memory associated 572 with the Globus C type. The wrapped pointer to the C struct used to 573 hold pointers to the callback functions is also freed. 574 575 @rtype: None 576 @return: None 577 578 @raise GridFTPClientException: raised if unable to free the 579 memory associated with the Globus C type 580 """ 581 582 if self._plugin and self._callback: 583 try: 584 gridftpwrapper.gridftp_perf_plugin_destroy(self._plugin, self._callback) 585 except Exception, e: 586 msg = "Unable to destroy perf plugin: %s" % e 587 ex = GridFTPClientException(msg)
588 589
590 -class FTPClient(object):
591 """ 592 A class to wrap the GridFTP client functions 593 """ 594
595 - def __init__(self, handleAttr):
596 """ 597 Constructs an instance. A wrapped pointer to the Globus C type 598 globus_ftp_client_handle_t is stored in the ._handle attribute. 599 600 @param handleAttr: instance of the HandleAttr class 601 @type handleAttr: instance of HandleAttr class 602 603 @return: an instance of class GridFTPClient 604 @rtype: instance of class GridFTPClient 605 606 @raise GridFTPClientException: thrown if unable to init the module 607 or open the connection to the server. 608 """ 609 610 self._handleAttr = handleAttr 611 self._handle = None 612 613 # create a handle for this client 614 try: 615 self._handle = gridftpwrapper.gridftp_handle_init(self._handleAttr._attr) 616 except Exception, e: 617 msg = "Unable to create a handle: %s" % e 618 ex = GridFTPClientException(msg) 619 raise ex
620
621 - def __del__(self):
622 """ 623 Destroys an instance. The wrapped pointer to the Globus C type is 624 used by globus_free() to free all the memory associated with the C 625 type. 626 627 @return: None 628 @rtype: None 629 630 @raise GridFTPClientException: thrown if unable to destroy the 631 instance 632 """ 633 634 if self._handle: 635 try: 636 gridftpwrapper.gridftp_handle_destroy(self._handle) 637 except Exception, e: 638 msg = "Unable to destroy client handle: %s" % e 639 ex = GridFTPClientException(msg) 640 raise ex
641
642 - def add_plugin(self, plugin):
643 """ 644 Add a plugin to the handle associated with this instance. 645 646 @param plugin: an instance of a plugin class, currently only the 647 PerformanceMarkerPlugin class is supported 648 @type plugin: instance of PerformanceMarkerPlugin 649 650 @return: None 651 @rtype: None 652 653 @raise GridFTPClientException: thrown if unable to add the plugin 654 to the handle 655 """ 656 if self._handle: 657 try: 658 gridftpwrapper.gridftp_handle_add_plugin(self._handle, plugin._plugin) 659 except Exception, e: 660 msg = "Unable to add plugin: %s" % e 661 ex = GridFTPClientException(msg) 662 raise ex
663
664 - def remove_plugin(self, plugin):
665 """ 666 Remove a plugin from the handle associated with this instance. The 667 plugin must have already been added using the add_plugin() method. 668 669 @param plugin: an instance of a plugin class, currently only the 670 PerformanceMarkerPlugin class is supported 671 @type plugin: instance of PerformanceMarkerPlugin 672 673 @return: None 674 @rtype: None 675 676 @raise GridFTPClientException: thrown if unable to remove the plugin 677 to the handle 678 """ 679 if self._handle: 680 try: 681 gridftpwrapper.gridftp_handle_remove_plugin(self._handle, plugin._plugin) 682 except Exception, e: 683 msg = "Unable to remove plugin: %s" % e 684 ex = GridFTPClientException(msg) 685 raise ex
686
687 - def third_party_transfer(self, src, dst, completeCallback, arg, 688 srcOpAttr = None, dstOpAttr = None, restartMarker = None):
689 """ 690 Initiate a third party transfer between to servers. This function 691 returns immediately. When the transfer is completed or if the 692 transfer is aborted, the completeCallback function will be invoked with the 693 final status of the transfer. 694 695 The completeCallback must have the form: 696 697 def completeCallback(arg, handle, error): 698 - arg is the user argument passed in when the transfer was 699 initiated 700 - handle is the wrapped pointer to the client handle 701 - error is None for success or a string if an error occurred 702 703 @param src: the source URL for the transfer 704 @type src: string 705 706 @param dst: the destination URL for the transfer 707 @type dst: string 708 709 @param completeCallback: the function to call when the transfer is 710 complete 711 @type completeCallback: callable 712 713 @param arg: user argument to pass to the completion callback 714 @type arg: any 715 716 @param srcOpAttr: an instance of OperationAttr for the source 717 @type srcOpAttr: instance of OperationAttr 718 719 @param dstOpAttr: an instance of OperationAttr for the destination 720 @type dstOpAttr: instance of OperationAttr 721 722 @param restartMarker: not currently supported, please pass in None 723 @type restartMarker: None 724 725 @return: None 726 @rtype: None 727 728 @raise GridFTPClientException: raised if unable to initiate the 729 third party transfer 730 """ 731 732 if not srcOpAttr: 733 srcOpAttr = OperationAttr() 734 if not dstOpAttr: 735 dstOpAttr = OperationAttr() 736 737 try: 738 gridftpwrapper.gridftp_third_party_transfer( 739 self._handle, 740 src, 741 srcOpAttr._attr, 742 dst, 743 dstOpAttr._attr, 744 None, 745 completeCallback, 746 arg 747 ) 748 except Exception, e: 749 msg = "Unable to initiate third party transfer: %s" % e 750 ex = GridFTPClientException(msg) 751 raise ex
752
753 - def get(self, url, completeCallback, arg, opAttr = None, marker = None):
754 """ 755 Get a file from an FTP server. 756 757 This function starts a get file transfer from an FTP server. If 758 this function returns without exception then the user may immediately 759 begin calling register_read() to retrieve the data associated with this URL. 760 761 When all of the data associated with this URL is retrieved, and all 762 of the data callbacks have been called, or if the get request is 763 aborted, the completeCallback will be invoked with the final 764 status of the get. 765 766 The completeCallback function must have the form: 767 768 def completeCallback(arg, handle, error): 769 - arg is the user argument passed in when the transfer was 770 initiated 771 - handle is the wrapped pointer to the client handle 772 - error is None for success or a string if an error occurred 773 774 @param url: the source URL to get 775 @type url: string 776 777 @param completeCallback: function to call when the transfer is 778 complete 779 @type completeCallback: callable 780 781 @param arg: user argument to pass to the callback 782 @type arg: any 783 784 @param opAttr: an instance of OperationAttr for the transfer 785 @type opAttr: instance of OperationAttr 786 787 @param marker: not currently supported, please pass in None 788 @type marker: None 789 790 @return: None 791 @rtype: None 792 793 @raise GridFTPClientException: raised if unable to initaite the get 794 operation 795 796 """ 797 if not opAttr: 798 opAttr = OperationAttr() 799 800 try: 801 gridftpwrapper.gridftp_get( 802 self._handle, 803 url, 804 opAttr._attr, 805 None, 806 completeCallback, 807 arg 808 ) 809 except Exception, e: 810 msg = "Unable to initiate get: %s" % e 811 ex = GridFTPClientException(msg) 812 raise ex
813
814 - def register_read(self, buffer, dataCallback, arg):
815 """ 816 Register an instance of class Buffer and the function dataCallback 817 to handle a part of the FTP data transfer. 818 819 The instance of class Buffer will be associated with the current get being 820 performed on this client handle and data will be written into the 821 buffer. The user must then empty the buffer and register another 822 instance for the transfer to proceed. Note that if parallel data 823 channels are used multiple buffers should be registered. 824 825 When the instance of class Buffer is fulled the function 826 dataCallback will be called. 827 828 The dataCallback function must have the form: 829 830 def dataCallback(arg, handle, buffer, length, offset, eof, error): 831 - arg is the user argument passed in when this function is called 832 - handle is the wrapped pointer to the client handle 833 - buffer is the buffer from which the data can be read 834 - length is the number of bytes in the buffer 835 - offset is the offset into the file at which the bytes start 836 - eof is true if this is the end of the file 837 - error is None or a string if there is an error 838 839 @param buffer: instance of class Buffer into which the data will be 840 written 841 @type buffer: instance of class Buffer 842 843 @param dataCallback: function to be called when the instance of 844 Buffer is full 845 @type dataCallback: callable 846 847 @param arg: user argument to pass to the callback function 848 @type arg: any 849 850 @return: None 851 @rtype: None 852 853 @raises GridFTPException: raised if unable to register the buffer 854 and callback for reading 855 856 """ 857 try: 858 gridftpwrapper.gridftp_register_read( 859 self._handle, 860 buffer._buffer, 861 buffer.size, 862 dataCallback, 863 arg 864 ) 865 except Exception, e: 866 msg = "Unable to register read: %s" % e 867 ex = GridFTPClientException(msg) 868 raise ex
869 870
871 - def cksm(self, url, completeCallback, arg, opAttr = None, offset = None, length = None):
872 """ 873 Get a file's checksum from an FTP server. 874 875 This function requests the checksum of a file from an FTP server. 876 877 When the request is completed or aborted, the completeCallback 878 will be invoked with the final status of the operation and the 879 checksum value. 880 881 The completeCallback must have the form: 882 883 def completeCallback(cksm, arg, handle, error): 884 - cksm is the Python string containing the checksum value 885 - arg is the user argument passed in when the call was 886 initiated 887 - handle is the wrapper pointer to the client handle 888 - error is None for success or a string if an error occurred 889 890 @param url: the source URL for the file to be checksummed 891 @type url: string 892 893 @param completeCallback: the function to be called when the checksum 894 operation is complete 895 @type completeCallback: callable 896 897 @param arg: user argument to pass to the callback function 898 @type arg: any 899 900 @param opAttr: an instance of OperationAttr for the source 901 @type opAttr: instance of OperationAttr 902 903 @param offset: the offset in bytes into the file at which to begin computing 904 the checkusm, use None to start at the beginning of the file 905 @type offset: integer 906 907 @param length: the length of the file in bytes to use when 908 computing the checksum, use None to checksum the entire file 909 @type length: integer 910 911 @return: None 912 @rtype: None 913 914 @raise GridFTPClientException: raised if unable to initiate the 915 checksum operation 916 """ 917 918 if not opAttr: 919 opAttr = OperationAttr() 920 if not offset: 921 offset = 0 922 if not length: 923 length = -1 924 925 try: 926 gridftpwrapper.gridftp_cksm(self._handle, url, opAttr._attr, offset, length, completeCallback, arg) 927 except Exception, e: 928 msg = "Unable to cksm: %s" % e 929 ex = GridFTPClientException(msg) 930 raise ex
931
932 - def mkdir(self, url, completeCallback, arg, opAttr = None):
933 """ 934 Make a directory on a server. 935 936 When the request is completed or aborted, the completeCallback 937 will be invoked with the final status of the 938 operation. 939 940 The completeCallback must have the form: 941 942 def completeCallback(arg, handle, error): 943 - arg is the user argument passed in when the call was 944 initiated 945 - handle is the wrapper pointer to the client handle 946 - error is None for success or a string if an error occurred 947 948 @param url: the source URL for the directory to be created 949 @type url: string 950 951 @param completeCallback: the function to be called 952 when the mkdir operation is complete 953 @type completeCallback: callable 954 955 @param arg: user argument to pass to the callback function 956 @type arg: any 957 958 @param opAttr: an instance of OperationAttr for the source 959 @type opAttr: instance of OperationAttr 960 961 @return: None 962 @rtype: None 963 964 @raise GridFTPClientException: raised if unable to initiate the 965 mkdir operation 966 """ 967 968 if not opAttr: 969 opAttr = OperationAttr() 970 971 try: 972 gridftpwrapper.gridftp_mkdir(self._handle, url, opAttr._attr, completeCallback, arg) 973 except Exception, e: 974 msg = "Unable to mkdir: %s" % e 975 ex = GridFTPClientException(msg) 976 raise ex
977
978 - def rmdir(self, url, completeCallback, arg, opAttr = None):
979 """ 980 Remove a directory on a server. 981 982 When the request is completed or aborted, the completeCallback 983 will be invoked with the final status of the 984 operation. 985 986 The completeCallback must have the form: 987 988 def completeCallback(arg, handle, error): 989 - arg is the user argument passed in when the call was 990 initiated 991 - handle is the wrapper pointer to the client handle 992 - error is None for success or a string if an error occurred 993 994 @param url: the source URL for the directory to be removed 995 @type url: string 996 997 @param completeCallback: the function to be called 998 when the mkdir operation is complete 999 @type completeCallback: callable 1000 1001 @param arg: user argument to pass to the callback function 1002 @type arg: any 1003 1004 @param opAttr: an instance of OperationAttr for the source 1005 @type opAttr: instance of OperationAttr 1006 1007 @return: None 1008 @rtype: None 1009 1010 @raise GridFTPClientException: raised if unable to initiate the 1011 mkdir operation 1012 """ 1013 1014 if not opAttr: 1015 opAttr = OperationAttr() 1016 1017 try: 1018 gridftpwrapper.gridftp_rmdir(self._handle, url, opAttr._attr, completeCallback, arg) 1019 except Exception, e: 1020 msg = "Unable to rmdir: %s" % e 1021 ex = GridFTPClientException(msg) 1022 raise ex
1023
1024 - def delete(self, url, completeCallback, arg, opAttr = None):
1025 """ 1026 Delete a file on a server. 1027 1028 When the request is completed or aborted, the completeCallback 1029 will be invoked with the final status of the 1030 operation. 1031 1032 The completeCallback must have the form: 1033 1034 def completeCallback(arg, handle, error): 1035 - arg is the user argument passed in when the call was 1036 initiated 1037 - handle is the wrapper pointer to the client handle 1038 - error is None for success or a string if an error occurred 1039 1040 @param url: the source URL for the file to be deleted 1041 @type url: string 1042 1043 @param completeCallback: the function to be called 1044 when the mkdir operation is complete 1045 @type completeCallback: callable 1046 1047 @param arg: user argument to pass to the callback function 1048 @type arg: any 1049 1050 @param opAttr: an instance of OperationAttr for the source 1051 @type opAttr: instance of OperationAttr 1052 1053 @return: None 1054 @rtype: None 1055 1056 @raise GridFTPClientException: raised if unable to initiate the 1057 delete operation 1058 """ 1059 1060 if not opAttr: 1061 opAttr = OperationAttr() 1062 1063 try: 1064 gridftpwrapper.gridftp_delete(self._handle, url, opAttr._attr, completeCallback, arg) 1065 except Exception, e: 1066 msg = "Unable to delete: %s" % e 1067 ex = GridFTPClientException(msg) 1068 raise ex
1069
1070 - def move(self, src, dst, completeCallback, arg, opAttr = None):
1071 """ 1072 Move or rename a file on a server. 1073 1074 When the request is completed or aborted, the completeCallback 1075 will be invoked with the final status of the 1076 operation. 1077 1078 The completeCallback must have the form: 1079 1080 def completeCallback(arg, handle, error): 1081 - arg is the user argument passed in when the call was 1082 initiated 1083 - handle is the wrapper pointer to the client handle 1084 - error is None for success or a string if an error occurred 1085 1086 @param src: the source URL for the file to be moved 1087 @type src: string 1088 1089 @param dst: the destination URL for the file to be moved 1090 @type dst: string 1091 1092 @param completeCallback: the function to be called 1093 when the mkdir operation is complete 1094 @type completeCallback: callable 1095 1096 @param arg: user argument to pass to the callback function 1097 @type arg: any 1098 1099 @param opAttr: an instance of OperationAttr for the source 1100 @type opAttr: instance of OperationAttr 1101 1102 @return: None 1103 @rtype: None 1104 1105 @raise GridFTPClientException: raised if unable to initiate the 1106 delete operation 1107 """ 1108 1109 if not opAttr: 1110 opAttr = OperationAttr() 1111 1112 try: 1113 gridftpwrapper.gridftp_move(self._handle, src, dst, opAttr._attr, completeCallback, arg) 1114 except Exception, e: 1115 msg = "Unable to move: %s" % e 1116 ex = GridFTPClientException(msg) 1117 raise ex
1118
1119 - def chmod(self, url, mode, completeCallback, arg, opAttr = None):
1120 """ 1121 Change the mode of a file on a server. 1122 1123 When the request is completed or aborted, the completeCallback 1124 will be invoked with the final status of the 1125 operation. 1126 1127 The completeCallback must have the form: 1128 1129 def completeCallback(arg, handle, error): 1130 - arg is the user argument passed in when the call was 1131 initiated 1132 - handle is the wrapper pointer to the client handle 1133 - error is None for success or a string if an error occurred 1134 1135 @param url: the source URL for the file 1136 @type url: string 1137 1138 @param mode: the integer file mode, be sure to use 4 1139 digits, for example 0644 instead of 644. 1140 @type mode: integer 1141 1142 @param completeCallback: the function to be called 1143 when the mkdir operation is complete 1144 @type completeCallback: callable 1145 1146 @param arg: user argument to pass to the callback function 1147 @type arg: any 1148 1149 @param opAttr: an instance of OperationAttr for the source 1150 @type opAttr: instance of OperationAttr 1151 1152 @return: None 1153 @rtype: None 1154 1155 @raise GridFTPClientException: raised if unable to initiate the 1156 delete operation 1157 """ 1158 1159 if not opAttr: 1160 opAttr = OperationAttr() 1161 1162 try: 1163 gridftpwrapper.gridftp_chmod(self._handle, url, mode, opAttr._attr, completeCallback, arg) 1164 except Exception, e: 1165 msg = "Unable to chmod: %s" % e 1166 ex = GridFTPClientException(msg) 1167 raise ex
1168
1169 - def verbose_list(self, url, completeCallback, arg, opAttr = None):
1170 """ 1171 Get a file listing from a FTP server. 1172 1173 This function starts a verbose file listing from an FTP server. If 1174 this function returns without exception then the user may immediately 1175 begin calling register_read() to retrieve the data associated with this 1176 operation. 1177 1178 When all of the data associated with this URL is retrieved, and all 1179 of the data callbacks have been called, or if the verbose list request is 1180 aborted, the completeCallback will be invoked with the final 1181 status of the get. 1182 1183 The completeCallback function must have the form: 1184 1185 def completeCallback(arg, handle, error): 1186 - arg is the user argument passed in when the transfer was 1187 initiated 1188 - handle is the wrapped pointer to the client handle 1189 - error is None for success or a string if an error occurred 1190 1191 @param url: the source URL from which to get the file listing 1192 @type url: string 1193 1194 @param completeCallback: function to call when the listing is 1195 complete 1196 @type completeCallback: callable 1197 1198 @param arg: user argument to pass to the callback 1199 @type arg: any 1200 1201 @param opAttr: an instance of OperationAttr for the transfer 1202 @type opAttr: instance of OperationAttr 1203 1204 @return: None 1205 @rtype: None 1206 1207 @raise GridFTPClientException: raised if unable to initiate the verbose 1208 list operation 1209 1210 """ 1211 if not opAttr: 1212 opAttr = OperationAttr() 1213 1214 try: 1215 gridftpwrapper.gridftp_verbose_list( 1216 self._handle, 1217 url, 1218 opAttr._attr, 1219 completeCallback, 1220 arg 1221 ) 1222 except Exception, e: 1223 msg = "Unable to initiate verbose list: %s" % e 1224 ex = GridFTPClientException(msg) 1225 raise ex
1226 1227
1228 - def abort(self):
1229 """ 1230 Abort the operation currently in progress. 1231 1232 @return: None 1233 @rtype: None 1234 1235 @raise GridFTPClientException: raised if unable to initiate the 1236 abort operation 1237 """ 1238 1239 if self._handle: 1240 try: 1241 gridftpwrapper.gridftp_abort(self._handle) 1242 except Exception, e: 1243 msg = "Unable to abort: %s" % e 1244 ex = GridFTPClientException(msg) 1245 raise ex
1246