ARC SDK
Copy File

C++

#include <arc/Logger.h>
#include <arc/URL.h>
#include <arc/UserConfig.h>
#include <arc/data/DataHandle.h>
#include <arc/data/DataMover.h>
int main(int argc, char** argv) {
// Set up logging to stderr with level VERBOSE (a lot of output will be shown)
Arc::LogStream logcerr(std::cerr);
logcerr.setFormat(Arc::ShortFormat);
if (argc != 3) {
logger.msg(Arc::ERROR, "Usage: copy source destination");
return 1;
}
// Set up source and destination objects
Arc::UserConfig usercfg;
Arc::URL src_url(argv[1]);
Arc::URL dest_url(argv[2]);
Arc::DataHandle src_handle(src_url, usercfg);
Arc::DataHandle dest_handle(dest_url, usercfg);
// Transfer should be insecure by default (most servers don't support encryption)
// and passive if the client is behind a firewall
mover.secure(false);
mover.passive(true);
// If caching and URL mapping are not necessary default constructed objects can be used
// Call DataMover to do the transfer
Arc::DataStatus result = mover.Transfer(*src_handle, *dest_handle, cache, map);
if (!result.Passed()) {
logger.msg(Arc::ERROR, "Copy failed: %s", std::string(result));
return 1;
}
return 0;
}

Python

1 #!/usr/bin/env python
2 
3 import sys
4 import arc
5 
6 # Copies a file from source to destination
7 
8 # Wait for all the background threads to exit before exiting
9 import atexit
10 @atexit.register
11 def wait_exit():
12  arc.ThreadInitializer().waitExit()
13 
14 def usage():
15  print(' Usage: copy_file.py source destination')
16 
17 if len(sys.argv) != 3:
18  usage()
19  sys.exit(1)
20 
21 # Logging to stdout
22 root_logger = arc.Logger_getRootLogger()
23 stream = arc.LogStream(sys.stdout)
24 root_logger.addDestination(stream)
25 # Set threshold to VERBOSE or DEBUG for more information
26 root_logger.setThreshold(arc.ERROR)
27 
28 # User configuration - paths to proxy certificates etc can be set here
29 # With no arguments default values are used
30 cfg = arc.UserConfig()
31 
32 # Convert the arguments to DataPoint objects
33 source = arc.datapoint_from_url(sys.argv[1], cfg)
34 if source is None:
35  root_logger.msg(arc.ERROR, "Can't handle source "+sys.argv[1])
36  sys.exit(1)
37 
38 destination = arc.datapoint_from_url(sys.argv[2], cfg)
39 if destination is None:
40  root_logger.msg(arc.ERROR, "Can't handle destination "+sys.argv[2])
41  sys.exit(1)
42 
43 # DataMover does the transfer
44 mover = arc.DataMover()
45 # Show transfer progress
46 mover.verbose(True)
47 # Don't attempt to retry on error
48 mover.retry(False)
49 # Do the transfer
50 status = mover.Transfer(source, destination, arc.FileCache(), arc.URLMap())
51 
52 # Print the exit status of the transfer
53 print (str(status))