Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python FTP to iPad

Tags:

python

ipad

ftp

I'm on Windows 7.

I cannot connect to my iPad with a simple Python script:

HOST = '192.168.1.122'
try:
    f = ftplib.FTP(HOST)
except (socket.error, socket.gaierror), e:    
    MessageBox.Show('ERROR: cannot reach "%s"' % HOST)
    return          
try:
    f.connect(HOST,2121)
    f.login()
except ftplib.error_perm:
    MessageBox.Show('ERROR: cannot login anonymously')
    f.quit()
    return

The errors I have is "getaddrinfo returns an empty list" and the "cannot reach..." message... Cannot solve it...

I tried to FTP with several programs on the iPad without success. If I FTP via DOS box or using a FTP software it works. I tried as well another FTP server on my PC and it works.

I am forced to use port 2121, so can't change it.

Any clue or experience?

like image 939
Maurizio Avatar asked Oct 13 '22 17:10

Maurizio


1 Answers

You should read docs before anything:

class ftplib.FTP([host[, user[, passwd[, acct[, timeout]]]]]) Return a new instance of the FTP class. When host is given, the method call connect(host) is made. When user is given, additionally the method call login(user, passwd, acct) is made (where passwd and acct default to the empty string when not given). The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if is not specified, the global default timeout setting will be used).

So, if you do f = ftplib.FTP(HOST) it fails because it will try to connect to standard port (21) and not 2121. You should get an instance of ftplib and later use f.connect(HOST, 2121).

http://docs.python.org/library/ftplib.html

like image 119
webbi Avatar answered Nov 15 '22 09:11

webbi