0

I have some simple ftps code, that works on my laptop when connected via WIFI. However if I use my ATT IPhones tethering capabilities the code no longer runs on my laptop and the following error is thrown:

*cmd* 'AUTH TLS'
*put* 'AUTH TLS\r\n'
*get* '234 Proceed with negotiation.\r\n'
*resp* '234 Proceed with negotiation.'
Traceback (most recent call last):
  File "/Users/n/anaconda/lib/python2.7/ftplib.py", line 669, in login
    self.auth()
  File "/Users/n/anaconda/lib/python2.7/ftplib.py", line 681, in auth
    server_hostname=self.host)
  File "/Users/n/anaconda/lib/python2.7/ssl.py", line 352, in wrap_socket
    _context=self)
  File "/Users/n/anaconda/lib/python2.7/ssl.py", line 579, in __init__
    self.do_handshake()
  File "/Users/n/anaconda/lib/python2.7/ssl.py", line 808, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:590)
[Finished in 52.4s with exit code 1]

How can I get the following example to work while using tethering?

from ftplib import FTP_TLS

url = 'url.com'
username = 'guest'
password = 'password'

ftps = FTP_TLS(url)
ftps.login(username, password)  # login anonymously before securing control channel
ftps.prot_p()          # switch to secure data connection

print ftps.nlst()

ftps.quit()

I have also tried including the SSL monkey patch from this stackoverflow answer with no success.

import ssl 
ssl._create_default_https_context = ssl._create_unverified_context
Community
  • 1
  • 1
pyCthon
  • 11,746
  • 20
  • 73
  • 135

1 Answers1

1

first set the debuglevel to 2 to print out more information, and do the comparison with the difference under WiFi and AT&T, what i can think of now is the network initiated the connection from disconnected interface, so you might can try disable them and just leave AT&T active.

Allen
  • 6,505
  • 16
  • 19
  • Thanks for the suggestion, I updated the answer above with the debuglevel 2 log. It's not the interface since I'm able to browser the web and comment on stack overflow. – pyCthon Nov 19 '15 at 00:48
  • can you remove ssl._create_default_https_context = ssl._create_unverified_context first to test out? this is just for when certificate does not match the host. – Allen Nov 19 '15 at 02:28
  • just double checked, I didn't have it in there. – pyCthon Nov 19 '15 at 03:19
  • case SSL_ERROR_SYSCALL: { unsigned long e = ERR_get_error(); if (e == 0) { if (ret == 0 || !obj->Socket) { p = PY_SSL_ERROR_EOF; errstr = "EOF occurred in violation of protocol"; the above code is in ssl.c for python 2.7, indicate there is no socket error, possible wrong interface issue, what is your at&t tether interface? – Allen Nov 19 '15 at 03:25
  • it's using `en0` for thether and for wifi. – pyCthon Nov 19 '15 at 03:42
  • ok, once you tether with at&t, try telnet url 21 from terminal to see if you can connect to the remote ftp port. – Allen Nov 19 '15 at 14:56