#!/usr/bin/env python
################################################################################
#\defgroup difxsendfile DiFXsendFile
#
#\brief Send data to a file location on the server.
#
# Usage: DiFXsendFile [args] [source path] \
#
# DiFXsendFile sends data to a specified path destination on the DiFX
# server. If two path names are given as arguments the first is assumed to
# be the full path of a local file from which data will be read, and the second
# is assumed to be its destination on the server. If one path name is given
# as an argument it is interpreted as the destination and data are expected
# from stdin.
#
#
Command Line Arguments
#
#
# -h, --help | Print help information and quit.
# |
-H, --hostname NAME | Use NAME as the host of the difxServer program.
# Default is to use DIFX_CONTROL_HOST environment variable.
# |
-P, --port PORT | Use PORT as the TCP port to communicated with the difxServer.
# Default is to use DIFX_CONTROL_PORT environment variable.
# |
" % ( sys.argv[0] ))
print("")
print("Options can include:")
print("")
print(" --help")
print(" -h Print this help information and quit.")
print("")
print(" --hostname NAME")
print(" -H NAME Use NAME as the host of the difxServer program.")
print(" Default is to use DIFX_CONTROL_HOST environment variable.")
print("")
print(" --port PORT")
print(" -P PORT Use PORT as the TCP port to communicated with the difxServer.")
print(" Default is to use DIFX_CONTROL_PORT environment variable.")
print("")
exit( 0 )
elif sys.argv[i] in [ "-H", "--hostname" ]:
host = sys.argv[i+1]
i = i + 1
elif sys.argv[i] in [ "-D", "--difx" ]:
DiFXVersion = sys.argv[i+1]
i = i + 1
elif sys.argv[i] in [ "-P", "--port" ]:
port = int( sys.argv[i+1] )
i = i + 1
else:
# There may only be a destination, or there might be a source and a
# destination. We'll sort that out below.
if source == None:
source = sys.argv[i]
else:
destination = sys.argv[i]
i = i + 1
except RuntimeError:
print("Usage: %s [options] [source] " % ( sys.argv[0] ))
exit( 0 )
# If only one path was specified, it is a destination - so we have to fix our
# interpretation of the command line and read data from stdin.
if destination == None:
destination = source
data = sys.stdin.read()
else:
f = open( source, "r" )
data = f.read()
# Open a new connection to the difxServer...
difx = DiFXFileTransfer.Client()
difx.connect( host, port )
if difx.socketOK:
difx.monitor()
fileSize = difx.sendFile( destination, data )
print("wrote " + str( fileSize ) + " bytes")
difx.close()