Problems with FTP

R

RizlaJ

Hi all, I'm very new to python. I'm using Python 2.7, in a corporate
environment, therefore am behind a proxy server, firewalls etc.

I can ftp to a barclays capital ftp site ok in internet explorer, but
I can't get the FTP from ftplib to work for me. Can someone please
help!

I've tried the following commands from my home personal machine
(thefore no proxies etc) and the commands work fine and I'm able to
enter my username and password and login successfuly - however in teh
corporate environment I can't. I'm wondering if this is soemthing to
do with security permissioning at work etc?

At the shell I'm typing:-
and get the following error:
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
ftp = FTP('indexftp.barcap.com')
File "C:\Python27\lib\ftplib.py", line 117, in __init__
self.connect(host)
File "C:\Python27\lib\ftplib.py", line 132, in connect
self.sock = socket.create_connection((self.host, self.port),
self.timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
error: [Errno 10060] A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond

I wasn't expecting this error message next, i was expecting to be able
to log on using the followign command :-

Please help!

thanks!
 
T

Thomas Jollans

Hi all, I'm very new to python. I'm using Python 2.7, in a corporate
environment, therefore am behind a proxy server, firewalls etc.

I can ftp to a barclays capital ftp site ok in internet explorer, but
I can't get the FTP from ftplib to work for me. Can someone please
help!

It sounds very much like, as you said, you're behind a proxy, and have to use
that proxy to connect to the FTP server. If you don't know the proxy settings,
you might be able to find them in the IE configuration, or ask the local
sysadmin.

http://stackoverflow.com/questions/1293518/proxies-in-python-ftp-application

It looks like you will have to ftp to the proxy server. Depending on the
application, you might be able to use urllib2 instead.

Thomas
I've tried the following commands from my home personal machine
(thefore no proxies etc) and the commands work fine and I'm able to
enter my username and password and login successfuly - however in teh
corporate environment I can't. I'm wondering if this is soemthing to
do with security permissioning at work etc?

At the shell I'm typing:-

and get the following error:
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
ftp = FTP('indexftp.barcap.com')
File "C:\Python27\lib\ftplib.py", line 117, in __init__
self.connect(host)
File "C:\Python27\lib\ftplib.py", line 132, in connect
self.sock = socket.create_connection((self.host, self.port),
self.timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
error: [Errno 10060] A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond

I wasn't expecting this error message next, i was expecting to be able
to log on using the followign command :-

Please help!

thanks!
 
G

Giampaolo Rodolà

The solution proposed on stackoverflow:

from ftplib import FTP
site = FTP('my_proxy')
site.set_debuglevel(1)
msg = site.login('anonymous at ftp.download.com', 'password')
site.cwd('/pub')

....can not work.
The "anonymous at ftp.download.com" part is pure fiction.
Nothing like that has ever been mentioned in any RFC or
implemented/supported by any server, as far as I know.
I'd say the only way to proxy FTP is by using a SOCKS proxy.
By looking at the error message it's likely that the company firewall
is just blocking the FTP traffic.


--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/



2011/1/21 Thomas Jollans said:
Hi all, I'm very new to python. I'm using Python 2.7, in a corporate
environment, therefore am behind a proxy server, firewalls etc.

I can ftp to a barclays capital ftp site ok in internet explorer, but
I can't get the FTP from ftplib to work for me. Can someone please
help!

It sounds very much like, as you said, you're behind a proxy, and have to use
that proxy to connect to the FTP server. If you don't know the proxy settings,
you might be able to find them in the IE configuration, or ask the local
sysadmin.

http://stackoverflow.com/questions/1293518/proxies-in-python-ftp-application

It looks like you will have to ftp to the proxy server. Depending on the
application, you might be able to use urllib2 instead.

Thomas
I've tried the following commands from my home personal machine
(thefore no proxies etc) and the commands work fine and I'm able to
enter my username and password and login successfuly - however in teh
corporate environment I can't. I'm wondering if this is soemthing to
do with security permissioning at work etc?

At the shell I'm typing:-
from ftplib import FTP
ftp = FTP('indexftp.barcap.com')

and get the following error:
Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    ftp = FTP('indexftp.barcap.com')
  File "C:\Python27\lib\ftplib.py", line 117, in __init__
    self.connect(host)
  File "C:\Python27\lib\ftplib.py", line 132, in connect
    self.sock = socket.create_connection((self.host, self.port),
self.timeout)
  File "C:\Python27\lib\socket.py", line 571, in create_connection
    raise err
error: [Errno 10060] A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond

I wasn't expecting this error message next, i was expecting to be able
to log on using the followign command :-
ftp.login("username","password")

Please help!

thanks!
 
R

RizlaJ

Hi Tom, Giampaolo,

Thank you both for your swift replies. I have asked our IT dept to see
if it is the firewall that is blocking the FTP. They are working on
that side of things.

However I would have thought that the following or some version of it
would have worked:-

Traceback (most recent call last):
File "<pyshell#51>", line 1, in <module>
filehandle = urllib.urlopen(some_url, proxies=proxies)
File "C:\Python27\lib\urllib.py", line 84, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 177, in open
fullurl = unwrap(toBytes(fullurl))
File "C:\Python27\lib\urllib.py", line 1026, in unwrap
url = url.strip()
AttributeError: 'dict' object has no attribute 'strip'

However as you can see there is an error - is this again related to
the firewall do you think?

Sorry for asking stupid questions! and thank you for your help in
advance.
 
B

Benjamin Kaplan

Hi Tom, Giampaolo,

Thank you both for your swift replies. I have asked our IT dept to see
if it is the firewall that is blocking the FTP. They are working on
that side of things.

However I would have thought that the following or some version of it
would have worked:-


Traceback (most recent call last):
 File "<pyshell#51>", line 1, in <module>
   filehandle = urllib.urlopen(some_url, proxies=proxies)
 File "C:\Python27\lib\urllib.py", line 84, in urlopen
   return opener.open(url)
 File "C:\Python27\lib\urllib.py", line 177, in open
   fullurl = unwrap(toBytes(fullurl))
 File "C:\Python27\lib\urllib.py", line 1026, in unwrap
   url = url.strip()
AttributeError: 'dict' object has no attribute 'strip'

However as you can see there is an error - is this again related to
the firewall do you think?

Sorry for asking stupid questions! and thank you for your help in
advance.


The one has nothing to do with a firewall. It's telling you that the
function is trying to call url.strip(). But url is a dict object which
doesn't have a strip method. Which should tell you that some_url is
being constructed incorrectly- it's supposed to be a string.
 
G

Giampaolo Rodolà

The standard FTP protocol does not supporty any kind of proxy-ing
feature natively.
The only closest thing to the concept of a "proxy" we can find in the
FTP protocol is the site-to-site transfer feature:
http://code.google.com/p/pyftpdlib/wiki/FAQ#What_is_FXP?
....but it's something different.

By taking a look at your code, though, this is out of question anyway
since you can't even connect to the server, let alone send proxy-like
(non-standard) commands.
I'd focus on investigating whether it's something with the internal
network and forget about proxy-related problems since from here I can
connect to indexftp.barcap.com.
As for urllib's proxy option I'd say it's only valid for HTTP protocol.

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
 
R

RizlaJ

Thanks Giampaolo, Benjamin for your responses. You are correct, if I
can connect to the ftp site from home and you can connect too then the
problem (as you state) lies at the firewall or some security issue.

Thanks for your detailed responses, they've been very helpful to me.
Kind Regards
 
Joined
Jan 22, 2011
Messages
1
Reaction score
0
you could check ftp.icannotconnect.com , it is an online test that tries to connect directly to the ftp port, bypassing any proxies you might have, so you can use it to tell if the ftp port is actually being blocked.
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top