Hallo,
Danke für den Hinweis bzgl. des passiven Modus. Wird morgen ausprobiert.
Hab hier noch die Ergebnisse aus der Console wo ich ein bisschen gespielt habe.
ftp> ls
200 Port command okay
150 Opening data connection.
.
..
01.log
02.log
03.log
04.log
05.log
06.log
07.log
08.log
09.log
226 Transfer complete.
FTP: 82 Bytes empfangen in 0.03Sekunden 3.15KB/s
ftp> ls 08.log
200 Port command okay
150 Opening data connection.
08.log
226 Transfer complete.
FTP: 11 Bytes empfangen in 0.00Sekunden 3.67KB/s
ftp> ?
Befehle können abgekürzt werden. Befehle sind:
! delete literal prompt send
? debug ls put status
append dir mdelete pwd trace
ascii disconnect mdir quit type
bell get mget quote user
binary glob mkdir recv verbose
bye hash mls remotehelp
cd help mput rename
close lcd open rmdir
ftp> type
Dateien werden im ascii-Modus übertragen.
ftp> user
Benutzername refu
331 User name okay, need password.
Kennwort:
230 Logged in
ftp> status
Verbindung mit 192.168.178.99 wurde hergestellt.
Typ: ascii; Verbose: EIN ; Bell: AUS ; Prompt: EIN ; Glob: EIN
Debug: AUS ; Hash: AUS
ftp> remotehelp
214- The following commands are recognized:
abor acct cwd dele form help
list mkd nlst noop opts pass
pasv port pwd quit retr rmd
rnfr rnto stor site syst type
user xcwd xmkd xpwd xrmd
214 Direct comments to Embedded Access Inc.
ftp> pasv
Ungültiger Befehl
ftp> status
Verbindung mit 192.168.178.99 wurde hergestellt.
Typ: ascii; Verbose: EIN ; Bell: AUS ; Prompt: EIN ; Glob: EIN
Debug: AUS ; Hash: AUS
ftp>
Wenn ich die Ausgabe der remotehelp richtig verstehe müsste sowohl pasv als auch retr akzeptiert werden.
FTP - Datei mit GET oder RECV laden
Das Testprogramm schaut so aus:
import ftplib
import os
ipadr = '192.168.178.99'
ftp_user = 'refu'
ftp_passwd = 'EE0129'
ftp = ftplib.FTP(ipadr, ftp_user, ftp_passwd, timeout=100)
ftp.set_debuglevel(2)
ftp.cwd('/data/logger/2020/02')
filedata = open('11.log', 'wb')
ftp.set_pasv(False)
ftp.retrbinary('RETR 09.log', filedata.write)
filedata.close()
ftp.quit()
Als Ausgabe folgt dann:
*cmd* 'CWD /data/logger/2020/02'
*put* 'CWD /data/logger/2020/02\r\n'
*get* '257 "\\data\\logger\\2020\\02" is the current directory\n'
*resp* '257 "\\data\\logger\\2020\\02" is the current directory'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type Binary.\n'
*resp* '200 Type Binary.'
*cmd* 'PORT 192,168,178,86,221,61'
*put* 'PORT 192,168,178,86,221,61\r\n'
*get* '200 Port command okay\n'
*resp* '200 Port command okay'
*cmd* 'RETR 09.log'
*put* 'RETR 09.log\r\n'
*get* '150 Opening data connection.\n'
*resp* '150 Opening data connection.'
*get* '226 File sent OK - 11288 bytes in 0.128 sec\n'
*resp* '226 File sent OK - 11288 bytes in 0.128 sec'
*cmd* 'QUIT'
*put* 'QUIT\r\n'
*get* '221 Goodbye.\n'
*resp* '221 Goodbye.'
wird oben ftp.set_pasv(False) auskommentiert ergibt sich folgendes Bild:
*cmd* 'CWD /data/logger/2020/02'
*put* 'CWD /data/logger/2020/02\r\n'
*get* '257 "\\data\\logger\\2020\\02" is the current directory\n'
*resp* '257 "\\data\\logger\\2020\\02" is the current directory'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type Binary.\n'
*resp* '200 Type Binary.'
*cmd* 'PASV'
*put* 'PASV\r\n'
Traceback (most recent call last):
File "test3.py", line 13, in <module>
ftp.retrbinary('RETR 09.log', filedata.write)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 425, in retrbinary
with self.transfercmd(cmd, rest) as conn:
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 382, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 342, in ntransfercmd
host, port = self.makepasv()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 320, in makepasv
host, port = parse227(self.sendcmd('PASV'))
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 275, in sendcmd
return self.getresp()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 238, in getresp
resp = self.getmultiline()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 224, in getmultiline
line = self.getline()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 206, in getline
line = self.file.readline(self.maxline + 1)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen
Danke nochmals für die Hilfe!
import ftplib
import os
ipadr = '192.168.178.99'
ftp_user = 'refu'
ftp_passwd = 'EE0129'
ftp = ftplib.FTP(ipadr, ftp_user, ftp_passwd, timeout=100)
ftp.set_debuglevel(2)
ftp.cwd('/data/logger/2020/02')
filedata = open('11.log', 'wb')
ftp.set_pasv(False)
ftp.retrbinary('RETR 09.log', filedata.write)
filedata.close()
ftp.quit()
Als Ausgabe folgt dann:
*cmd* 'CWD /data/logger/2020/02'
*put* 'CWD /data/logger/2020/02\r\n'
*get* '257 "\\data\\logger\\2020\\02" is the current directory\n'
*resp* '257 "\\data\\logger\\2020\\02" is the current directory'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type Binary.\n'
*resp* '200 Type Binary.'
*cmd* 'PORT 192,168,178,86,221,61'
*put* 'PORT 192,168,178,86,221,61\r\n'
*get* '200 Port command okay\n'
*resp* '200 Port command okay'
*cmd* 'RETR 09.log'
*put* 'RETR 09.log\r\n'
*get* '150 Opening data connection.\n'
*resp* '150 Opening data connection.'
*get* '226 File sent OK - 11288 bytes in 0.128 sec\n'
*resp* '226 File sent OK - 11288 bytes in 0.128 sec'
*cmd* 'QUIT'
*put* 'QUIT\r\n'
*get* '221 Goodbye.\n'
*resp* '221 Goodbye.'
wird oben ftp.set_pasv(False) auskommentiert ergibt sich folgendes Bild:
*cmd* 'CWD /data/logger/2020/02'
*put* 'CWD /data/logger/2020/02\r\n'
*get* '257 "\\data\\logger\\2020\\02" is the current directory\n'
*resp* '257 "\\data\\logger\\2020\\02" is the current directory'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type Binary.\n'
*resp* '200 Type Binary.'
*cmd* 'PASV'
*put* 'PASV\r\n'
Traceback (most recent call last):
File "test3.py", line 13, in <module>
ftp.retrbinary('RETR 09.log', filedata.write)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 425, in retrbinary
with self.transfercmd(cmd, rest) as conn:
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 382, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 342, in ntransfercmd
host, port = self.makepasv()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 320, in makepasv
host, port = parse227(self.sendcmd('PASV'))
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 275, in sendcmd
return self.getresp()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 238, in getresp
resp = self.getmultiline()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 224, in getmultiline
line = self.getline()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\ftplib.py", line 206, in getline
line = self.file.readline(self.maxline + 1)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen
Danke nochmals für die Hilfe!
- __blackjack__
- User
- Beiträge: 13111
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@f3yb4la: Noch ein paar Anmerkungen: `os` wird importiert aber nicht verwendet.
Man sollte Namen nicht kryptisch abkürzen.
Kontextmanager auch benutzen (``with``).
`filedata` ist ein unpassender Name für eine Datei.
Man sollte Namen nicht kryptisch abkürzen.
Kontextmanager auch benutzen (``with``).
`filedata` ist ein unpassender Name für eine Datei.
Code: Alles auswählen
#!/usr/bin/env python3
import ftplib
def main():
hostname = "192.168.178.99"
ftp_user = "refu"
ftp_password = "EE0129"
with ftplib.FTP(hostname, ftp_user, ftp_password, timeout=100) as ftp:
ftp.set_debuglevel(2)
ftp.set_pasv(False)
ftp.cwd("/data/logger/2020/02")
with open("11.log", "wb") as file:
ftp.retrbinary("RETR 09.log", file.write)
if __name__ == "__main__":
main()
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
Hallo __blackjack__
Danke für die Hinweise und den Code Vorschlag.
Da hab ich nicht alle "Leichen" rausgeschmissen aber ich merk schon am Code Style und an der Wissensbasis muss ich noch massiv arbeiten.
Bin jedenfalls nun gefühlt ein ganzes Stück näher an dem was ich mir da so vorstelle.
Danke für die Hinweise und den Code Vorschlag.
Da hab ich nicht alle "Leichen" rausgeschmissen aber ich merk schon am Code Style und an der Wissensbasis muss ich noch massiv arbeiten.
Bin jedenfalls nun gefühlt ein ganzes Stück näher an dem was ich mir da so vorstelle.