FTP 服务器应该如何响应尝试检索不存在的文件
How should FTP server respond to attempt to retrieve file that doesn't exist
我正在使用 pyftplib 创建一个 ftp 服务器来上传视频。
ftp 服务器本身位于 google 计算引擎之上,视频文件存储在 google 云中。
我通过使用 pyftplib 中的事件回调在将视频发送到 ftp 服务器时将它们从计算引擎上传到云来执行此操作。
同样,当客户端请求文件时,我正在从 google 云中检索文件。
在下面代码中描述的情况下,我需要响应找不到文件。
但是,我不清楚当文件不存在时预期的 FTP 响应是什么。是否有我不知道的特定状态代码?
def ftp_RETR(self, file):
for restricted_file_name in restricted_file_names:
if restricted_file_name.lower() in file.lower():
self.respond('200') # this is where I want to say file doesn't exist
return
try:
storage_client = storage.Client(project='myproject')
bucket = storage_client.get_bucket('myvideo')
blob = bucket.blob(file)
blob.download_to_file(open(file, 'w'))
except NotFound:
pass
FTPHandler.ftp_RETR(self, file)
谢谢
来自 RFC 959,即 FTP 标准:
450 Requested file action not taken.
File unavailable (e.g., file busy).
我正在使用 pyftplib 创建一个 ftp 服务器来上传视频。 ftp 服务器本身位于 google 计算引擎之上,视频文件存储在 google 云中。 我通过使用 pyftplib 中的事件回调在将视频发送到 ftp 服务器时将它们从计算引擎上传到云来执行此操作。 同样,当客户端请求文件时,我正在从 google 云中检索文件。 在下面代码中描述的情况下,我需要响应找不到文件。 但是,我不清楚当文件不存在时预期的 FTP 响应是什么。是否有我不知道的特定状态代码?
def ftp_RETR(self, file):
for restricted_file_name in restricted_file_names:
if restricted_file_name.lower() in file.lower():
self.respond('200') # this is where I want to say file doesn't exist
return
try:
storage_client = storage.Client(project='myproject')
bucket = storage_client.get_bucket('myvideo')
blob = bucket.blob(file)
blob.download_to_file(open(file, 'w'))
except NotFound:
pass
FTPHandler.ftp_RETR(self, file)
谢谢
来自 RFC 959,即 FTP 标准:
450 Requested file action not taken.
File unavailable (e.g., file busy).