I have a script which I use to retrieve specific files via SFTP on a regular basis. On occasion, the script will error out with the following output:
Traceback (most recent call last):
File "ETL.py", line 304, in <module>
get_all_files(startdate, enddate, "vma" +
foldernumber + "/logs/", txtype[1] + single_date2 + ".log", txtype[2] +
foldernumber + "\\", sftp)
File "ETL.py", line 283, in get_all_files
sftp.get(sftp_dir + filename, local_dir + filename)
File "C:\Python27\lib\site-packages\pysftp\__init__.py", line 249, in get
self._sftp.get(remotepath, localpath, callback=callback)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 806, in get
"size mismatch in get! {} != {}".format(s.st_size, size)
IOError: size mismatch in get! 950272 != 1018742
I have looked through the Paramiko documentation and do not see an explanation for what would trigger this error. Furthermore, the code often works successfully on subsequent tries, or will run successfully for the first few files in the date range and then error out in the middle of downloading all the files I need to retrieve. Other answers on SO say it might be related to the space available on the drive, but I have tried clearing out the destination folder and it hasn't helped. I am trying to download to a network drive/cloud storage if that makes any difference.
Here is the function and code I am using to retrieve the files (via Paramiko):
def get_all_files(start_date, end_date, sftp_dir, filename, local_dir, \
sftp_connection):
sftp.get(sftp_dir + filename, local_dir + filename)
with pysftp.Connection('******.com', username='*****', password='******', cnopts=cnopts) as sftp:
get_all_files(startdate, enddate, "vma" + foldernumber + "/logs/", txtype[1] + single_date2 + ".log", txtype[2] + foldernumber + "\\", sftp)
I would like all downloadable files to be retrieved without producing this error.