我想要检查FTP服务器上是否存在某个文件。我使用了Test-Path
的代码,但它没有起作用。然后我又写了一段代码来获取FTP服务器上的文件大小,但也没能起到作用。
我的代码:
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)
这段代码无法工作。
错误
Get-Content:找不到驱动器。名称为“ftp”的驱动器不存在。位置:C:\documents\upload-file.ps1:67 字符:19 + $sourcefilesize = Get-Item($urlDest) + ~~~~~~~~~~~~~~~~~~~~~ + 类别信息 : ObjectNotFound: (ftp:String) [Get-Content],DriveNotFoundException + 完全合格的错误 ID:DriveNotFound,Microsoft.PowerShell.Commands.GetContentCommand
有什么解决此错误的方法吗?有没有办法检查FTP服务器中是否存在某些内容?任何关于此问题的线索都将是有帮助的。