powershell - 在powershell中通过PSFTP下载文件
问题描述
我有一个脚本需要从 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 "".
知道如何解决吗?
解决方案
推荐阅读
- python - 为什么输入为 4 时乘积为 24?
- aframe - 我可以在框架中插入 360 度全景照片并与视频和其他工作人员一起工作吗?
- python-3.x - 替换字符串中的特定“var”
- django - Wagtail 根页面不呈现正文内容
- android - 为安卓汽车模拟器设置代理
- java - 如何将文本文件读入固定大小的字符串数组
- testing - 在 ROBOT 框架的变量中添加 Json 数据
- prometheus - 如何在 Spring Cloud Dataflow Server 上使用 /management/prometheus
- python - 将多个操作应用于函数中的单个数据帧的执行方式?
- swift - 点击标签栏项目时快速禁用pop vc动画