Skip to content

Commit

Permalink
Merge pull request #506 from MVKozlov/SFTPPathInformation
Browse files Browse the repository at this point in the history
Add Sftp path information.
  • Loading branch information
darkoperator authored Feb 4, 2023
2 parents 7f6da80 + caa1b30 commit 3076048
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 30 deletions.
1 change: 1 addition & 0 deletions Posh-SSH/Posh-SSH.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ FunctionsToExport = @('Get-PoshSSHModVersion',
'Get-SFTPContent',
'Get-SFTPLocation',
'Get-SFTPPathAttribute',
'Get-SFTPPathInformation',
'Get-SFTPSession',
'Get-SSHPortForward',
'Get-SSHSession',
Expand Down
72 changes: 72 additions & 0 deletions Posh-SSH/Posh-SSH.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,78 @@ function Set-SFTPPathAttribute
}
}

# .ExternalHelp Posh-SSH.psm1-Help.xml
function Get-SFTPPathInformation
{
[CmdletBinding()]
[OutputType([Renci.SshNet.Sftp.SftpFileSytemInformation])]
Param
(
[Parameter(Mandatory=$true,
ParameterSetName = 'Index',
ValueFromPipelineByPropertyName=$true,
Position=0)]
[Alias('Index')]
[Int32[]]
$SessionId,

[Parameter(Mandatory=$true,
ParameterSetName = 'Session',
ValueFromPipeline=$true,
Position=0)]
[Alias('Session')]
[SSH.SFTPSession[]]
$SFTPSession,

[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=1)]
[string]
$Path
)

Begin
{
$ToProcess = @()
switch($PSCmdlet.ParameterSetName)
{
'Session'
{
$ToProcess = $SFTPSession
}

'Index'
{
foreach($session in $Global:SFTPSessions)
{
if ($SessionId -contains $session.SessionId)
{
$ToProcess += $session
}
}
}
}
}
Process
{
foreach($session in $ToProcess)
{

if (Test-SFTPPath -SFTPSession $session -Path $Path)
{
$session.Session.GetStatus($Path)
}
else
{
throw "Path $($Path) does not exist on the target host."
}
}
}
End
{
}
}

# .ExternalHelp Posh-SSH.psm1-Help.xml
function New-SFTPSymlink
{
Expand Down
176 changes: 176 additions & 0 deletions Posh-SSH/en-US/Posh-SSH.psm1-Help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,182 @@ CentOS Linux release 7.0.1406 (Core)</dev:code>
</maml:navigationLink>
</command:relatedLinks>
</command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<command:details>
<command:name>Get-SFTPPathInformation</command:name>
<command:verb>Get</command:verb>
<command:noun>SFTPPathInformation</command:noun>
<maml:description>
<maml:para>Get the filesystem information for a specified path in a SFTP session.</maml:para>
</maml:description>
</command:details>
<maml:description>
<maml:para>Get the filesystem information for a specified path in a SFTP session.</maml:para>
</maml:description>
<command:syntax>
<command:syntaxItem>
<maml:name>Get-SFTPPathInformation</maml:name>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="0" aliases="Index">
<maml:name>SessionId</maml:name>
<maml:description>
<maml:para>SFTP Session Id of an exiting session.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Int32[]</command:parameterValue>
<dev:type>
<maml:name>Int32[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="1" aliases="none">
<maml:name>Path</maml:name>
<maml:description>
<maml:para>Path to get information on.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
<command:syntaxItem>
<maml:name>Get-SFTPPathInformation</maml:name>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="Session">
<maml:name>SFTPSession</maml:name>
<maml:description>
<maml:para>SFTP Session Object of an exiting session.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">SftpSession[]</command:parameterValue>
<dev:type>
<maml:name>SftpSession[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="1" aliases="none">
<maml:name>Path</maml:name>
<maml:description>
<maml:para>Path to get information on.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="0" aliases="Index">
<maml:name>SessionId</maml:name>
<maml:description>
<maml:para>SFTP Session Id of an exiting session.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Int32[]</command:parameterValue>
<dev:type>
<maml:name>Int32[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="1" aliases="none">
<maml:name>Path</maml:name>
<maml:description>
<maml:para>Path to get information on.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="Session">
<maml:name>SFTPSession</maml:name>
<maml:description>
<maml:para>SFTP Session Object of an exiting session.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">SftpSession[]</command:parameterValue>
<dev:type>
<maml:name>SftpSession[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters>
<command:inputTypes>
<command:inputType>
<dev:type>
<maml:name>System.Int32[]</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:inputType>
<command:inputType>
<dev:type>
<maml:name>System.String</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:inputType>
<command:inputType>
<dev:type>
<maml:name>SSH.SftpSession[]</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:inputType>
</command:inputTypes>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>Renci.SshNet.Sftp.SftpFileSytemInformation</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
<maml:alertSet>
<maml:alert>
<maml:para></maml:para>
</maml:alert>
</maml:alertSet>
<command:examples>
<command:example>
<maml:title>-------------------------- EXAMPLE 1 --------------------------</maml:title>
<dev:code>Get-SFTPPathInformation -SessionId 0 -Path "/tmp"

FileSystemBlockSize : 4096
BlockSize : 4096
TotalBlocks : 238077722
FreeBlocks : 197779304
AvailableBlocks : 188098654
TotalNodes : 60599664
FreeNodes : 60257137
AvailableNodes : 60257137
Sid : 80809960231584831832
IsReadOnly : False
SupportsSetUid : True
MaxNameLenght : 255</dev:code>
<dev:remarks>
<maml:para></maml:para>
</dev:remarks>
</command:example>
</command:examples>
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>Online Version:</maml:linkText>
<maml:uri>https://github.com/darkoperator/Posh-SSH/tree/master/docs</maml:uri>
</maml:navigationLink>
</command:relatedLinks>
</command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<command:details>
<command:name>Get-SFTPSession</command:name>
Expand Down
Loading

0 comments on commit 3076048

Please sign in to comment.