I am trying to send a csv file from google cloud gcs bucket to remote sftp location using python.
import pysftp
from google.cloud import storage
from google.cloud.storage import Blob
client = storage.Client()
bucket = client.bucket("bucket_path")
blob = bucket.blob("FILE.csv")
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection(host='remote_server', username='user', password='password',
port=22,
cnopts=cnopts) as sftp:
print("Connection succesfully established ... ")
remote_file=sftp.open('remote_location/sample.csv', 'w+')
blob.download_to_file(remote_file)
I am getting the following errors :
Connection succesfully established ...
Traceback (most recent call last):
File "/dirvenv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 997, in download_to_file
self._do_download(
File "/dirvenv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 872, in _do_download
response = download.consume(transport, timeout=timeout)
File "/dirvenv/lib/python3.8/site-packages/google/resumable_media/requests/download.py", line 168, in consume
self._process_response(result)
File "/dirvenv/lib/python3.8/site-packages/google/resumable_media/_download.py", line 185, in _process_response
_helpers.require_status_code(
File "/dirvenv/lib/python3.8/site-packages/google/resumable_media/_helpers.py", line 106, in require_status_code
raise common.InvalidResponse(
google.resumable_media.common.InvalidResponse: ('Request failed with status code', 404, 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/dirPycharmProjects/leanplum/file_ftp.py", line 15, in <module>
blob.download_to_file(remote_file)
File "/dirvenv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 1008, in download_to_file
_raise_from_invalid_response(exc)
File "/dirvenv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 3262, in _raise_from_invalid_response
raise exceptions.from_http_status(response.status_code, message, response=response)
google.api_core.exceptions.NotFound: 404 GET https://storage.googleapis.com/download/storage/v1/b/gs://bucket_name/o/FILE.csv?alt=media: ('Request failed with status code', 404, 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)
Process finished with exit code 1
Any suggestion?