Uploading file using Paramiko in Python seemingly works, but the file cannot be found on the server

Viewed 214

I am new to Python and sorry for my bad english. I'm trying to save a file "toto.txt" from my HDD "d:" to my Synology NAS. So I'll use paramiko for this, here is the code :

import paramiko
import os

ip_address = "my nas ip"
username = "my username"
password = "mypass"
utilisateur = os.getenv("USERNAME") // to get Windows username
remote_path = f"{utilisateur}/test.txt" // the file downloaded
local_path = "d:/toto.txt" //the file stored on my pc

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip_address,username=username,password=password)
print("Connexion OK >", ip_address)

stdin, stdout, stderr = ssh_client.exec_command(f'mkdir {utilisateur}') //creating folder for the 
user
sftp = ssh_client.open_sftp()
sftp.put(local_path,remote_path) // trying to send the file
sftp.close()
ssh_client.close()

i am not getting error but nothing is happening. The folder is successful created but no file is sending in it. Have someone an idea? thanks a lot

1 Answers

If Paramiko does not throw any error, the upload was successful. The file just possibly ended in different location than you wanted/than you look to.

At least for a test, if not permanently, try an absolute absolute path. Make no guesses, use the exact path you see in your GUI SFTP client.


Another possibility is that the server automatically processes the uploaded file somehow and moves it away.

Related