Upload files using SFTP in Python, but create directories if path doesn’t exist
SFTP supports the usual FTP commands (chdir, mkdir, etc…), so use those: sftp = paramiko.SFTPClient.from_transport(transport) try: sftp.chdir(remote_path) # Test if remote_path exists except IOError: sftp.mkdir(remote_path) # Create remote_path sftp.chdir(remote_path) sftp.put(local_path, ‘.’) # At this point, you are in remote_path in either case sftp.close() To fully emulate mkdir -p, you can work through remote_path recursively: import … Read more