< Back

New-SFTPFileStream

Sat Jan 18, 2020 7:58 pm

NAME New-SFTPFileStream



SYNOPSIS

Create a IO Stream over SFTP for a file on a remote host.





SYNTAX

New-SFTPFileStream [-SessionId] <Int32> [-Path] <String> [-FileMode] <String> [-FileAccess] <String>

[<CommonParameters>]



New-SFTPFileStream [-SFTPSession] <SftpSession> [-Path] <String> [-FileMode] <String> [-FileAccess] <String>

[<CommonParameters>]





DESCRIPTION

Create a IO Stream over SFTP for a file on a remote host.





PARAMETERS

-SessionId <Int32>

SSH Session Id for an existing session.



Required? true

Position? 0

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-Path <String>

Path of file to create a stream for.



Required? true

Position? 1

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-FileMode <String>

Specifies how the operating system should open a file. Options are: * Append - Opens the file if it exists and

seeks to the end of the file, or creates a new file.



* Create - Specifies that the operating system should create a new file.



* CreateNew - Specifies that the operating system should create a new file



* Open - Specifies that the operating system should open an existing file.



* OpenOrCreate - pecifies that the operating system should open a file if it exists; otherwise, a new file

should be





created. * Truncate - Specifies that the operating system should open an existing file. When the file is

opened, it should be truncated so that its size is zero bytes.





Required? true

Position? 2

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-FileAccess <String>

Defines constants for read, write, or read/write access to a file. * Read - Read access to the file. Data can

be read from the file. * ReadWrite - Read and write access to the file. Data can be written to and read from

the file. * Write - Write access to the file. Data can be written to the file.



Required? true

Position? 3

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-SFTPSession <SftpSession>

SFTP Session Object of an exiting session.



Required? true

Position? 0

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

System.Int32





System.String





SSH.SftpSession







OUTPUTS

Renci.SshNet.Sftp.SftpFileStream







NOTES









-------------------------- EXAMPLE 1 --------------------------



$bashhistory = New-SFTPFileStream -SessionId 0 -Path /home/admin/.bash_history -FileMode Open -FileAccess Read



PS C:\\> $bashhistory





CanRead : True

CanSeek : True

CanWrite : False

CanTimeout : True

Length : 830

Position : 0

IsAsync : False

Name : /home/admin/.bash_history

Handle : {0, 0, 0, 0}

Timeout : 00:00:30

ReadTimeout :

WriteTimeout :



PS C:\\> $streamreader = New-Object System.IO.StreamReader -ArgumentList $bashhistory

PS C:\\> while ($streamreader.Peek() -ge 0) {$streamreader.ReadLine()}

ls

exit

ssh-keygen -t rsa

mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

chmod 600 ~/.ssh/authorized_keys

vim /etc/ssh/sshd_config

sudo vim /etc/ssh/sshd_config



PS C:\\>







RELATED LINKS

Online Version: https://github.com/darkoperator/Posh-SS ... aster/docs