How can I check to make sure a network connection was successful or not?
Question:
I am using pysftp
to connect to a remote sftp server.
The syntax seems simple:
with pysftp.Connection('hostname', username='me', password='secret') as sftp:
with sftp.cd('/allcode'):
sftp.put('/pycode/filename')
But how can I check to make sure the pysftp.Connection
was successful and the sftp.put
actually uploaded the file? I would like to send an email notification if they are not.
Is there a way to do that?
Thanks!
Answers:
But how can I check to make sure the pysftp.Connection was successful and the sftp.put actually uploaded the file?
Most likely pysftp
will throw an exception if there is a problem. You shouldn’t check for success before hand. Just send the file and assume it works. Add code to handle exceptions if they occur.
As the saying goes: it is better to ask for forgiveness than to ask for permission.
So if you have any problems with that server then probably it’s better to find something else? You may check this sftp server for windows right there in case you are looking for something reliable and trustworthy. I have checked some reviews on the Internet and it looks quite nice. Hood luck with it.
I am using pysftp
to connect to a remote sftp server.
The syntax seems simple:
with pysftp.Connection('hostname', username='me', password='secret') as sftp:
with sftp.cd('/allcode'):
sftp.put('/pycode/filename')
But how can I check to make sure the pysftp.Connection
was successful and the sftp.put
actually uploaded the file? I would like to send an email notification if they are not.
Is there a way to do that?
Thanks!
But how can I check to make sure the pysftp.Connection was successful and the sftp.put actually uploaded the file?
Most likely pysftp
will throw an exception if there is a problem. You shouldn’t check for success before hand. Just send the file and assume it works. Add code to handle exceptions if they occur.
As the saying goes: it is better to ask for forgiveness than to ask for permission.
So if you have any problems with that server then probably it’s better to find something else? You may check this sftp server for windows right there in case you are looking for something reliable and trustworthy. I have checked some reviews on the Internet and it looks quite nice. Hood luck with it.