Python 两次使用FTP.cwd()时出现FTP错误
当我运行此部件时:Python 两次使用FTP.cwd()时出现FTP错误,python,ftp,ftplib,Python,Ftp,Ftplib,当我运行此部件时: directory = ftp.pwd() file_name = 'config.single' ftp.cwd('plugins/GAListener') print('dir:', directory) ftp.cwd('plugins/CrateReloaded/crates') 它说: ftplib.error\u perm:550没有这样的文件或目录 当我在if语句中多次更改目录时,它可以正常工作 您不能像那样更改工作目录吗?在更改到另一个服务器目录之前,是否需
directory = ftp.pwd()
file_name = 'config.single'
ftp.cwd('plugins/GAListener')
print('dir:', directory)
ftp.cwd('plugins/CrateReloaded/crates')
它说:
ftplib.error\u perm:550没有这样的文件或目录
当我在if语句中多次更改目录时,它可以正常工作
您不能像那样更改工作目录吗?在更改到另一个服务器目录之前,是否需要重置到主服务器目录?如果是的话,我会怎么做
在代码中,无论哪个目录位于第一位,都是它要访问的目录,然后在尝试更改为第二个目录时会给出一个错误。第二个ftp.cwd()
被注释掉后,第一个运行没有问题,无论它指向哪个目录,因此它们肯定都在那里
另外,当我打印目录时,它只打印/
,而不打印插件/GAListener
编辑:当在if语句中执行此操作时,所有目录都会转到它们应该去的地方,并且我不会在没有前导斜杠的情况下收到任何错误
if day_of_week == 0 and file_name not in ftp.nlst():
ftp.rename('config.yml', 'config.single')
ftp.rename('config.double', 'config.yml')
print('plugins/GAListener/config.yml is now plugins/GAListener/config.single.')
print('plugins/GAListener/config.double is now plugins/GAListener/config.yml.')
ftp.cwd('plugins/MOTDCountdown')
ftp.rename('config.yml', 'config.sunday')
ftp.rename('config.monday', 'config.yml')
print('plugins/MOTDCountdown/config.yml is now plugins/MOTDCountdown/config.sunday.')
print('plugins/MOTDCountdown/config.monday is now plugins/MOTDCountdown/config.yml.')
ftp.cwd('plugins/Essentials')
ftp.rename('motd.txt', 'motd.sunday')
ftp.rename('motd.monday', 'motd.txt')
在第一次cwd
之后,您将进入以下文件夹:
/plugins/GAListener
更改为相对路径plugins/cantreloaded/crates(不带前导斜杠)将根据当前工作目录解析它。因此,它将尝试打开以下文件夹:
/plugins/GAListener/plugins/carteloaded/crates
这很可能是不存在的
我猜你想去
/plugins/cantreloaded/crates
为此,必须使用绝对路径(带前导斜杠):
在第一次cwd
之后,您将进入以下文件夹:
/plugins/GAListener
更改为相对路径plugins/cantreloaded/crates(不带前导斜杠)将根据当前工作目录解析它。因此,它将尝试打开以下文件夹:
/plugins/GAListener/plugins/carteloaded/crates
这很可能是不存在的
我猜你想去
/plugins/cantreloaded/crates
为此,必须使用绝对路径(带前导斜杠):
我懂了。那么为什么它在if语句中工作呢?如果我连续几次使用ftp.cwd(plugins/xxxx)
而不使用前导斜杠,它就可以正常工作。如果没有代码示例,我无法回答这个问题。你的描述太模糊了。这些是不同的文件夹+你能为你的示例启用日志并发布日志吗FTP.set_debuglevel
我想我可能犯了一个错误,以为我尝试了没有前导斜杠的if语句。谢谢你的帮助。那么为什么它在if语句中工作呢?如果我连续几次使用ftp.cwd(plugins/xxxx)
而不使用前导斜杠,它就可以正常工作。如果没有代码示例,我无法回答这个问题。你的描述太模糊了。这些是不同的文件夹+你能为你的示例启用日志并发布日志吗FTP.set_debuglevel
我想我可能犯了一个错误,以为我尝试了没有前导斜杠的if语句。谢谢你的帮助
ftp.cwd('/plugins/CrateReloaded/crates')