diff --git a/src/data_transfer.cpp b/src/data_transfer.cpp
index b2fa6f587ec5ddf24e6aa71fa6100f2291694071..f6955119965c20c8df6b13571b710e2b41c407ae 100644
--- a/src/data_transfer.cpp
+++ b/src/data_transfer.cpp
@@ -287,9 +287,13 @@ IncomingFileTransfer::close() noexcept
     } catch (...) {}
 
     fout_.close();
-    RING_DBG() << "[FTP] file closed with size " << info_.bytesProgress;
 
-    emit(DRing::DataTransferEventCode::finished);
+    RING_DBG() << "[FTP] file closed, rx " << info_.bytesProgress
+               << " on " << info_.totalSize;
+    if (std::size_t(info_.bytesProgress) == info_.totalSize)
+        emit(DRing::DataTransferEventCode::finished);
+    else
+        emit(DRing::DataTransferEventCode::closed_by_host);
 }
 
 void
diff --git a/src/ftp_server.cpp b/src/ftp_server.cpp
index 6388e3164faa9d14b27b312f6e86e2483e72103f..501170477a569b983542bba1e00a7fd9cb786c3a 100644
--- a/src/ftp_server.cpp
+++ b/src/ftp_server.cpp
@@ -93,7 +93,8 @@ FtpServer::write(const std::vector<uint8_t>& buffer)
                     auto count = headerStream_.gcount();
                     if (!count)
                         continue;
-                    out_->write(reinterpret_cast<const uint8_t*>(&line_[0]), count);
+                    if (out_)
+                        out_->write(reinterpret_cast<const uint8_t*>(&line_[0]), count);
                     rx_ += count;
                     if (rx_ >= fileSize_) {
                         closeCurrentFile();
@@ -107,7 +108,8 @@ FtpServer::write(const std::vector<uint8_t>& buffer)
             break;
 
         case FtpState::READ_DATA:
-            out_->write(&buffer[0], buffer.size());
+            if (out_)
+                out_->write(&buffer[0], buffer.size());
             rx_ += buffer.size();
             if (rx_ >= fileSize_) {
                 closeCurrentFile();