对这样的初学者问题很抱歉,但是我正在尝试创建一个脚本,用户可以使用该脚本从我的sftp服务器获取文件名。目录基本上是/ files / year / month / day,因此一个示例是files / 2017/1/23。
我试图让用户输入以打印出他们想要的特定目录的文件名。我认为我的问题与将“ /”合并到输入路径中有关。但这是我的第一个项目,我可能会完全放弃。感谢您在这里的任何输入。
import pysftp as sftp
year = int(input("Enter year of event: "))
month = int(input("Enter month of event: "))
day = int(input ("Enter day of event: "))
srv = sftp.Connection(host="hostname", username="user",
password="pass")
srv.chdir("recordings/'year'/'month'/'day'")
for filename in sorted(srv.listdir()):
if filename.startswith('web') and filename.endswith('.mp4'):
print (filename)
srv.close()
换srv.chdir("recordings/'year'/'month'/'day'")
行到下面
srv.chdir("recordings/%s/%s/%s"%(year,month,day))
希望这可以帮助 !
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句