Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: Arnau27 en 11 Septiembre 2013, 23:15 pm



Título: [Python]Subir archivos via FTP
Publicado por: Arnau27 en 11 Septiembre 2013, 23:15 pm
Buenas!
El caso es que no consigo subir un archivo via ftp con python y he buscado mucha información y todavía no encuentro solución :'(

Asi es como lo he echo en la consola

Código
  1. >>> import getpass
  2. >>> from ftplib import FTP
  3. >>> ftp=FTP("nonamewebsite.zxq.net")
  4. >>> getpass=getpass.getpass()
  5. Password:
  6. >>> ftp.login("nonamewebsite_zxq", getpass)
  7. '230-User nonamewebsite_zxq has group access to:  vhosts  \n230-OK. Current restricted directory is /\n230 0 Kbytes used (0%) - authorized: 6144000 Kb'
  8. >>> ftp.getwelcome()
  9. '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\n220-You are user number 45 of 500 allowed.\n220-Local time is now 21:02. Server port: 21.\n220-This is a private system - No anonymous login\n220-IPv6 connections are also welcome on this server.\n220 You will be disconnected after 2 minutes of inactivity.'
  10. >>> ftp.retrlines("LIST")
  11. drwxrwxrwx    2 876654   vhosts       4096 Sep 11 22:16 .
  12. drwxrwxrwx    2 876654   vhosts       4096 Sep 11 22:16 ..
  13. -rw-r--r--    1 876654   vhosts          6 Sep 11 22:16 .ftpquota
  14. -rw-r--r--    1 876654   vhosts        776 Sep 11 22:16 index.html
  15. '226-Options: -a -l \n226 4 matches total'
  16. >>> ftp.delete("index.html")
  17. '250-0 Kbytes used (0%) - authorized: 6144000 Kb\n250 Deleted index.html'
  18. >>> upload_file=open("/index.html", "r")
  19. >>> ftp.storbinary("STOR /index.html", upload_file)
  20. Traceback (most recent call last):
  21.  File "<stdin>", line 1, in <module>
  22.  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 473, in storbinary
  23.    conn.sendall(buf)
  24. TypeError: 'str' does not support the buffer interface
  25. >>> files=ftp.dir()
  26. Traceback (most recent call last):
  27.  File "<stdin>", line 1, in <module>
  28.  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 528, in dir
  29.    self.retrlines(cmd, func)
  30.  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 439, in retrlines
  31.    with self.transfercmd(cmd) as conn, \
  32.  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 379, in transfercmd
  33.    return self.ntransfercmd(cmd, rest)[0]
  34.  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 337, in ntransfercmd
  35.    host, port = self.makepasv()
  36.  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 315, in makepasv
  37.    host, port = parse227(self.sendcmd('PASV'))
  38.  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 836, in parse227
  39.    raise error_reply(resp)
  40. ftplib.error_reply: 200 TYPE is now ASCII'
  41.  

Como veis he eliminado el archivo antiguo "index.html" para intentar subir el nuevo y hay dos errores, al subir el archivo y al pedirle la lista de archivos al servidor.
Espero que alguien me de la sulución, gracias !

________
Edito
Me autorespondo ya que veo que nadie ha podido responder y después de mucho buscar he encontrado la solución.
El problema estaba en que no debia usar "storbinary" sino "retrbinary".


Título: Re: [Python]Subir archivos via FTP
Publicado por: fallout20xx en 20 Septiembre 2013, 09:57 am
te lo digo para que no te coja por sorpresa, si alguna vez quieres usar sftp puedes usar una libreria llamada paramikos