This package provides some simple routines to read, move, copy, and delete files as references by string URLs, URI objects or URIs embedded in HTTP::Reqeust or LWP::Request objects. All subroutines in this package that expect a URI will accept a string, a URI object, or a HTTP::Reqeust or LWP::Request with an embedded URI. If passed a HTTP::Request or LWP::Request, then the method of the object is ignored and the proper method will be used to either GET or PUT the requested UIR.

The distinction between files and directories in a URI is tested by looking for a trailing / in the path. If a trailing / exists, then the URI is considered to point to a directory, otherwise it is a file.

All of the following subroutines are exported to the users namespace automatically. If you do not want this, then require this package instead of useing it.

The get_urls function will fetch the documents identified by the given URIs and returns a list of HTTP::Responses. You can test if the GET succeeded by using the HTTP::Responseis_success method. If is_success returns 1, then use the content method to get the contents of the GET.

Get_urls performs the GETs in parallel to speed execution and should be faster than performing individual gets.

Put the contents of string or the return from &coderef() into the listed uris. The destination uris must be either ftp: or file: and must specify a complete file; no directories are allowed. If the first form is used with string then the contents of string will be sent. If the second form is used, then coderef is a reference to a subroutine or anonymous CODE and &coderef() will be called repeatedly until it returns '' or undef and all of the text it returns will be stored in the uris.

Upon return, put_urls returns an array, where each element contains a HTTP::Response object corresponding to the success or failure of transferring the data to the i-th uri. This object can be tested for the success or failure of the PUT by using the is_success method on the element. If the PUT was not successful, then the message method may be used to gather an error message explaining why the PUT failed. If there is invalid input to put_urls then put_urls returns an empty list in a list context, an undefined value in a scalar context, or nothing in a void context, and $@ contains a message containing explaining the invalid input.

For example, the following code, prints either YES or NO and a failure message if the put failed.

Copy the content contained in the URI uri_from to the location specified by the URI uri_to. uri_from must contain the complete path to a file; no directories are allowed. uri_to must be a file: or ftp: URI and may either be a directory or a file.

If supplied, base may be used to convert uri_from and uri_to from relative URIs to absolute URIs.

On return, copy_url returns 1 on success, 0 on otherwise. On failure $@ contains a message explaining the failure. See copy_urls if you want to quickly copy a single file to multiple places or copy multiple files to one directory or both. copy_urls provides simultaneous file transfers and will do the task much faster than calling copy_url many times over. If invalid input is given to copy_url, then it returns an empty list in a list context, an undefined value in a scalar context, or nothing in a void context and $@ contains a message explaining the invalid input.

Copy the content contained at the specified URIs to other locations also specified by URIs. The first argument to copy_urls is either a single URI or a reference to an array of URIs to copy. All of these URIs must contain the complete path to a file; no directories are allowed. The second argument may be a single URI or a reference to an array of URIS. If any of the destination URIs are a location of a file and not a directory, then only one URI can be passed as the first argument. If a reference to an array of URIs is passed as the second argument, then all URIs must point to directories, not files. Only file: and ftp: URIs may be used as the destination of the copy.

If supplied, base may be used to convert relative URIs to absolute URIs for all URIs supplied to copy_urls.

The copy operations of the multiple URIs are done in parallel to speed execution.

On return copy_urls returns a list of the LWP::Response from each GET performed on the from URIs. If there is invalid input to copy_urls then copy_urls returns an empty list in a list context, an undefined value in a scalar context, or nothing in a void context and contains $@ a message explaining the error. The success or failure of each GET may be tested by using is_success method on each element of the list. If the GET succeeded (is_success returns TRUE), then hash element 'put_requests' exists and is a reference to a list of LWP::Responses containing the response to the PUT. For example, the following code prints a message containing the results from copy_urls:

Delete the files located by the uris and return a HTTP::Response for each uri. If the uri was successfully deleted, then the is_success method returns 1, otherwise it returns 0 and the message method contains the reason for the failure.

Move the contents of the from_uri URI to the to_uri URI. If base is supplied, then the from_uri and to_uri URIs are converted from relative URIs to absolute URIs using base. If the move was successful, then move_url returns 1, otherwise it returns 0 and $@ contains a message explaining why the move failed. If invalid input was given to move_url then it returns an empty list in a list context, an undefined value in a scalar context, or nothing in a void context and $@ contains a message explaining the invalid input.

Return a list containing the filenames in the directory located at uri. Only file and FTP directory URIs currently work. If for any reason the list can not be obtained, then list_url returns an empty list in a list context, an undefined value in a scalar context, or nothing in a void context and $@ contains a message why list_url failed.