10060, 'Operation timed out'

S

Sumit Acharya

I am using following script to connect to the server and i try the
connection for 1000 times. Some times it succeeds for all the 1000
times,but some times it fails with error:-
10060, 'Operation timed out'. When it fails with the abover error, it
seems timed out time is 20 seconds. Is there a way I can increase the
timedout time for FTP?

from ftplib import FTP
import time
import sys

host = sys.argv[1]
port = sys.argv[2]

for x in range(1000):
try:
y = time.time()
ftp = FTP()
ftp.connect(host,port)
ftp.login('a','a')
try:
print ftp.sendcmd('pass x')
except:
print sys.exc_value
ftp.close()
except:
print sys.exc_value
r = time.time()
print "Timeout %d %d %((r-y),x)

when there is error in connecting, it comes to the outer except and
prints the value of r-y as 21. How i can increase this timeout time? or
this error indicates something else?

Please let me know asap,
 
S

Steve Holden

Sumit said:
I am using following script to connect to the server and i try the
connection for 1000 times. Some times it succeeds for all the 1000
times,but some times it fails with error:-
10060, 'Operation timed out'. When it fails with the abover error, it
seems timed out time is 20 seconds. Is there a way I can increase the
timedout time for FTP?

from ftplib import FTP
import time
import sys

host = sys.argv[1]
port = sys.argv[2]

for x in range(1000):
try:
y = time.time()
ftp = FTP()
ftp.connect(host,port)
ftp.login('a','a')
try:
print ftp.sendcmd('pass x')
except:
print sys.exc_value
ftp.close()
except:
print sys.exc_value
r = time.time()
print "Timeout %d %d %((r-y),x)

when there is error in connecting, it comes to the outer except and
prints the value of r-y as 21. How i can increase this timeout time? or
this error indicates something else?

Please let me know asap,
In a single-threaded program you can import the socket module and then
use the socket.setdefaulttimeout() function to establish a longer timeout.

regards
Steve
 
S

Sumit Acharya

can u please modify the script that i have posted with your suggestion,
it will help me to a certain extent.

Thanks
 
S

Steve Holden

Sumit said:
can u please modify the script that i have posted with your suggestion,
it will help me to a certain extent.

Thanks
from ftplib import FTP
import time
import sys
import socket

socket.setdefaulttimeout(60)
host = sys.argv[1]
port = sys.argv[2]

for x in range(1000):
try:
y = time.time()
ftp = FTP()
ftp.connect(host,port)
ftp.login('a','a')
try:
print ftp.sendcmd('pass x')
except:
print sys.exc_value
ftp.close()
except:
print sys.exc_value
r = time.time()
print "Timeout %d %d %((r-y),x)
 
S

Steve Holden

Sumit said:
After 20 seconds only.
Of course I now realise there's no default timeout on sockets anyway, so
that likely wasn't the problem.

Which statement is failing?

You would actually get much more information without the try/except
clauses, as they are stopping the traceback from being printed - if the
error is occurring deep in the ftplib you will actually see "what and
where" with a full traceback. Your loop should read:

for x in range(1000):
ftp = FTP()
ftp.connect(host,port)
ftp.login('a','a')
print ftp.sendcmd('pass x')
ftp.close()

Try running the script without both try/excepts and then post the full
traceback, please. You can forget about the timings for now. It may well
be an FTP server loading issue, but a traceback will give more information.

regards
Steve
 
S

Sumit Acharya

Hi Steve,

Thanks, I have started the run without try and except block, I will
update with the findings tomm.
Please keep this thread on for you so that I can get the solution
 
S

Sumit Acharya

Hi Steve,
this is the trace I have got:-
Traceback (most recent call last):
File "sumit1.py", line 39, in ?
ftp.connect(host,port)
File "C:\programs\packages\python24\lib\ftplib.py", line 129, in
connect
raise socket.error, msg
socket.error: (10060, 'Operation timed out')
 
S

Steve Holden

Sumit said:
Hi Steve,
this is the trace I have got:-
Traceback (most recent call last):
File "sumit1.py", line 39, in ?
ftp.connect(host,port)
File "C:\programs\packages\python24\lib\ftplib.py", line 129, in
connect
raise socket.error, msg
socket.error: (10060, 'Operation timed out')
So the FTP server is refusing your connection, I suspect. There's no way
the client can control the time it takes to do that.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top