Forum Discussion

spartan27244's avatar
spartan27244
Icon for Resolver I rankResolver I
1 year ago
Solved

Pass File list to notebook from copy data in a pipeline

I have a copy data activity that copies files that come in via sftp each day to my onelake. I need to be able move those files to another folder once the copy is complete. Since there is no activity ...
  • spartan27244's avatar
    1 year ago

    was able to accomplish my task using a notebook, since the Copy Data activity does not pass a list of files anywhere.

     

    transport = paramiko.Transport(ftpserver, 22)
    transport.connect(username=ftpuserid, password=ftppwd)
    sftp = paramiko.SFTPClient.from_transport(transport)

    fileList = sftp.listdir(FromFolder)

    for file in fileList:
        if fnmatch.fnmatch(file, Mask):
            # read file to memory becuase ftp library has no access to lake house
            with sftp.open(FromFolder + "/" + file, "r") as remote_file:
                file_data = remote_file.read()   # 1MB chunks
                str_data = file_data.decode("latin-1")
                notebookutils.fs.put(ToFolder + "/" + file, str_data, True)            
           
            #let's ensure the Arc Folder exists on the ftp server
            try:
                print(sftp.listdir(ArcFolder))
            except IOError:
                sftp.mkdir(ArcFolder)
           
            sftp.rename(FromFolder + "/" + file, ArcFolder + "/" + file)
           
       
    sftp.close()
    transport.close()