Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Script didn't save the downloaded files correct

You never use $localPathImport in your code. Maybe you wanted to use it, where you actually use undefined $localPath.

Also, what do you expect the $zeit = Get-Date >> ... to do? Imo, the $zeit = Get-Date does not output anything. Possibly you meant to do Get-Date >> ... only.

If you need further help, please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
piti87

Script didn't save the downloaded files correct

I have the following script (PowerShell)

param (
    $localPathImport = "C:\application\Data\12345\Import\SAP\PROJEKTE\",
    $remotePath = "/test/download/*"
)
 
try
{
    # WinSCP .NET assembly laden
    Add-Type -Path "WinSCPnet.dll"
 
    # Session Einstellungen
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "host.net"
        UserName = "user_ftp"
        SshHostKeyFingerprint = "xxx"
        SshPrivateKeyPath = "C:\application\AddOns\File_upload\ssh\private_key_cust01_new.ppk"
    }
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Verbinden
        $session.Open($sessionOptions)
 
        # Download
        $transferResult = $session.GetFiles($remotePath, $localPath)
               
        foreach ($transfer in $transferResult.Transfers)
        {
            # Download erfolgt oder Error?
            if ($transfer.Error -eq $Null)
            {
                $zeit = Get-Date >> C:\application\AddOns\File_upload\download_sap_projektstamm_log.txt
                Write-output "Download von $($transfer.FileName) erfolgt!" >> C:\application\AddOns\File_upload\download_sap_projektstamm_log.txt
            }
            else
            {
                $zeit = Get-Date >> C:\application\AddOns\File_upload\download_sap_projektstamm_error.txt
                Write-output "Download von $($transfer.FileName) fehlgeschlagen: $($transfer.Error.Message)" >> C:\application\AddOns\File_upload\download_sap_projektstamm_error.txt
            }
        }
               
        # löschen aus Verzeichnis               
        $session.RemoveFiles($remotePath)
    }
    finally
    {
        # Verbindung trennen
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    $zeit = Get-Date >> C:\application\AddOns\File_upload\download_sap_projektstamm_error.txt
    Write-output "Error: $($_.Exception.Message)" >> C:\application\AddOns\File_upload\download_sap_projektstamm_error.txt
    exit 1
}


The script does not save the files in the $localPathImport.
The three files on the FTP server are:
project0000000000001319

project0000000000001320
project0000000000001321

It makes a file named %22 in the directory, where is the winscp.exe located. And in this file %22, the content of the three files are combined.

Any ideas?