PowerShell / PowerShell/Win32-OpenSSH

`scp` locks the output file but it shouldn't

Open
#2,246 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-SCP Issue-Upstream Parity
Dominant language
No language data
Stars
8.3k
Forks
819
PR merge metrics
No merged PRs in 30d

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.
Steps to reproduce
  1. In CMD or PowerShell, download a big file into Windows with `scp
scp "hostname:big_input_file" big_output_file
  1. In another PowerShell terminal, while it's downloading, try to access it:
Get-Content big_output_file -TotalCount 2KB
  1. See the following error:
Get-Content: The process cannot access the file 'C:\Users\Robby\Desktop\big_output_file' because it is being used by another process.
Expected behavior
I'm trying to download a big file with `scp` and read it during the download in another program. This works with `scp` in WSL, but not in Windows.
Actual behavior
In Windows, I can't read from the file because it gets locked by `scp`.
Error details
Exception             :
    Type       : System.IO.IOException
    TargetSite :
        Name          : CreateFile
        DeclaringType : [Microsoft.Win32.SafeHandles.SafeFileHandle]
        MemberType    : Method
        Module        : System.Private.CoreLib.dll
    Message    : The process cannot access the file 'C:\Users\Robby\Desktop\big_output_file' because it is being
used by another process.
    Source     : System.Private.CoreLib
    HResult    : -2147024864
    StackTrace :
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access,
FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare
share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share,
FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access,
FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter.CreateStreams(String filePath, String streamName,
FileMode fileMode, FileAccess fileAccess, FileShare fileShare, Encoding fileEncoding)
   at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter..ctor(String path, String streamName, FileMode mode,
FileAccess access, FileShare share, Encoding encoding, Boolean usingByteEncoding, Boolean waitForChanges,
CmdletProvider provider, Boolean isRawStream)
   at Microsoft.PowerShell.Commands.FileSystemProvider.GetContentReader(String path)
TargetObject          : C:\Users\Robby\Desktop\big_output_file.mkv
CategoryInfo          : ReadError: (C:\Users\Robby\Desktop\big_output_file:String) [Get-Content], IOException
FullyQualifiedErrorId : GetContentReaderIOError,Microsoft.PowerShell.Commands.GetContentCommand
InvocationInfo        :
    MyCommand        : Get-Content
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 15
    Line             : Get-Content $env:file -TotalCount 2KB
    Statement        : Get-Content $env:file -TotalCount 2KB
    PositionMessage  : At line:1 char:1
                       + Get-Content $env:file -TotalCount 2KB
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Get-Content
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
      0
      1
Environment data
Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Version

OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2

Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the Windows scp command and the PowerShell Get-Content command while downloading a large file. Trace how the Windows client opens the destination output file and compare the behavior with scp in WSL. Done means another process can read the partially downloaded file during the transfer without the reported sharing violation.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, shell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.