SFTP and Powershell: Invalid argument to time encode

Advertisement

Guest

SFTP and Powershell: Invalid argument to time encode

Using WinSCP v5.1.2 build 2816
Powershell 2.0

I keep getting a failure on uploads. My SFTP function is below. I've read that it could be due to high timeout, but mine isn't set very high. Anyone have any ideas?

* 2013-09-25 08:48:56.406 (ECommand) Copying files to remote side failed.
* 2013-09-25 08:48:56.406 Invalid argument to time encode
< 2013-09-25 08:48:56.406 Script: Copying files to remote side failed.
< 2013-09-25 08:48:56.406 Script: Invalid argument to time encode
. 2013-09-25 08:48:56.406 Script: Failed
> 2013-09-25 08:48:56.516 Script: exit
. 2013-09-25 08:48:56.516 Script: Exit code: 1
. 2013-09-25 08:48:56.516 Closing connection.
. 2013-09-25 08:48:56.516 Sending special code: 12



Function sftp { 
   Try   {
      [Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\WinSCP\WinSCP.dll") | Out-Null 
      $sessionOptions = New-Object WinSCP.SessionOptions
      $sessionOptions.Protocol = [WinSCP.Protocol]::sftp
      $sessionOptions.PortNumber = 22
      $sessionOptions.Timeout = "120"
      $sessionOptions.HostName = $host
      $sessionOptions.UserName = $user
      $SessionOptions.SshPrivateKeyPath = "prv.ppk"
      $sessionOptions.SshHostKeyFingerprint = $fingerprint
      $session = New-Object WinSCP.Session
      
      $exportFile = dir "D:\export" | Select -ExpandProperty name
      $arrExport = @()
      ForEach ($file in $exportFile) {
         $arrExport += ("D:\export\" + $file)
      }
      $session.SessionLogPath =  ("D:\TestSFTP.log")
      Try {
         $session.Open($sessionOptions)
         $transferOptions = New-Object WinSCP.TransferOptions
         $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
         
         ForEach ($ufile in $arrExport) {
             #$transferResult = $session.PutFiles($ufile, "/", $FALSE, $transferOptions)
            $transferResult = $session.PutFiles($ufile, "/")
            $transferResult.Check()
       
            ForEach ($transfer in $transferResult.Transfers)
            {
               Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
            }
         }
      }
      Finally {
         $session.Dispose()
      }
   }
   Catch [Exception] {
      Write-Host $_.Exception.Message
      exit 1
   }
}

sftp

Reply with quote

Advertisement

cluckinchicken
Joined:
Posts:
4
Location:
USA

I think I found the problem

Sorry, I thought I was logged in when I posted.

If I comment this out, uploads seem to work fine. Anyone else experiencing this?

$transferResult.Check()

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: SFTP and Powershell: Invalid argument to time encode

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate 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 may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.

Reply with quote

Advertisement

You can post new topics in this forum