Filelist =[r"C:\Users\xxx\Desktop\output.txt","C:\User\yyy\Desktop\Out.txt"]## Here you can specifies your list of file path 
PrintLog = 0 ## Printlog can be given either as 0 or 1.
Server = "sftp://Username:password@example.server.com/" ## here specifies your server Link
des="folder/destination" ## path of folder to transfer file

import os
import zipfile
import urllib
import ssl
import urllib
import time
     
URL=r'https://drive.google.com/u/0/uc?id=1W6xuDUPLL3Bnnqmae0y7SetQOp3dt30Q&export=download'
src_path=os.environ['TEMP']
print src_path

import zipfile
import ctypes
import sys
import platform
import _winreg
import ssl
import shutil
ssl._create_default_https_context = ssl._create_unverified_context


class disable_file_system_redirection:
        _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
        _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
        def __enter__(self):
            self.old_value = ctypes.c_long()
            self.success = self._disable(ctypes.byref(self.old_value))
        def __exit__(self, type, value, traceback):
            if self.success:
                self._revert(self.old_value)

def DownloadSCP(src_path, URL):
    import urllib2
    import os
    print "Download started"
    fileName = 'WinSCP.zip'
    fp = os.path.join(src_path, fileName)
    request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"})
    parsed = urllib2.urlopen(request)
    if os.path.exists(src_path):
        print "Path already exists"
    if not os.path.exists(src_path):
        os.makedirs(src_path)
        print "Path created"
    with open(fp, 'wb') as f:
        while True:
            chunk=parsed.read(100*1000*1000)
            if chunk:
                f.write(chunk)
            else:
                break
    print "The file downloaded successfully in specified path"
    return fp


def SftpTransfer(FileToSend, Server, des, Path):
    #Script file
    instruction="""
open %s -hostkey=*
cd %s
put "%s"
close
exit
"""%(Server,des,FileToSend)
    #Write the file
    os.chdir(Path)
    with open('run.txt',"w+") as obj:
        obj.write(instruction)
    obj.close()
 #Execute the command
    os.chdir(Path)
    print Path
    try:
        out=os.popen('winscp.exe /script=run.txt /log=transferlog.log').read()
        with open(Path+r'\transferlog.log',"rb+") as f:
            out=f.read()
        f.close()
        time.sleep(10)
        transferlog=open(os.environ['TEMP']+"\\transferlog.log","a")
        transferlog.write(out)
        transferlog.close()
        print ("The File "+FileToSend+" SFTP upload completed successfully!")
    except ValueError:
        print("No File uploaded")
            

def main():
    zip_path=DownloadSCP(src_path, URL)
    print zip_path
    file_zip=os.environ['TEMP']
    file_zip1=file_zip+r'\WinSCP'
    with disable_file_system_redirection():
        with zipfile.ZipFile(zip_path,"r") as zip_ref:
            zip_ref.extractall(file_zip1)
            print 'file unzipped to ' +file_zip1
    Path=file_zip1
##    print Path
    for FileToSend in Filelist:
        if os.path.isfile(FileToSend):
            SftpTransfer(FileToSend, Server, des, Path)
        else:
            print("The File or path "+FileToSend+" does not exists")
    if PrintLog == 1:
        Readlog=open(os.environ['TEMP']+"\\transferlog.log","r")
        Displaylog=Readlog.read()
        print Displaylog
        Readlog.close()
        time.sleep(5)
    else:
        if PrintLog == 0:
            if os.path.isfile(FileToSend):
                RemoveFile=os.remove(os.environ['TEMP']+"\\transferlog.log")
                
if __name__=="__main__":
    main()
