Test Foro de elhacker.net SMF 2.1

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 (python) [Seleccionar]
>>> import getpass
>>> from ftplib import FTP
>>> ftp=FTP("nonamewebsite.zxq.net")
>>> getpass=getpass.getpass()
Password:
>>> ftp.login("nonamewebsite_zxq", getpass)
'230-User nonamewebsite_zxq has group access to:  vhosts  \n230-OK. Current restricted directory is /\n230 0 Kbytes used (0%) - authorized: 6144000 Kb'
>>> ftp.getwelcome()
'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.'
>>> ftp.retrlines("LIST")
drwxrwxrwx    2 876654   vhosts       4096 Sep 11 22:16 .
drwxrwxrwx    2 876654   vhosts       4096 Sep 11 22:16 ..
-rw-r--r--    1 876654   vhosts          6 Sep 11 22:16 .ftpquota
-rw-r--r--    1 876654   vhosts        776 Sep 11 22:16 index.html
'226-Options: -a -l \n226 4 matches total'
>>> ftp.delete("index.html")
'250-0 Kbytes used (0%) - authorized: 6144000 Kb\n250 Deleted index.html'
>>> upload_file=open("/index.html", "r")
>>> ftp.storbinary("STOR /index.html", upload_file)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 473, in storbinary
   conn.sendall(buf)
TypeError: 'str' does not support the buffer interface
>>> files=ftp.dir()
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 528, in dir
   self.retrlines(cmd, func)
 File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 439, in retrlines
   with self.transfercmd(cmd) as conn, \
 File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 379, in transfercmd
   return self.ntransfercmd(cmd, rest)[0]
 File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 337, in ntransfercmd
   host, port = self.makepasv()
 File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 315, in makepasv
   host, port = parse227(self.sendcmd('PASV'))
 File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/ftplib.py", line 836, in parse227
   raise error_reply(resp)
ftplib.error_reply: 200 TYPE is now ASCII'


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