I have a Python code that uses Paramiko.
#!/usr/bin/env python
import paramiko
username = ('user')
password = ('1234')
hostname = ('test-server.com')
ports = 22
localD = ('/var/tmp/testxxxxxxxx.tar.gz')
remoteD = ('/var/tmp/testxxxxxxxx.tar.gz')
paramiko.util.log_to_file('/tmp/paramiko.log')
transport = paramiko.Transport((hostname, ports))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put(remotepath=remoteD, localpath=localD)
sftp.close()
transport.close()
With this code, the local-dir and the remote-dir should be equals. if not “file not found”
How can I change or use another remote-dir different to local-dir?
Example:
localD = ('/var/tmp/testxxxxxxxx.tar.gz')
remoteD = ('/home/user/testxxxxxxxx.tar.gz')
Thank you
Since the error message says ‘No such file or directory‘, I’d first check to make sure the directory exists on remote system and is writable by the credentials you’re using. The SFTPClient class has all sorts of other methods you can call to verify the existence of target paths and create them if they don’t exist yet.
For example, calling the stat() method passing in the destination path should give you back a tuple the same as that returned by os.stat. Try running this script (I just hacked up a little path check routine and dropped it into your script):
Output should be something like this:
The mode numbers will most likely differ, but you shouldn’t get “No such file” error on any of the parts of the path other than the file name. If you do, then it probably means you need to construct the path down to the point where you want to put the file using sftp.mkdir()