Bonjour,

Je programme un client FTP.
Apres avoir fait le mode PASSIF, je m'attaque au mode ACTIF.

Voici le code pour la fonction LIST :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
# fonction list mode actif
def listAct(maSock,portAct):
    # on recupere notre ip
    while 1:
        ip_donnees = raw_input("Votre adresse ip : ")
        re_ip = re.compile(r"^([1,2]{0,1}[0-9]{0,1}[0-9]{1}).([1,2]{0,1}[0-9]{0,1}[0-9]{1}).([1,2]{0,1}[0-9]{0,1}[0-9]{1}).([1,2]{0,1}[0-9]{0,1}[0-9]{1})$")
        ip = re_ip.search(ip_donnees)
        if ( ip ):
            ip = ip.group(1)+','+ip.group(2)+','+ip.group(3)+','+ip.group(4)
            # on recupere le port
            port1 = portAct//256
            port2 = portAct%256
            portAct += 1
            adrAct = ip+','+str(port1)+','+str(port2)
            break
    # PORT
    print "Commande :\tPORT "+adrAct
    maSock.sendall("PORT "+adrAct+"\r\n")
    resp = maSock.recv(1024).rstrip('\r\n')
    print "Reponse  :\t"+resp
    maSocketDonnees = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
    maSocketDonnees.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
    maSocketDonnees.bind((ip_donnees,portAct))
    maSocketDonnees.listen(socket.SOMAXCONN)
    # LIST
    print "Commande :\tLIST"
    maSock.sendall("LIST\r\n")
    resp = maSock.recv(1024).rstrip('\r\n')
    print "Reponse  :\t"+resp
    print "accept..."
    (nll_conn,depuis) = maSocketDonnees.accept()
    print nll_conn+' depuis : '+depuis
     ....
Ca bloque au niveau du accept :

$ ./clientFTP.py
Entrez l'adresse du serveur ftp : 210.96.16.205
Entrez le port du serveur ftp [21] :
Entrez votre username [anonymous] :
Entrez votre password [bob@bob.com] :
Gestion du transfert ACTIF/PASSIF [PASSIF] : ACTIF
Mode du transfert des fichiers I/A [I] :
Commande : Connect(210.96.16.205,21)
Reponse : 220 Microsoft FTP Service
Commande : USER anonymous
Reponse : 331 Anonymous access allowed, send identity (e-mail name) as password.
Commande : PASS bob@bob.com
Reponse : 230 Anonymous user logged in.
Commande : TYPE I
Reponse : 200 Type set to I.
Votre adresse ip : 172.16.7.239
Commande : PORT 172,16,7,239,100,184
Reponse : 200 PORT command successful.
Commande : LIST
Reponse : 150 Opening BINARY mode data connection for /bin/ls.
accept...
J'ai testé avec FileZilla en mode ACTIF, ça fonctionne parfaitement.
Donc je ne pige pas pourquoi avec mon client non.

Si quelqu'un voit l'erreur..
Merci !

Sorry