diff --git a/src/ftp_server.cpp b/src/ftp_server.cpp
index a44fcba24f2091294c84cc30d1e8aec23175a27b..84f2f37af4e918ffaef3104059b238d6bab22730 100644
--- a/src/ftp_server.cpp
+++ b/src/ftp_server.cpp
@@ -112,10 +112,9 @@ FtpServer::startNewFile()
 void
 FtpServer::closeCurrentFile()
 {
-    if (out_.stream) {
+    if (out_.stream && not closed_.exchange(true)) {
         out_.stream->close();
         out_.stream.reset();
-        closed_ = true;
     }
 }
 
@@ -123,8 +122,7 @@ bool
 FtpServer::read(std::vector<uint8_t>& buffer) const
 {
     if (!out_.stream) {
-        if (closed_) {
-            closed_ = false;
+        if (closed_.exchange(false)) {
             if (rx_ < fileSize_) {
                 buffer.resize(4);
                 buffer[0] = 'N';
diff --git a/src/ftp_server.h b/src/ftp_server.h
index 8269570d6bcc09f7a9b14fcd40e96dbf8950a19e..137238a4cdcfa18eea34415188773bc80ff577ce 100644
--- a/src/ftp_server.h
+++ b/src/ftp_server.h
@@ -81,7 +81,7 @@ private:
     std::stringstream headerStream_;
     std::string displayName_;
     std::array<char, 1000> line_;
-    mutable bool closed_ {false};
+    mutable std::atomic_bool closed_ {false};
     mutable bool go_ {false};
     FtpState state_ {FtpState::PARSE_HEADERS};
 
diff --git a/src/jamidht/channeled_transfers.cpp b/src/jamidht/channeled_transfers.cpp
index f0da0a279b3c7599e5aff684e62d6b4d02ef860e..ba18b5c5a90944a78ef4a0ddfa2787a7271f2d3c 100644
--- a/src/jamidht/channeled_transfers.cpp
+++ b/src/jamidht/channeled_transfers.cpp
@@ -40,6 +40,7 @@ ChanneledOutgoingTransfer::~ChanneledOutgoingTransfer()
     channel_->setOnRecv({});
     file_->setOnRecv({});
     channel_->shutdown();
+    file_->close();
 }
 
 std::string
@@ -99,14 +100,8 @@ ChanneledIncomingTransfer::~ChanneledIncomingTransfer()
 {
     channel_->setOnRecv({});
     channel_->shutdown();
-}
-
-DRing::DataTransferId
-ChanneledIncomingTransfer::id() const
-{
     if (ftp_)
-        return ftp_->getId();
-    return 0;
+        ftp_->close();
 }
 
 } // namespace jami
\ No newline at end of file
diff --git a/src/jamidht/channeled_transfers.h b/src/jamidht/channeled_transfers.h
index 1054dc20b655d1c59fd5dd698604f811b86b148f..56c4f7f862b2b2c657713dba9c49699897480c35 100644
--- a/src/jamidht/channeled_transfers.h
+++ b/src/jamidht/channeled_transfers.h
@@ -53,7 +53,6 @@ public:
                               const std::shared_ptr<FtpServer>& ftp,
                               OnStateChangedCb&& cb);
     ~ChanneledIncomingTransfer();
-    DRing::DataTransferId id() const;
 
 private:
     std::shared_ptr<FtpServer> ftp_;
diff --git a/src/jamidht/p2p.cpp b/src/jamidht/p2p.cpp
index aca42ce804bb4f26ac5e96d23fb53b72be4b145c..30c57e540c92ff9c9a3aa46d680e7cbf29541601 100644
--- a/src/jamidht/p2p.cpp
+++ b/src/jamidht/p2p.cpp
@@ -837,20 +837,14 @@ DhtPeerConnector::Impl::cancelChanneled(const std::string& peerId, const DRing::
         if (!shared)
             return;
         // Cancel outgoing files
-        DRing::DataTransferId finalId = tid;
         {
             std::lock_guard<std::mutex> lk(shared->channeledIncomingMtx_);
-            auto it = shared->channeledIncoming_.find(tid);
-            if (it != shared->channeledIncoming_.end()) {
-                finalId = it->second->id();
-            }
-            shared->channeledIncoming_.erase(tid);
+            auto it = shared->channeledIncoming_.erase(tid);
         }
         {
             std::lock_guard<std::mutex> lk(shared->channeledOutgoingMtx_);
             shared->channeledOutgoing_.erase(tid);
         }
-        Manager::instance().dataTransfers->close(finalId);
     });
 }
 
@@ -977,7 +971,6 @@ DhtPeerConnector::requestConnection(
                                 shared->channeledOutgoing_.erase(outgoingTransfers);
                         }
                     }
-                    Manager::instance().dataTransfers->close(tid);
                 });
             });
             // Cancel via DHT because we will use the channeled path
@@ -1080,17 +1073,9 @@ DhtPeerConnector::onIncomingConnection(const std::string& peer_id,
             if (!shared)
                 return;
             // Cancel incoming files
-            DRing::DataTransferId internalId = 0;
-            {
-                std::lock_guard<std::mutex> lk(shared->channeledIncomingMtx_);
-                auto it = shared->channeledIncoming_.find(tid);
-                if (it != shared->channeledIncoming_.end())
-                    internalId = it->second->id();
-                shared->channeledIncoming_.erase(tid);
-            }
-            if (internalId != 0) {
-                Manager::instance().dataTransfers->close(internalId);
-            }
+            // Note: erasing the channeled transfer will close the file via ftp_->close()
+            std::lock_guard<std::mutex> lk(shared->channeledIncomingMtx_);
+            shared->channeledIncoming_.erase(tid);
         });
     });
 }