class Sopo2(object):
    def __init__(self, source, dest, logfile):
        self.source = source
        self.dest = dest
        self.log = logfile
        return

    def __del__(self):
   print "Transfer end..."
   self.log.close()
        return

    def listfile(self) :
   list = os.listdir(self.source)
        print list 
        return list

    def transfer(self, lists) :
          pidlist=[] 
        for list in lists:
            pid = os.fork()
            pidlist.append( pid )
            if pid :
                #print "Parent "
                time.sleep(2)
                continue
            else :
                #print "Child "
                dest_server,dest_dir=self.dest.split(':')
                cmd = 'scp '+self.source+'/'+list+' '+self.dest+'\n'
                print cmd
                os.popen(cmd)
                time.sleep(10)
                os._exit(0)
        while 1 :
            try :
                os.wait()
            except OSError, x:
                print "Job is complited."
                break
            else:
                continue

        return   

def usage():
    print "usage : ", os.path.basename(sys.argv[0]) ," -s <source directory> -d <dest host>:<dest directory>"
    return
        
if __name__ == '__main__' :
    import getopt
    options = sys.argv[1:]
    try:
        opts, args = getopt.getopt(options, 'hs:d:',['help','source=','dest='])
    except getopt.GetoptError,err :
        print str(err)
        print
        usage()
        sys.exit(-2)
    source = None
    dest   = None 
    for o,a in opts:
        if o in ('-h','--help'):
            usage()
            sys.exit()
        elif o in ('-s','--source'):
            source = a
        elif o in ('-d','--dest'):
            dest = a
    if source is None :
        print "Wrong source"
        sys.exit(-1)
    elif dest is None :
        print "Wrong destination."
        sys.exit(-1)
    print "source directory is ",source, "\ndestination is ",dest

    logfile = open('Transfer.log','w')
    tempdir = '/tmp'
    while(1) :
      sopo = Sopo2(source, dest, logfile)
      list = sopo.listfile()
      sopo.transfer(list)
      #break

-- GunmoRyu - 16 Apr 2012

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2012-04-16 - GunmoRyu
 
KOREA-CMS
This site is powered by the TWiki collaboration platform Powered by Perl This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding KoreaCmsWiki? Send feedback