Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在powershell中通过PSFTP下载文件_Powershell_Ftp - Fatal编程技术网

在powershell中通过PSFTP下载文件

在powershell中通过PSFTP下载文件,powershell,ftp,Powershell,Ftp,我有一个脚本,需要从ftp目录下载文件。在此目录中,我有两个不需要的文件夹和四个需要使用此脚本下载的.log文件: # Import Custom PSFTP Module (PowerShell FTP). Import-Module PSFTP $FtpServer = "***.***.***.***" $User = "USER" $PWD = "****" $Password = ConvertTo-SecureString $Pwd -AsPlainText -Force $Ft

我有一个脚本,需要从ftp目录下载文件。在此目录中,我有两个不需要的文件夹和四个需要使用此脚本下载的.log文件:

# Import Custom PSFTP Module (PowerShell FTP).
Import-Module PSFTP

$FtpServer = "***.***.***.***"
$User = "USER"
$PWD = "****"
$Password =  ConvertTo-SecureString $Pwd -AsPlainText -Force
$FtpCredentials = New-Object System.Management.Automation.PSCredential ($User, $Password)
Set-FTPConnection -Credentials $FtpCredentials -Server $FtpServer -Session MyFtpSession
$FtpSession = Get-FTPConnection -Session MyFtpSession
$ServerPath = "/sd0/"
$LocalPath  = "C:\ftp"
$fileList   = Get-FTPChildItem -Session $FtpSession -Path $ServerPath -Filter "*.log"
foreach ($element in $fileList ) {
 $filename = $ServerPath  + $element.name
 Get-FTPItem  -Session $FtpSession  -Path $filename -LocalPath $LocalPath
我有以下输出:

ContentLength           : -1
Headers                 : {}
SupportsHeaders         : True
ResponseUri             : ftp://***.***.***.***/
StatusCode              : ClosingData
StatusDescription       : 226 Transfer complete

LastModified            : 1.1.0001 г. 00:00:00 ч.
BannerMessage           : 220 FTP server ready.

WelcomeMessage          : 230 Login OK

ExitMessage             : 221 Bye

IsFromCache             : False
IsMutuallyAuthenticated : False
ContentType             :
本地目录中没有下载的文件。在详细模式下,它表示:

VERBOSE: Performing the operation "Download item: 'ftp://***.***.***.***/sd0/file1.log'" on target "".
VERBOSE: Performing the operation "Download item: 'ftp://***.***.***.***/sd0/file2.log'" on target "".
VERBOSE: Performing the operation "Download item: 'ftp://***.***.***.***/sd0/file3.log'" on target "".
VERBOSE: Performing the operation "Download item: 'ftp://***.***.***.***/sd0/file4.log'" on target "".
知道如何修复它吗?

“导入自定义PSFTP模块”您应该检查此模块的文档以确保正确使用,如果正确,请联系创建者以获得帮助。“导入自定义PSFTP模块”您应该检查此模块的文档以确保正确使用,如果正确,联系创建者以获得帮助。