def download(self, localfile: str, remotefile: str, overwrite: bool = True, **kwargs):
valid = self._sb.file_info(remotefile, quiet = True)<EOL>if valid is None:<EOL><INDENT>return {'<STR_LIT>' : False, <EOL>'<STR_LIT>'     : "<STR_LIT>"+str(remotefile)+"<STR_LIT>"}<EOL><DEDENT>if valid == {}:<EOL><INDENT>return {'<STR_LIT>' : False, <EOL>'<STR_LIT>'     : "<STR_LIT>"+str(remotefile)+"<STR_LIT>"}<EOL><DEDENT>if os.path.isdir(localfile):<EOL><INDENT>locf = localfile + os.sep + remotefile.rpartition(self._sb.hostsep)[<NUM_LIT:2>]<EOL><DEDENT>else:<EOL><INDENT>locf = localfile<EOL><DEDENT>try:<EOL><INDENT>fd = open(locf, '<STR_LIT:wb>')<EOL><DEDENT>except OSError as e:<EOL><INDENT>return {'<STR_LIT>' : False, <EOL>'<STR_LIT>'     : "<STR_LIT>"+str(locf)+"<STR_LIT>"+str(e)}<EOL><DEDENT>port =  kwargs.get('<STR_LIT:port>', <NUM_LIT:0>)<EOL>if port==<NUM_LIT:0> and self.sascfg.tunnel:<EOL><INDENT>port = self.sascfg.tunnel<EOL><DEDENT>try:<EOL><INDENT>sock = socks.socket()<EOL>if self.sascfg.tunnel:<EOL><INDENT>sock.bind(('<STR_LIT:localhost>', port))<EOL><DEDENT>else:<EOL><INDENT>sock.bind(('<STR_LIT>', port))<EOL><DEDENT>port = sock.getsockname()[<NUM_LIT:1>]<EOL><DEDENT>except OSError:<EOL><INDENT>return {'<STR_LIT>' : False, <EOL>'<STR_LIT>'     : "<STR_LIT>"}<EOL><DEDENT>if self.sascfg.ssh:<EOL><INDENT>if not self.sascfg.tunnel:<EOL><INDENT>host = self.sascfg.hostip <EOL><DEDENT>else:<EOL><INDENT>host = '<STR_LIT:localhost>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>host = '<STR_LIT>'<EOL><DEDENT>code = """<STR_LIT>"""+remotefile+"""<STR_LIT>"""+host+"""<STR_LIT::>"""+str(port)+"""<STR_LIT>"""<EOL>sock.listen(<NUM_LIT:1>)<EOL>self._asubmit(code, '<STR_LIT:text>')<EOL>datar = b'<STR_LIT>'<EOL>newsock = (<NUM_LIT:0>,<NUM_LIT:0>)<EOL>try:<EOL><INDENT>newsock = sock.accept()<EOL>while True:<EOL><INDENT>data = newsock[<NUM_LIT:0>].recv(<NUM_LIT>)<EOL>if len(data):<EOL><INDENT>datar += data<EOL><DEDENT>else:<EOL><INDENT>if len(datar):<EOL><INDENT>fd.write(datar)<EOL><DEDENT>break<EOL><DEDENT>if len(datar) > <NUM_LIT>:<EOL><INDENT>fd.write(datar[:<NUM_LIT>])<EOL>datar = datar[<NUM_LIT>:]<EOL><DEDENT><DEDENT><DEDENT>except:<EOL><INDENT>if newsock[<NUM_LIT:0>]:<EOL><INDENT>newsock[<NUM_LIT:0>].shutdown(socks.SHUT_RDWR)<EOL>newsock[<NUM_LIT:0>].close()<EOL><DEDENT>sock.close()<EOL>fd.close()<EOL>ll = self.submit("<STR_LIT>", '<STR_LIT:text>')<EOL>return {'<STR_LIT>' : False, <EOL>'<STR_LIT>'     : "<STR_LIT>"+ll['<STR_LIT>']}<EOL><DEDENT>newsock[<NUM_LIT:0>].shutdown(socks.SHUT_RDWR)<EOL>newsock[<NUM_LIT:0>].close()<EOL>sock.close()<EOL>fd.flush()<EOL>fd.close()<EOL>ll = self.submit("<STR_LIT>", '<STR_LIT:text>')<EOL>return {'<STR_LIT>' : True, <EOL>'<STR_LIT>'     : ll['<STR_LIT>']}<EOL>
This method downloads a remote file from the SAS servers file system.
localfile  - path to the local file to create or overwrite
remotefile - path to remote file tp dpwnload
overwrite  - overwrite the output file if it exists?