title: Download files via PSFTP in powershell
body: <p>I have a script that need to download files from ftp directory. In this directory I have a couple of folders that i don't need and four .log files that need to be downloaded with this script:</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>I have output:</p>
  
  <pre><code>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             :
  </code></pre>
  
  <p>With no downloaded files in the local directory. In verbose mode it says:</p>
  
  <pre><code>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 "".
  </code></pre>
  
  <p>Any idea how to fix it?</p>