Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

sftp - Rename file on remote server on Python

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...