I have a powershell script that I am useing and I cannot download a file. I recieve the error "Can't get attributes of file..." and inside my log file it says:
<message>Can't get attributes of file '/ /download/100_MBytes.txt'.</message>
<message>Could not retrieve file information</message>
<message>SIZE: Not owner</message
But I am able to download the file using the GUI. What could cause this? I am using the path "/download/<filename>" but when I go into the GUI the root folder is just "/", could this be the cause of it? My other servers have the path "/home/...". I have attached my powershell script and my log file. Note: I have removed all of the login information due to it being confidential.
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Session.FileTransferProgress event handler
function FileTransferProgress
{
param($e)
# New line for every new file
if (($script:lastFileName -ne $Null) -and
($script:lastFileName -ne $e.FileName))
{
Write-Host
}
# Print transfer progress
Write-Host -NoNewline ("`r{0} ({1:P0})" -f $e.FileName, $e.FileProgress)
# Remember a name of the last file reported
$script:lastFileName = $e.FileName
}
# Main script
$script:lastFileName = $Null
try
{
Write-Host "Please wait while startup procedures run"
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::ftp
$sessionOptions.HostName = "xxx"
$sessionOptions.UserName = "xxxx"
$sessionOptions.Password = "xxxx"
$sessionOptions.FtpMode = [WinSCP.FtpMode]::passive
$sessionOptions.AddRawSettings("SendBuf","4096");
#$sessionOptions.AddRawSettings("Compression","1");
#$sessionOptions.AddRawSettings("Cipher","blowfish,aes,3des,WARN,arcfour,des");
#$sessionOptions.AddRawSettings("Cipher","blowfish");
#$sessionOptions.AddRawSettings("Compression","1");
#$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
$session = New-Object WinSCP.Session
try
{
# Will continuously report progress of transfer
$session.add_FileTransferProgress( { FileTransferProgress($_) } )
# Connect
$session.Open($sessionOptions)
$session.DebugLogPath = "WinSCP.log"
$remotePath = "/download/100_MBytes.txt"
$localPath = "C:\download\100_MBytes.txt"
# Force binary transfer
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Ascii
Write-Host "Starting download"
$start = Get-Date # Get start time
#$directory = $session.ListDirectory("/download")
#foreach ($fileInfo in $directory.Files)
#{
# Write-Host ("{0} with size {1}, permissions {2} and last modification at {3}" -f
# $fileInfo.Name, $fileInfo.Length, $fileInfo.FilePermissions, $fileInfo.LastWriteTime)
#}
# Download the file and throw on any error
$session.GetFiles($remotePath, $localPath).Check()
# Get end time and calculate throughput
$duration = (Get-Date) - $start
$size = (Get-Item $localPath).Length
$sizeInKb = (Get-Item $localPath).Length / 1024
$speed = $sizeInKb / $duration.TotalSeconds
Write-Host
Write-Host ("Downloaded file {0} to {1}" -f $remotePath, $localPath)
Write-Host ("Size {0:N0} B | Time {1:hh\:mm\:ss}" -f $size, $duration)
Write-Host ("Speed {0:N0} KB/s" -f $speed)
}
finally
{
# Terminate line after the last file (if any)
if ($script:lastFileName -ne $Null)
{
Write-Host
}
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}