Rename file on remote server on Python

拜拜、爱过 提交于 2021-01-13 09:37:12

问题


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?


回答1:


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




回答2:


For pysftp 0.2.8, rename documentation is available at API page. There is nothing in cookbook for rename.



来源:https://stackoverflow.com/questions/31315427/rename-file-on-remote-server-on-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!