我需要自动化一个FTP进程,该进程从前一天下载最新文件,这些文件都有不同的名称,并且都以* 1.DAT扩展名结尾 .

我在传递过程中使用FTP客户端模块取得了真正的成功,这是我在使用FTP上传和下载文件时通常使用的 . 我遇到的问题是,这与-Credentials开关一起使用并且期望密码被加密,不在我控制下的目标ftp服务器在传递给服务器时不理解credentails对象并且失败了550错误

我在这个网站上看到过很多关于在PowerShell中使用FTP的帖子,但是在获取前几天的文件方面似乎没有真正做我想做的事情 .

有谁可以帮忙

谢谢

代码请求

`尝试

{Add-Type -Path WinSCPnet.dll

# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::ftp
$sessionOptions.HostName = "IPServer"
$sessionOptions.UserName = "username"
$sessionOptions.Password = "Password"
$sessionOptions.PortNumber = 21 
#$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"



$session = New-Object WinSCP.Session
$session.XmlLogPath = "D:\scripts\Xml.log"
#$session.SessionLogPath = "D:\scripts\Logs\Session.log"


$date = Get-Date
$date1 =$date.AddDays(-1)
$date2str = $date1.ToString("yyyyMMdd")

try
{
    # Connect
    $session.Open($sessionOptions)

    $localPath = "D:\Eastcoast\Input\Data\Barcode_files"
    $remotePath = "/"

    # Gel list of files in the directory
    $directoryInfo = $session.ListDirectory($remotePath)

    # Select the most recent file
    $latest = $directoryInfo.Files | Where-Object { -not $_.IsDirectory}

        Foreach ($file in $latest) { 
        $filedate = $file.LastWriteTime.ToString("yyyyMMdd")
        If ( $filedate -eq $date2str) { $session.GetFiles($session.EscapeFileMask($remotePath + $latest.Name), $localPath).Check()}

        }`