Skip to content

Commit

Permalink
mkdir for subsubdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldo committed Nov 8, 2024
1 parent b476a9c commit 2721650
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions layertree2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ def inputsFtpOk(self, host=None, user=None, password=None):
return False
else:
return True


def mk_each_dir(self, sftp, inRemoteDir):
currentDir = '/' # Slash '/' is hardcoded because ftp always uses slash
for dirElement in inRemoteDir.split('/'):
if dirElement:
currentDir += dirElement + '/'
try:
sftp.mkdir(currentDir)
except:
pass # fail silently if remote directory already exists


def connectToFtp(self, localFilePath=False, uploadPath=False, uploadFile=False, host=None, user=None, password=None):
Expand All @@ -244,10 +255,13 @@ def connectToFtp(self, localFilePath=False, uploadPath=False, uploadFile=False,
if localFilePath and uploadPath and uploadFile:
# Test if remote_path exists and create of not
try:
ftp_client.chdir(uploadPath)
ftp_client.chdir(uploadPath)
except IOError:
ftp_client.mkdir(uploadPath)

try:
self.mk_each_dir(ftp_client, uploadPath)
except IOError:
pass

#print(localFilePath, "->", uploadPath + uploadFile)
ftp_client.put(localFilePath, uploadPath + uploadFile)

Expand All @@ -256,9 +270,10 @@ def connectToFtp(self, localFilePath=False, uploadPath=False, uploadFile=False,
self.iface.messageBar().pushMessage("Success", "FTP connection ESTABLISHED to host " + host + " without uploading file", level=Qgis.Success, duration=3)

ftp_client.close()
ssh_client.close()
except:
self.iface.messageBar().pushMessage("Warning", "FTP connection FAILED to host " + host, level=Qgis.Warning, duration=3)


def replaceSpecialChar(self, text):
chars = "!\"#$%&'()*+,./:;<=>?@[\\]^`{|}~¬·"
Expand Down

0 comments on commit 2721650

Please sign in to comment.