FTP 两次使用 ftp.cwd() 时出现 550 错误
FTP giving 550 error when using ftp.cwd() twice
当我运行这部分:
directory = ftp.pwd()
file_name = 'config.single'
ftp.cwd('plugins/GAListener')
print('dir:', directory)
ftp.cwd('plugins/CrateReloaded/crates')
它说:
ftplib.error_perm: 550 No such file or directory.
当我在 if 语句中多次更改目录时,它工作正常。
你不能这样改变工作目录吗?在更改到另一个目录之前,我是否需要重置到主服务器目录?如果是这样,我该怎么做?
代码中第一个出现的目录就是它要去的目录,然后在尝试更改到第二个目录时出错。第二个 ftp.cwd()
被注释掉,第一个 运行 没有问题,无论它指向哪个目录,所以它们肯定都在那里。
此外,当我打印 directory
时,它只打印 /
而不是 plugins/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/CrateReloaded/crates
(没有前导斜杠)将根据当前工作目录解析它。因此它将尝试打开文件夹:
/plugins/GAListener/plugins/CrateReloaded/crates
这很可能不存在。
我假设你想去
/plugins/CrateReloaded/crates
为此你必须使用绝对路径(带前导斜杠):
ftp.cwd('/plugins/CrateReloaded/crates')
当我运行这部分:
directory = ftp.pwd()
file_name = 'config.single'
ftp.cwd('plugins/GAListener')
print('dir:', directory)
ftp.cwd('plugins/CrateReloaded/crates')
它说:
ftplib.error_perm: 550 No such file or directory.
当我在 if 语句中多次更改目录时,它工作正常。
你不能这样改变工作目录吗?在更改到另一个目录之前,我是否需要重置到主服务器目录?如果是这样,我该怎么做?
代码中第一个出现的目录就是它要去的目录,然后在尝试更改到第二个目录时出错。第二个 ftp.cwd()
被注释掉,第一个 运行 没有问题,无论它指向哪个目录,所以它们肯定都在那里。
此外,当我打印 directory
时,它只打印 /
而不是 plugins/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/CrateReloaded/crates
(没有前导斜杠)将根据当前工作目录解析它。因此它将尝试打开文件夹:
/plugins/GAListener/plugins/CrateReloaded/crates
这很可能不存在。
我假设你想去
/plugins/CrateReloaded/crates
为此你必须使用绝对路径(带前导斜杠):
ftp.cwd('/plugins/CrateReloaded/crates')