我想使用PowerShell PSFTP module通过FTP从另一台服务器下载一些文件夹和文件。我想从指定地址下载所有文件和文件夹。
根据this的答案,我写了下一个脚本:
$User = "xxxxx"
$Password = ConvertTo-SecureString "xxxx" -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential ($User, $Password)
$ftp_server = "ftp://backup.xxxxx.eu"
$ftp_path = "backup_old/xxx/xx_Config_Backup"
$local_path = "D:\Backup\backup_old\xxx"
Set-FTPConnection -Credentials $Credentials -Server $ftp_server -EnableSsl -ignoreCert -UsePassive
Get-FTPChildItem -path $ftp_path -Recurse | Get-FTPItem -localpath $local_path -Overwrite -Verbose #-RecreateFolders
当ftp_path
的文件夹只包含文件时,此脚本可以正常工作。
ContentLength : -1
Headers : {}
SupportsHeaders : True
ResponseUri : ftp://backup.xxxxx.eu/
StatusCode : ClosingData
StatusDescription : 226 Transfer complete.
LastModified : 01.01.0001 0:00:00
BannerMessage : 220 Microsoft FTP Service
WelcomeMessage : 230 User logged in.
ExitMessage : 221 Goodbye.
IsFromCache : False
IsMutuallyAuthenticated : False
ContentType :
VERBOSE: Performing the operation "Download item: 'ftp://backup.xxxxx.eu
/backup_old/xxx/QlikView/xxx.qvw'" on target "".
226 Transfer complete.
VERBOSE: Performing the operation "Download item: 'ftp://backup.xxxxx.eu
/backup_old/xxx/QlikView/xxxFulFillment.qvw'" on target "D:\Backup\backu
p_old\xxx\xxx.qvw".
226 Transfer complete.
但是,当它包含其他文件夹的文件,它会创建一个文件大小为零命名为相同的文件夹和崩溃与550错误。
ContentLength : -1
Headers : {}
SupportsHeaders : True
ResponseUri : ftp://backup.xxxxx.eu/
StatusCode : ClosingData
StatusDescription : 226 Transfer complete.
LastModified : 01.01.0001 0:00:00
BannerMessage : 220 Microsoft FTP Service
WelcomeMessage : 230 User logged in.
ExitMessage : 221 Goodbye.
IsFromCache : False
IsMutuallyAuthenticated : False
ContentType :
VERBOSE: Performing the operation "Download item: 'ftp://backup.xxxxx.eu
/backup_old/xxx/xx_Config_Backup/AlertSender'" on target "".
Get-FTPItem : Exception calling "GetResponse" with "0" argument(s): "The remote
server returned an error: (550) File unavailable (e.g., file not found, no acc
ess)."
At C:\PS_Scrips\PSFTP_1.ps1:13 char:45
+ ... -Recurse | Get-FTPItem -localpath $local_path -Overwrite -Verbose #- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExcep
tion
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio
n,Get-FTPItem
请帮助我了解问题的原因并解决它。谢谢。
另外。
1.添加-RecreateFolders
:
Get-FTPChildItem -path $ftp_path -Recurse | Get-FTPItem -localpath $local_path -Overwrite -Verbose -RecreateFolders
导致了同样的错误
Get-FTPItem:使用“0”参数调用“GetResponse”时出现异常:“远程服务器返回错误:(550)文件不可用(e.例如,未找到文件,无法访问)。“在C:\PS_Scrips\PSFTP_1。ps1:13 char:45 + .... -递归|Get-FTPItem -localpath $local_path -Overwrite -Verbose -R。.. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~未指定:(:)[Write-Error],WriteErrorExcep tion + FullyQualifiedErrorId:Microsoft.PowerShell.命令.WriteErrorExceptio n,Get-FTPItem1.仅执行
Get-FTPChildItem -path $ftp_path -Recurse`返回https://pastebin.com/t9F5Th59
- 2023/04/07它坏了,但我不知道为什么。
Get-FTPChildItem -path $ftp_path -Recurse |
Where-Object { $_.Dir -ne "DIR" } |
Get-FTPItem -localpath $local_path -Overwrite -Verbose -RecreateFolders
再次得到相同的错误:
Get-FTPChildItem : Exception calling "GetResponse" with "0" argument(s): "The remote serve
r returned an error: (550) File unavailable (e.g., file not found, no access)."
At line:14 char:1
+ Get-FTPChildItem -path $ftp_path -Recurse |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-FTPCh
ildItem
1条答案
按热度按时间z2acfund1#
您可能需要过滤掉目录条目: