Forum Discussion

zxbucks's avatar
zxbucks
Regular Visitor
9 months ago
Solved

Notebook to load file from Lakehouse to SFTP failed

Hey Community, I need your help to troubleshooting below script:

 

Purpose:  Upload file from Lakehouse to SFTP

 

 

Failure Message:

No such file or directory: 'Files/test.csv'

 

Script:

import paramiko
local_csv_path="Files/test.csv"
sftp_host = x
sftp_port = x
sftp_user = x
sftp_pass = x
remote_path = x
 

# SFTP connect succss, I can success print list of SFTP
try:
    transport = paramiko.Transport((sftp_host, sftp_port))
    transport.connect(username=sftp_user, password=sftp_pass)
    sftp = paramiko.SFTPClient.from_transport(transport)
 
    #This sftp.put fail with error: No such file or directory: 'Files/test.csv'
    sftp.put(local_csv_path, remote_path)

    sftp.close()
    transport.close()
except Exception as e:
    print(f"SFTP upload failed: {e}")
 
 
Do I refer the file url in a wrong way?
 
 
Add:
Looks I found the solution:
Here you could use "Copy File API path" (click the ... dots in Lakehouse Files session to get it from the file you want) to get the right file url format for paramiko to use:
 
The one I get is like this:
local_csv_path="/lakehouse/default/Files/test.csv"
 
Thanks for support!

 

  • Hi zxbucks ,

     

    You already found the right fix 👍 — the issue was just the file path. In Fabric notebooks, Files/test.csv is not a valid local path for Python libraries like paramiko. The file system that your code can see always starts at the Lakehouse mount point.

     

    That’s why Paramiko couldn’t find the file and raised “No such file or directory”.

     

    The correct way to reference a file from the Lakehouse is:

    local_csv_path = "/lakehouse/default/Files/test.csv"

     

    Once you use the full Lakehouse path, sftp.put() works as expected.

     

    Your tip about using “Copy file API path” from the Lakehouse UI is perfect — that’s the easiest way to get the right path format without guessing.

     

    So yes, your solution is 100% correct, and this is exactly how it should be done in Fabric.

    – Gopi Krishna

1 Reply

  • Hi zxbucks ,

     

    You already found the right fix 👍 — the issue was just the file path. In Fabric notebooks, Files/test.csv is not a valid local path for Python libraries like paramiko. The file system that your code can see always starts at the Lakehouse mount point.

     

    That’s why Paramiko couldn’t find the file and raised “No such file or directory”.

     

    The correct way to reference a file from the Lakehouse is:

    local_csv_path = "/lakehouse/default/Files/test.csv"

     

    Once you use the full Lakehouse path, sftp.put() works as expected.

     

    Your tip about using “Copy file API path” from the Lakehouse UI is perfect — that’s the easiest way to get the right path format without guessing.

     

    So yes, your solution is 100% correct, and this is exactly how it should be done in Fabric.

    – Gopi Krishna