Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef969d3d3b | |||
3d92d73879 |
@ -125,7 +125,7 @@ class IoTFTPSClient:
|
|||||||
with open(dest, "wb") as file:
|
with open(dest, "wb") as file:
|
||||||
self.ftps_session.retrbinary(f"RETR {source}", file.write)
|
self.ftps_session.retrbinary(f"RETR {source}", file.write)
|
||||||
|
|
||||||
def upload_file(self, source: str, dest: str, callback=None):
|
def upload_file(self, source: str, dest: str, callback=None) -> bool:
|
||||||
"""upload a file to a path inside the FTPS server"""
|
"""upload a file to a path inside the FTPS server"""
|
||||||
|
|
||||||
file_size = os.path.getsize(source)
|
file_size = os.path.getsize(source)
|
||||||
@ -133,43 +133,50 @@ class IoTFTPSClient:
|
|||||||
block_size = max(file_size // 100, 8192)
|
block_size = max(file_size // 100, 8192)
|
||||||
rest = None
|
rest = None
|
||||||
|
|
||||||
# Taken from ftplib.storbinary but with custom ssl handling
|
try:
|
||||||
# due to the shitty bambu p1p ftps server TODO fix properly.
|
# Taken from ftplib.storbinary but with custom ssl handling
|
||||||
with open(source, "rb") as fp:
|
# due to the shitty bambu p1p ftps server TODO fix properly.
|
||||||
self.ftps_session.voidcmd('TYPE I')
|
with open(source, "rb") as fp:
|
||||||
|
self.ftps_session.voidcmd('TYPE I')
|
||||||
|
|
||||||
with self.ftps_session.transfercmd(f"STOR {dest}", rest) as conn:
|
with self.ftps_session.transfercmd(f"STOR {dest}", rest) as conn:
|
||||||
while 1:
|
while 1:
|
||||||
buf = fp.read(block_size)
|
buf = fp.read(block_size)
|
||||||
|
|
||||||
if not buf:
|
if not buf:
|
||||||
break
|
break
|
||||||
|
|
||||||
conn.sendall(buf)
|
conn.sendall(buf)
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
callback(buf)
|
callback(buf)
|
||||||
|
|
||||||
# shutdown ssl layer
|
# shutdown ssl layer
|
||||||
if ftplib._SSLSocket is not None and isinstance(conn, ftplib._SSLSocket):
|
if ftplib._SSLSocket is not None and isinstance(conn, ftplib._SSLSocket):
|
||||||
# Yeah this is suposed to be conn.unwrap
|
# Yeah this is suposed to be conn.unwrap
|
||||||
# But since we operate in prot p mode
|
# But since we operate in prot p mode
|
||||||
# we can close the connection always.
|
# we can close the connection always.
|
||||||
# This is cursed but it works.
|
# This is cursed but it works.
|
||||||
if "vsFTPd" in self.welcome:
|
if "vsFTPd" in self.welcome:
|
||||||
conn.unwrap()
|
conn.unwrap()
|
||||||
else:
|
else:
|
||||||
conn.shutdown(socket.SHUT_RDWR)
|
conn.shutdown(socket.SHUT_RDWR)
|
||||||
|
|
||||||
return self.ftps_session.voidresp()
|
return True
|
||||||
|
except Exception as ex:
|
||||||
|
print(f"unexpected exception occurred: {ex}")
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
# Old api call.
|
def delete_file(self, path: str) -> bool:
|
||||||
# self.ftps_session.storbinary(
|
|
||||||
# f"STOR {dest}", file, blocksize=block_size, callback=callback)
|
|
||||||
|
|
||||||
def delete_file(self, path: str):
|
|
||||||
"""delete a file from under a path inside the FTPS server"""
|
"""delete a file from under a path inside the FTPS server"""
|
||||||
self.ftps_session.delete(path)
|
try:
|
||||||
|
self.ftps_session.delete(path)
|
||||||
|
return True
|
||||||
|
except Exception as ex:
|
||||||
|
print(f"unexpected exception occurred: {ex}")
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
def move_file(self, source: str, dest: str):
|
def move_file(self, source: str, dest: str):
|
||||||
"""move a file inside the FTPS server to another path inside the FTPS server"""
|
"""move a file inside the FTPS server to another path inside the FTPS server"""
|
||||||
|
@ -509,8 +509,8 @@ class BambuPrinter:
|
|||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def _gcode_M29(self, data: str) -> bool:
|
def _gcode_M29(self, data: str) -> bool:
|
||||||
self._logger.debug("ignoring M28 command.")
|
self._logger.debug("ignoring M29 command.")
|
||||||
self._send("M28 disabled for Bambu")
|
self._send("M29 disabled for Bambu")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _gcode_M30(self, data: str) -> bool:
|
def _gcode_M30(self, data: str) -> bool:
|
||||||
@ -811,7 +811,7 @@ class BambuPrinter:
|
|||||||
if file is not None:
|
if file is not None:
|
||||||
ftp = IoTFTPSClient(f"{host}", 990, "bblp", f"{access_code}", ssl_implicit=True)
|
ftp = IoTFTPSClient(f"{host}", 990, "bblp", f"{access_code}", ssl_implicit=True)
|
||||||
try:
|
try:
|
||||||
if ftp.delete_file(filename):
|
if ftp.delete_file(file["path"]):
|
||||||
self._logger.debug(f"{filename} deleted")
|
self._logger.debug(f"{filename} deleted")
|
||||||
else:
|
else:
|
||||||
raise Exception("delete failed")
|
raise Exception("delete failed")
|
||||||
|
2
setup.py
2
setup.py
@ -14,7 +14,7 @@ plugin_package = "octoprint_bambu_printer"
|
|||||||
plugin_name = "OctoPrint-BambuPrinter"
|
plugin_name = "OctoPrint-BambuPrinter"
|
||||||
|
|
||||||
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
||||||
plugin_version = "0.0.7"
|
plugin_version = "0.0.9"
|
||||||
|
|
||||||
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
||||||
# module
|
# module
|
||||||
|
Reference in New Issue
Block a user