Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename file on remote server on Python

Tags:

python

sftp

I am using pysftp to access files on server using python.

conn = sftp.Connection(host = 'host', username = 'user', password = 'password')
remotepath = '/tmp/random/NAME_LATEST.zip'
localpath = '/home/tmp/Desktop/NAME.zip'
conn.put(localpath,remotepath)
conn.close()

What I want to do is, before putting the file NAME_LATEST, I want to rename the file already present with the name 'NAME_LATEST' to 'NAME+' and then put the new file as NAME_LATEST. What is a way to rename the file?

like image 750
randomnessrandomly Avatar asked Jun 21 '26 22:06

randomnessrandomly


1 Answers

conn.rename(remote_src, remote_dest): rename a file or directory on the remote host.

like image 110
kay Avatar answered Jun 23 '26 11:06

kay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!