I want to check if some file exists on FTP server. I wrote code with Test-Path
but it's not working. Then I wrote code to get FTP server file size, but it's not working either.
My code
function File-size()
{
Param ([int]$size)
if($size -gt 1TB) {[string]::Format("{0:0.00} TB ",$size /1TB)}
elseif($size -gt 1GB) {[string]::Format("{0:0.00} GB ",$size/1GB)}
elseif($size -gt 1MB) {[string]::Format("{0:0.00} MB ",$size/1MB)}
elseif($size -gt 1KB) {[string]::Format("{0:0.00} KB ",$size/1KB)}
elseif($size -gt 0) {[string]::Format("{0:0.00} B ",$size)}
else {""}
}
$urlDest = "ftp://ftpxyz.com/folder/ABCDEF.XML"
$sourcefilesize = Get-Content($urlDest)
$size = File-size($sourcefilesize.length)
Write-Host($size)
This code is not working.
ERROR
Get-Content : Cannot find drive. A drive with the name 'ftp' does not exist.At C:\documents\upload-file.ps1:67 char:19 + $sourcefilesize = Get-Item($urlDest) + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (ftp:String) [Get-Content], DriveNotFoundException + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetContentCommand
Any idea how to solve this error? Is there any way I can check some exists into FTP server? Any clue regarding this will be helpful.