Skip to content

Commit 1bdde73

Browse files
authored
Merge pull request #19 from shivanand-adky/master
Fix create_file method to ensure parent directories exist
2 parents a64c7f1 + 7e86d0d commit 1bdde73

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

shell_util/common_api.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,27 @@ def copy_files_local_to_remote(self, src_path, des_path):
327327

328328
# create a remote file from input string
329329
def create_file(self, remote_path, file_data):
330+
# Ensure parent directory exists
331+
self._ensure_parent_directory_exists(remote_path)
332+
333+
# Create the file
330334
output, error = self.execute_command("echo '{0}' > {1}".format(file_data, remote_path))
331335

336+
def _ensure_parent_directory_exists(self, file_path):
337+
# Extract parent directory from file path
338+
parent_dir = os.path.dirname(file_path)
339+
340+
# Skip if no parent directory (file is in root)
341+
if not parent_dir or parent_dir == file_path:
342+
return
343+
344+
try:
345+
# Use existing create_directory method which handles both Windows and Unix
346+
self.create_directory(parent_dir)
347+
except Exception as e:
348+
self.log.error(f"Failed to create parent directory {parent_dir}: {e}")
349+
raise
350+
332351
def find_file(self, remote_path, file):
333352
sftp = self._ssh_client.open_sftp()
334353
try:

0 commit comments

Comments
 (0)