New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Methods of ftplib never ends if the ip address changes #57923
Comments
If a client gets a reconnect and a new ip from the provider the methods of ftplib can't handle this and are hanging in an infinite loop. For example if a file is transfered with storbinary() and the client gets a new ip address the script will never end. I'm using the Linux Kernel 3.2 on a 64 bit system and Python 2.7 is affected too. |
It seems expected behavior to me, and the same issue should apply to all other network libs as well. What would you expect ftplib to do in such case? |
If the connection gets lost and reconnected again but the ip address doesn't change storbinary() continues the data transfer. But if the ip address was changed due to the reconnect storbinary() hangs in a loop. I expect either that storbinary() detects the change of the ip address and continues the data transfer like it does if the ip address has never changed or it should throw an exception. |
What storbinary does is just using a socket to send data. As a user, you just shouldn't change the IP address while a network app is running on that network interface and expect it to keep working or raise an exception. In summary, this is not a problem which should be dealt with by base ftplib or any other network lib in the stdlib. |
The problem is that it is for example here in germany very common that the provider disconnects the client every 24 hours and gives him a new ip address if his router reconnects. This makes it very difficult to send big files with ftplib. For example for daily backups I have written an automatic backup script which uses ftplib. The transfer needs some hours and very often it fails (it silently never ends) because I got a new ip address. |
Since you say the connection hangs I think you can set a timeout:
That is applied to both control and data connection (and hence storbinary). This way you should get a socket.timeout exception after 30 seconds. |
If i set the timeout argument an exception s thrown if the ip address is changed. At least it's a workaround but we should think about if Python shouldn't try to detect changes of the ip address. It would be nicer to continue the file transfer like it does if the connection gets lost without a change of the ip address instead of sending the complete data again. |
Python can't do that. It's a socket implementation detail. Python just exposes the underlying socket implementation as-is. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: