diff --git a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php
index 4b68c237b911e8ba4f96bad8557be4d80d3472b6..26fd98b342f378c4c1eb38455242fe2d886e18de 100644
--- a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php
+++ b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php
@@ -41,6 +41,27 @@ abstract class FileTransfer {
    */
   protected $port;
 
+  /**
+   * Full path to directory where file-transfer is restricted to.
+   *
+   * @var string
+   */
+  protected $jail;
+
+  /**
+   * Path to connection chroot.
+   *
+   * @var string|false|null
+   */
+  private $chrootPath;
+
+  /**
+   * The instantiated connection object.
+   *
+   * @var object|false|null
+   */
+  private $connectionHandle;
+
   /**
    * Constructs a Drupal\Core\FileTransfer\FileTransfer object.
    *
@@ -93,12 +114,49 @@ public static function factory($jail, $settings) {
   public function __get($name) {
     if ($name == 'connection') {
       $this->connect();
-      return $this->connection;
+      return $this->connectionHandle;
     }
 
     if ($name == 'chroot') {
       $this->setChroot();
-      return $this->chroot;
+      return $this->chrootPath;
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __set(string $name, $value): void {
+    if ($name == 'connection') {
+      $this->connectionHandle = $value;
+    }
+    elseif ($name == 'chroot') {
+      $this->chrootPath = $value;
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __isset(string $name): bool {
+    if ($name == 'connection') {
+      return isset($this->connectionHandle);
+    }
+    if ($name == 'chroot') {
+      return isset($this->chrootPath);
+    }
+    return FALSE;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __unset(string $name): void {
+    if ($name == 'connection') {
+      unset($this->connectionHandle);
+    }
+    elseif ($name == 'chroot') {
+      unset($this->chrootPath);
     }
   }
 
@@ -235,8 +293,8 @@ final protected function fixRemotePath($path, $strip_chroot = TRUE) {
     // Strip out windows drive letter if its there.
     $path = preg_replace('|^([a-z]{1}):|i', '', $path);
     if ($strip_chroot) {
-      if ($this->chroot && strpos($path, $this->chroot) === 0) {
-        $path = ($path == $this->chroot) ? '' : substr($path, strlen($this->chroot));
+      if ($this->chrootPath && strpos($path, $this->chrootPath) === 0) {
+        $path = ($path == $this->chrootPath) ? '' : substr($path, strlen($this->chrootPath));
       }
     }
     return $path;
diff --git a/core/modules/system/tests/src/Functional/FileTransfer/TestFileTransfer.php b/core/modules/system/tests/src/Functional/FileTransfer/TestFileTransfer.php
index 1860812babf14fdd6096b0ee905404fd6c9a5178..2794ea98b25ad0d4eaeeaa687c66da1b32824dac 100644
--- a/core/modules/system/tests/src/Functional/FileTransfer/TestFileTransfer.php
+++ b/core/modules/system/tests/src/Functional/FileTransfer/TestFileTransfer.php
@@ -45,8 +45,9 @@ public static function factory($jail, $settings) {
   }
 
   public function connect() {
-    $this->connection = new MockTestConnection();
-    $this->connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/";
+    $connection = new MockTestConnection();
+    $connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/";
+    $this->connection = $connection;
   }
 
   public function copyFileJailed($source, $destination) {