Python FTP -Fehler beim Senden von Datei von SPSPython

Python-Programme
Anonymous
 Python FTP -Fehler beim Senden von Datei von SPS

Post by Anonymous »

Ich stöbere in Schwierigkeiten, wenn ich versuche, eine Datei mit FTP zu senden. Es scheint, als würde die Datei erfolgreich gesendet, aber dann erhalte ich den Fehler: FTP 451 Fehlerschließdatei .-- [5370]-. C: \ Blabla

200 Portbefehl erfolgreich. (192,168,1.100.58508)

451 Fehlerschließdatei .- [5370]-

FTP: 11738 Bytes, die in 0,00 Sekunden 5869,00KByte /Sekunden geschickt wurden. Plc < /p>
Dies ist der Python -Code, den ich auf dem SPS -SPS ausgeführt habe: < /p>
def upload_file(ftp_server, ftp_user, ftp_password, file_path, remote_path):
try:
ftp = ftplib.FTP(ftp_server)
ftp.login(user=ftp_user, passwd=ftp_password)

with open(file_path, 'rb') as file:
ftp.cwd(remote_path)
filename = os.path.basename(file_path)
ftp.storbinary(f'STOR {filename}', file)
print(f"Successfully uploaded {filename} to {remote_path} on {ftp_server}.")

ftp.quit()

return True, ""

except ftplib.all_errors as e:
print(f"FTP error: {e}")
return False, f"FTP error: {e}"

ftp_server = ''
ftp_user = ''
ftp_password = ''
plc = pyads.Connection('127.0.0.1.1.1', pyads.PORT_TC3PLC1)
plc.open()

running = True

while(running):

Send_file = plc.read_by_name('PLC variable', pyads.PLCTYPE_BOOL)

if Send_file:
source_path = plc.read_by_name('PLC variable', pyads.PLCTYPE_STRING)
destination_path = plc.read_by_name('PLC variable', pyads.PLCTYPE_STRING)

is_successful, error_message = upload_file(ftp_server, ftp_user, ftp_password, source_path, destination_path)
plc.write_by_name('PLC variable', is_successful)

if is_successful:
print("File transfer completed successfully.")
else:
print("File transfer failed.")
plc.write_by_name('PLC variable', error_message)

plc.write_by_name('PLC variable', True)

plc.close()
< /code>
Dieser Code funktioniert gut, wenn ich in ein anderes Verzeichnis auf dem Zielsystem schreibe, aber wenn ich versuche, in dieses andere Verzeichnis zu schreiben, gibt es mir den Fehler: < /p>

FTP 451 Fehlerschließdatei .- [5370]-. Kennt jemand eine Möglichkeit, diesen Fehler zu beheben? Oder eine Richtung, in die man aussehen kann?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post