在 Python 上重命名远程服务器上的文件 [英] Rename file on remote server on Python

查看:57
本文介绍了在 Python 上重命名远程服务器上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pysftp 使用 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()

我想要做的是,在放置文件 NAME_LATEST 之前,我想将已经存在的名称为NAME_LATEST"的文件重命名为NAME+",然后将新文件命名为 NAME_LATEST.重命名文件的方法是什么?

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?

推荐答案

conn.rename(remote_src, remote_dest):重命名远程主机上的文件或目录.

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

这篇关于在 Python 上重命名远程服务器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆