1

Python version 2.7.3

Python code, interactive mode

import socket
socket.setdefaulttimeout(2)
s = socket.socket()
s.connect(("192.168.95.148",21))

Errors out

>>> s.connect(("192.168.95.148",21))
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/lib/python2.7/socket.py", line 224, in meth
 return getattr(self._sock,name)(*args)
socket.timeout: timed out

Syntax looks correct. I even tried with another IP address that is pingable and same error.

Thanks!

asked Jun 16, 2015 at 21:48

2 Answers 2

2

I am looking at the port you are using (21) and it's the FTP port.

https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

I don't see any errors in your code per se, but here some things I am worried about:

a) A lot of places lock down and turn off FTP, telnet, etc. ports that are historically used, but in today's security consious world, we use scp and ssh (instead of ftp and ssh). You might talk to your system administrators and see if that service is even turned on, or let alone your filewall even allows that port to go through.

b) I am not used to seeing the default parameters, but I assume you want

socket(socket.AF_INET, socket.SOCK_STREAM)

I have Python 2.6, and that is the defaults for that (which I assume is the same for 2.7).

c) I would try this on different ports to see if it is a port problem. Of course, the early numbered ports are special "well-known ports" that normal users can't use. I usually use port 9711 or 8888.

d) I would also try it without the timeout and see if that works.

I hope this helps!

answered Jun 16, 2015 at 22:09
Sign up to request clarification or add additional context in comments.

1 Comment

I am learning from "Violent Python" for study. Will try this.
0

This is not a direct answer to your question, but if you're seeking to do FTP transfers, may I suggest to use the standard ftplib module instead?

answered Jun 16, 2015 at 22:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.