Topic "SFTP and Powershell: Invalid argument to time encode"

Author Message
Guest




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



Code:
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

Advertisements
cluckinchicken
[View user's profile]

Joined: 2013-09-25
Posts: 4
Location: USA
Sorry, I thought I was logged in when I posted.

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

Code:
$transferResult.Check()
cluckinchicken
[View user's profile]

Joined: 2013-09-25
Posts: 4
Location: USA
It's still failing actually. Blimey!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24538
Location: Prague, Czechia
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.

_________________
Martin Prikryl
cluckinchicken
[View user's profile]

Joined: 2013-09-25
Posts: 4
Location: USA
I've sent my log to you. Thanks!
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License