Re: 4.3.6 returns error code 1 and 0 bytes transferred
This bug has been added to the tracker:
https://winscp.net/tracker/794
https://winscp.net/tracker/794
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
I just updated to 4.3.6 from 4.3.5
I use scripting and have had no problems going back 4 or 5 versions.
Using Windows 7 Ultimate, SFTP-4 and scripting to MS Server 2008 Std.
I use 2 methods, command line script and sessions.
Sessions returns error code 1, 0 bytes transferred.
Command line returns error code 0, 0 bytes transferred.
Both acutally transfer fine.
This only applies to uploads.
Downloads work fine.
Here arethe code and logs for both methods:
Session protocol = SSH-2
SSH implementation = 1.00 FlowSsh: WinSSHD 5.05
Encryption algorithm = aes
Compression = No
File transfer protocol = SFTP-4
------------------------------------------------------------
Server host key fingerprint
ssh-dss 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
------------------------------------------------------------
Can change permissions = Yes
Can change owner/group = Yes
Can execute arbitrary command = No
Can create symlink/hardlink = Yes/No
Can lookup user groups = No
Can duplicate remote files = No
Can check available space = No
Can calculate file checksum = No
Native text (ASCII) mode transfers = Yes
------------------------------------------------------------
Additional information
The server supports these SFTP extensions:
newline="\r\n"
**************************************************************
This method returns Exit Code 1, says 0 bytes transferred
The file actually transfers fine
*************************************************************
###########################################################################
##
## UPLOAD Text Files to Test Directory on the Server.
##
## Version: 3.3
## Date: June 9, 2011
###########################################################################
########################################################################################
$VersionLine = "Script Version: 3.3 Date: June 9, 2011"
$uploadServer = "xx.com"
$uploadPort = "xx"
$Processor = $Env:Processor_Architecture
$UserName = "xx"
$PWDFile = "C:\xx\xxs\" + $Env:Username + "_" + $UserName + "@" + $uploadServer + ".pwd"
$connector = '@' + $uploadServer + ':' + $uploadPort
########################################################################################
$SaveCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
[System.Globalization.CultureInfo] $NewCulture = "en-US"
[System.Threading.Thread]::CurrentThread.CurrentCulture = $NewCulture
if(Test-Path $PWDFile)
## If the Password file exits for the UserName,
## then read the password and create the Credentials.
{
$Password = Get-Content $PWDFile | ConvertTo-SecureString
$Credential = New-Object System.Management.Automation.PsCredential $UserName,$Password
}
else
## If the Password file does not exist for UserName,
## then query the user for the password and create the password file.
{
$Credential = Get-Credential $UserName
$Credential.Password | ConvertFrom-SecureString | Set-Content $PWDFile
}
$ProgramFiles = [Environment]::GetFolderPath("ProgramFiles")
if ( $Processor -ne "x86" )
{
$ProgramFiles += " (x86)"
}
$ProgramFiles += "\WinSCP\WinSCP.com"
## Winscp session Information
$startInfo = New-Object Diagnostics.ProcessStartInfo
$startInfo.Filename = $ProgramFiles
$startInfo.UseShellExecute = $false
$startInfo.RedirectStandardInput = $true
$startInfo.CreateNoWindow = $true
$startInfo.RedirectStandardOutput = $true
## Create arrays to hold Winscp Sessions and Logs
$winscp = @(1..10)
[String[]]$logfiles = (1..10)
$counter = 1
$winscp[$counter] = [System.Diagnostics.Process]::Start($startInfo)
$winscp[$counter].StandardInput.WriteLine("option echo off")
$winscp[$counter].StandardInput.WriteLine("option batch abort")
$winscp[$counter].StandardInput.WriteLine("option confirm off")
$winscp[$counter].StandardInput.WriteLine("option transfer binary")
$winscp[$counter].StandardInput.WriteLine("option reconnecttime 20")
$winscp[$counter].StandardInput.WriteLine("open " + $Credential.GetNetworkCredential().UserName +":" + $Credential.GetNetworkCredential().Password + $connector)
$winscp[$counter].StandardInput.WriteLine("cd TestDirectory")
$winscp[$counter].StandardInput.WriteLine("lcd C:\TestExitCode")
$winscp[$counter].StandardInput.WriteLine("put -preservetime -nopermissions C:\TestExitCode\Sample.txt")
Write-Host "Opened Winscp Session $counter `n"
$winscp[$counter].StandardInput.Close()
$logfiles[$counter] = $winscp[$counter].StandardOutput.ReadToEnd()
$winscp[$counter].WaitForExit()
$ExitCode = $winscp[$counter].ExitCode
Write-Host "Closed Winscp Session $counter`n"
Write-Host "Session $counter finished with exit code $ExitCode`n"
Write-Host $logfiles[$counter]
************************************************************************************
Here is the log
************************************************************************************
PS C:\JAPAN\Scripts> C:\JAPAN\Scripts\TestExitCode.ps1
Opened Winscp Session 1
Closed Winscp Session 1
Session 1 finished with exit code 1
winscp> option echo off
echo off
winscp> option batch abort
batch abort
winscp> option confirm off
confirm off
winscp> option transfer binary
transfer binary
winscp> option reconnecttime 20
reconnecttime 20
winscp> open xx:xx@xx.com:xx
Searching for host...
Connecting to host...
Authenticating...
Using username "xx".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] xx@xx.com
winscp> cd TestDirectory
/TestDirectory
winscp> lcd C:\TestExitCode
C:\TestExitCode
winscp> put -preservetime -nopermissions C:\TestExitCode\Sample.txt
C:\TestExitCode\Sample.txt | 0 KiB | 0.0 KiB/s | binary | 100%
winscp>
*************************************************************************************
## Another method that returns exit code 0 but still lists 0 bytes transferred
*************************************************************************************
$Command_String = '"option echo off" '
$Command_String += '"option batch abort" '
$Command_String += '"option confirm off" '
$Command_String += '"option transfer binary" '
$Command_String += '"open '
$Command_String += $Credential.GetNetworkCredential().UserName
$Command_String += ':'
$Command_String += $Credential.GetNetworkCredential().Password
$Command_String += '@' + $uploadServer + ':' + $uploadPort + '" '
$Command_String += '"cd TestDirectory" '
$Command_String += '"lcd C:\TestExitCode " '
$Command_String += '"put -preservetime -nopermissions C:\TestExitCode\Sample2.txt" '
$Command_String += '"exit "'
$LogFile = [System.IO.Path]::GetTempFileName()
Write-Host "Connecting to WinSCP `n `n"
& $ProgramFiles /Command $Command_String >>$Logfile 2>&1
$TestExitCode = $lastExitCode
Write-Host "Exited with exit code $TestExitCode `n" -foregroundcolor "green"
$message = [System.IO.File]::ReadAllText($Logfile)
Write-Host $message
Remove-Item -Force $Logfile
Write-Host "Press ENTER to QUIT the application." -foregroundcolor "green"
[Console]::ReadKey($true) | Out-Null
*************************************************************
Here is the Log
*************************************************************
Connecting to WinSCP
Exited with exit code 0
echo off
batch abort
confirm off
transfer binary
Searching for host...
Connecting to host...
Authenticating...
Using username "xx".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] xx@xx.com
/TestDirectory
C:\TestExitCode
C:\TestExitCode\Sample2.txt | 0 KiB | 0.0 KiB/s | binary | 100%
Press ENTER to QUIT the application.