I am using a server to store my files, and I have employed storages.backends.sftpstorage.SFTPStorage to manage URLs, downloads, and uploads. However, I occasionally encounter the following issue when I try to get files from server, causing the entire server to hang and become temporarily unavailable.
My error log.
My sftp configuration
SFTP_STORAGE_HOST = "host"
SFTP_STORAGE_ROOT = "/Files"
SFTP_STORAGE_UID = 1000
SFTP_STORAGE_PARAMS = {
"username": "username",
"password": "password",
"port": 5522,
"timeout": 4,
"banner_timeout": 1,
"auth_timeout": 1,
"channel_timeout": 4,
}
My view to access files:
def get(self, request, name=None, *args, **kwargs):
"""Only for SFTP users."""
SFS = SFTPStorage()
if SFS.exists(name):
file = SFS._read(name)
type, encoding = mimetypes.guess_type(name)
response = HttpResponse(file, content_type=type)
response["Content-Disposition"] = 'attachment; filename="{filename}'.format(filename=name)
return response
raise Http404
I tried to set timeouts, but they didn’t help much.