Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

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: Scripting zOS session fails - psFTP works

WinSCP .NET assembly interface requires a use absolute paths.

Do not try to hack it by running cd in a shell.

Use absolute path in the PutFiles.
Guest

Scripting zOS session fails - psFTP works

Script fails after Login on changing directory to HOME, here is LOG and Script

param (
[string]$text1 = "0",
[string]$SRC = "PROD",
[string]$text2 = "0",
[string]$TGT = "DEV"
)

##write-output $diaglevel
##write-output $bundleid

try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"

# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = ""
PortNumber = 22
UserName = "3"
Password = "7"
SshHostKeyFingerprint = "ssh-rsa 1024 6d:19:01:b0:27:36:ff:12:f2:a1:1c:21:5e:cb:77:d8"
#FtpSecure = [WinSCP.FtpSecure]::Implicit
#FtpSecure = [WinSCP.FtpSecure]::Explicit

}

$session = New-Object WinSCP.Session

try
{
#
$TDMROOT = "C:\tdm"
$LogPath = $TDMROOT + "\logs"
$JCLPath = $TDMROOT + "\jcl"
$Template = $JCLPath + "\iebgener.jcl.txt"

$rand = Get-Random -minimum 1 -maximum 100

$Job = $Template + "." + $rand + ".txt"

$session.SessionLogPath = $LogPath + "\subJCLFTP.log"
# Connect
$session.Open($sessionOptions)

# Your code
Write-Host ("Opening..")

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Ascii

$content = [System.IO.File]::ReadAllText($Template).Replace("<SRC>",$SRC)
$content = $content.Replace("<TGT>", $TGT)


[System.IO.File]::WriteAllText($Job, $content)

#Write-Host ("Auth..")

#$session.ExecuteCommand("AUTH SSL 1").Check()

Write-Host ("JES..")

# $session.ExecuteCommand("SITE FILETYPE=JES").Check()

$session.ExecuteCommand("cd //-JES.intrdr").Check() ##########
Write-Host ("Put..")


$transferResult = $session.PutFiles($Job, "~", $False, $transferOptions)


Write-Host "END..Result "

# Your code END
}
finally
{
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host ("Error {0}" -f $_.Exception.Message)
}
:evil:


CONSOLE

PS C:\Windows\system32> C:\Users\c653\Downloads\debugFTP.ps1
Opening..
JES..
Error Error changing directory to '//C653'.
Command 'cd "//C6053"'
failed with return code 1 and error message
cd: //C6053: EDC5129I No such file or directory..

PS C:\Windows\system32>



LOG

. 2017-05-23 18:56:05.773 --------------------------------------------------------------------------
. 2017-05-23 18:56:05.774 WinSCP Version 5.9.5 (Build 7441) (OS 6.3.9600 - Windows Server 2012 R2 Standard)
. 2017-05-23 18:56:05.774 Configuration: nul
. 2017-05-23 18:56:05.774 Log level: Normal
. 2017-05-23 18:56:05.774 Local account: USAGNT\xxxxxx
. 2017-05-23 18:56:05.774 Working directory: C:\Program Files (x86)\WinSCP
. 2017-05-23 18:56:05.774 Process ID: 7972
. 2017-05-23 18:56:05.775 Command-line: "C:\Program Files (x86)\WinSCP\winscp.exe" /xmllog="C:\Users\xxxxxx\AppData\Local\Temp\wscp2A9C.026E04AB.tmp" /xmlgroups /xmllogrequired /nointeractiveinput /dotnet=595 /ini=nul /log="C:\tdm\logs\subJCLFTP.log" /console /consoleinstance=_10908_22467095_529
. 2017-05-23 18:56:05.775 Time zone: Current: GMT-4, Standard: GMT-5 (Eastern Standard Time), DST: GMT-4 (Eastern Daylight Time), DST Start: 3/12/2017, DST End: 11/5/2017
. 2017-05-23 18:56:05.775 Login time: Tuesday, May 23, 2017 6:56:05 PM
. 2017-05-23 18:56:05.775 --------------------------------------------------------------------------
. 2017-05-23 18:56:05.775 Script: Retrospectively logging previous script records:
> 2017-05-23 18:56:05.775 Script: option batch on
< 2017-05-23 18:56:05.775 Script: batch on
< 2017-05-23 18:56:05.775 Script: reconnecttime 120
> 2017-05-23 18:56:05.775 Script: option confirm off
< 2017-05-23 18:56:05.775 Script: confirm off
> 2017-05-23 18:56:05.775 Script: option reconnecttime 120
< 2017-05-23 18:56:05.775 Script: reconnecttime 120
> 2017-05-23 18:56:05.775 Script: open sftp://xxxxxx:***@xxxxxx:22 -hostkey="ssh-rsa 1024 6d:19:01xxxxxx7:d8" -timeout=15
. 2017-05-23 18:56:05.775 --------------------------------------------------------------------------
. 2017-05-23 18:56:05.775 Session name: xxxxxx@xxxxxx (Ad-Hoc site)
. 2017-05-23 18:56:05.775 Host name: xxxxxx (Port: 22)
. 2017-05-23 18:56:05.775 User name: xxxxxx (Password: Yes, Key file: No, Passphrase: No)
. 2017-05-23 18:56:05.775 Tunnel: No
. 2017-05-23 18:56:05.775 Transfer Protocol: SFTP
. 2017-05-23 18:56:05.775 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2017-05-23 18:56:05.775 Disable Nagle: No
. 2017-05-23 18:56:05.775 Proxy: None
. 2017-05-23 18:56:05.775 Send buffer: 262144
. 2017-05-23 18:56:05.775 SSH protocol version: 2; Compression: No
. 2017-05-23 18:56:05.775 Bypass authentication: No
. 2017-05-23 18:56:05.775 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2017-05-23 18:56:05.775 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2017-05-23 18:56:05.775 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2017-05-23 18:56:05.776 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2017-05-23 18:56:05.776 Simple channel: Yes
. 2017-05-23 18:56:05.776 Return code variable: Autodetect; Lookup user groups: Auto
. 2017-05-23 18:56:05.776 Shell: default
. 2017-05-23 18:56:05.776 EOL: LF, UTF: Auto
. 2017-05-23 18:56:05.776 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2017-05-23 18:56:05.776 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2017-05-23 18:56:05.776 SFTP Bugs: Auto,Auto
. 2017-05-23 18:56:05.776 SFTP Server: default
. 2017-05-23 18:56:05.776 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2017-05-23 18:56:05.776 Cache directory changes: Yes, Permanent: Yes
. 2017-05-23 18:56:05.776 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2017-05-23 18:56:05.776 DST mode: Unix
. 2017-05-23 18:56:05.776 --------------------------------------------------------------------------
. 2017-05-23 18:56:05.776 Looking up host "xxxxxx" for SSH connection
. 2017-05-23 18:56:05.776 Connecting to xxxxxx port 22
. 2017-05-23 18:56:05.778 We claim version: SSH-2.0-WinSCP_release_5.9.5
. 2017-05-23 18:56:05.864 Server version: SSH-2.0-OpenSSH_6.4
. 2017-05-23 18:56:05.865 We believe remote version has SSH-2 channel request bug
. 2017-05-23 18:56:05.865 Using SSH protocol version 2
. 2017-05-23 18:56:05.865 Have a known host key of type rsa2
. 2017-05-23 18:56:05.879 Doing ECDH key exchange with curve nistp256 and hash SHA-256
. 2017-05-23 18:56:05.952 Server also has ssh-dss host key, but we don't know it
. 2017-05-23 18:56:05.953 Host key fingerprint is:
. 2017-05-23 18:56:05.953 ssh-rsa 1024 6d:19:01xxxxxx7:d8
. 2017-05-23 18:56:05.953 Verifying host key rsa2 0x23,0xbb6bxxxxxxf5279f1705c64 5e5a5222dfb57dab 0e0e5857cf0b144b 5f22bafab67358d0 63f07c3d2751541f cd7ff7230ce4050a 0008a872aa5a1c80 4c5ce0e01040be54 98971c91bbab10fb 7626f662c7106c62 6ecbc8e4eb790338 7f8136544edf27e7 with fingerprint ssh-rsa 1024 6d:19:01xxxxxx7:d8
. 2017-05-23 18:56:05.953 Host key matches configured key
. 2017-05-23 18:56:05.954 Initialised AES-256 SDCTR client->server encryption
. 2017-05-23 18:56:05.954 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2017-05-23 18:56:05.954 Initialised AES-256 SDCTR server->client encryption
. 2017-05-23 18:56:05.954 Initialised HMAC-SHA-256 server->client MAC algorithm
! 2017-05-23 18:56:06.194 Using username "xxxxxx".
. 2017-05-23 18:56:06.215 Server offered these authentication methods: publickey,password
. 2017-05-23 18:56:06.215 Prompt (password, "SSH password", <no instructions>, "&Password: ")
. 2017-05-23 18:56:06.215 Using stored password.
. 2017-05-23 18:56:06.216 Sent password
. 2017-05-23 18:56:06.265 Access granted
. 2017-05-23 18:56:06.265 Opening session as main channel
. 2017-05-23 18:56:06.291 Opened main channel
. 2017-05-23 18:56:06.501 Started a shell/command
. 2017-05-23 18:56:06.501 --------------------------------------------------------------------------
. 2017-05-23 18:56:06.501 Using SFTP protocol.
. 2017-05-23 18:56:06.501 Doing startup conversation with host.
> 2017-05-23 18:56:06.501 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2017-05-23 18:56:06.790 Type: SSH_FXP_VERSION, Size: 155, Number: -1
. 2017-05-23 18:56:06.790 SFTP version 3 negotiated.
. 2017-05-23 18:56:06.791 Unknown server extension posix-rename@openssh.com="1"
. 2017-05-23 18:56:06.791 Unknown server extension coz-zopts@dovetail.com="0"
. 2017-05-23 18:56:06.791 Supports statvfs@openssh.com extension version "2"
. 2017-05-23 18:56:06.791 Unknown server extension fstatvfs@openssh.com="2"
. 2017-05-23 18:56:06.791 Supports hardlink@openssh.com extension version "1"
. 2017-05-23 18:56:06.791 We believe the server has signed timestamps bug
. 2017-05-23 18:56:06.791 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 strings are not mandatory
. 2017-05-23 18:56:06.791 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2017-05-23 18:56:06.791 Getting current directory name.
. 2017-05-23 18:56:06.791 Getting real path for '.'
> 2017-05-23 18:56:06.791 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2017-05-23 18:56:06.794 Type: SSH_FXP_NAME, Size: 37, Number: 16
. 2017-05-23 18:56:06.794 Real path is '//xxxxxx'
. 2017-05-23 18:56:06.794 Startup conversation with host finished.
< 2017-05-23 18:56:06.794 Script: Active session: [1] xxxxxx@xxxxxx
> 2017-05-23 18:56:07.386 Script: pwd
< 2017-05-23 18:56:07.386 Script: //xxxxxx
> 2017-05-23 18:56:07.485 Script: call cd //-JES.intrdr
< 2017-05-23 18:56:07.485 Script: Searching for host...
. 2017-05-23 18:56:07.486 [Shell] Looking up host "xxxxxx" for SSH connection
. 2017-05-23 18:56:07.486 [Shell] Connecting to xxxxxx port 22
. 2017-05-23 18:56:07.486 [Shell] We claim version: SSH-2.0-WinSCP_release_5.9.5
< 2017-05-23 18:56:07.486 Script: Connecting to host...
. 2017-05-23 18:56:07.573 [Shell] Server version: SSH-2.0-OpenSSH_6.4
. 2017-05-23 18:56:07.574 [Shell] We believe remote version has SSH-2 channel request bug
. 2017-05-23 18:56:07.574 [Shell] Using SSH protocol version 2
. 2017-05-23 18:56:07.574 [Shell] Have a known host key of type rsa2
. 2017-05-23 18:56:07.586 [Shell] Doing ECDH key exchange with curve nistp256 and hash SHA-256
. 2017-05-23 18:56:07.663 [Shell] Server also has ssh-dss host key, but we don't know it
. 2017-05-23 18:56:07.663 [Shell] Host key fingerprint is:
. 2017-05-23 18:56:07.663 [Shell] ssh-rsa 1024 6d:19:01xxxxxx7:d8
. 2017-05-23 18:56:07.663 [Shell] Verifying host key rsa2 0x23,0xbb6bxxxxxxf5279f1705c64 5e5a5222dfb57dab 0e0e5857cf0b144b 5f22bafab67358d0 63f07c3d2751541f cd7ff7230ce4050a 0008a872aa5a1c80 4c5ce0e01040be54 98971c91bbab10fb 7626f662c7106c62 6ecbc8e4eb790338 7f8136544edf27e7 with fingerprint ssh-rsa 1024 6d:19:01xxxxxx7:d8
< 2017-05-23 18:56:07.663 Script: Authenticating...
. 2017-05-23 18:56:07.664 [Shell] Host key matches configured key
. 2017-05-23 18:56:07.665 [Shell] Initialised AES-256 SDCTR client->server encryption
. 2017-05-23 18:56:07.665 [Shell] Initialised HMAC-SHA-256 client->server MAC algorithm
. 2017-05-23 18:56:07.665 [Shell] Initialised AES-256 SDCTR server->client encryption
. 2017-05-23 18:56:07.665 [Shell] Initialised HMAC-SHA-256 server->client MAC algorithm
! 2017-05-23 18:56:07.897 [Shell] Using username "xxxxxx".
< 2017-05-23 18:56:07.897 Script: Using username "xxxxxx".
. 2017-05-23 18:56:07.916 [Shell] Server offered these authentication methods: publickey,password
. 2017-05-23 18:56:07.916 [Shell] Prompt (password, "SSH password", <no instructions>, "&Password: ")
. 2017-05-23 18:56:07.916 [Shell] Using stored password.
< 2017-05-23 18:56:07.916 Script: Authenticating with pre-entered password.
. 2017-05-23 18:56:07.916 [Shell] Sent password
. 2017-05-23 18:56:07.965 [Shell] Access granted
. 2017-05-23 18:56:07.965 [Shell] Opening session as main channel
. 2017-05-23 18:56:07.985 [Shell] Opened main channel
. 2017-05-23 18:56:08.202 [Shell] Started a shell/command
< 2017-05-23 18:56:08.202 Script: Authenticated.
. 2017-05-23 18:56:08.203 [Shell] --------------------------------------------------------------------------
. 2017-05-23 18:56:08.203 [Shell] Using SCP protocol.
. 2017-05-23 18:56:08.203 [Shell] Doing startup conversation with host.
< 2017-05-23 18:56:08.203 Script: Starting the session...
. 2017-05-23 18:56:08.203 [Shell] Skipping host startup message (if any).
> 2017-05-23 18:56:08.203 [Shell] echo "WinSCP: this is end-of-file:0"
< 2017-05-23 18:56:08.252 [Shell] SH running in non terminal environment - Defaults are:
< 2017-05-23 18:56:08.252 [Shell] *************************************************************************
< 2017-05-23 18:56:08.252 [Shell] PATH=/usr/lpp/java/J8.0/bin:/usr/lpp/tcpip/sbin:/usr/lpp/Printsrv/bin:/usr/lpp/slma/bin:/usr/lpp/NFS:/usr/lpp/zosmf/V2R1/bin:/bin:/usr/sbin:.
< 2017-05-23 18:56:08.252 [Shell] *************************************************************************
< 2017-05-23 18:56:08.252 [Shell] CLASSPATH=.:/usr/lpp/cicsts/cicsts52/lib/*.jar:/usr/lpp/mqm/V7R1M0/java/lib/com.ibm.mq.jar
< 2017-05-23 18:56:08.252 [Shell] *************************************************************************
< 2017-05-23 18:56:08.253 [Shell] LIBPATH=/usr/lpp/java/J8.0/lib:/lib:/usr/lib:/usr/lpp/Printsrv/lib
< 2017-05-23 18:56:08.253 [Shell] *************************************************************************
< 2017-05-23 18:56:08.253 [Shell] LOGNAME=xxxxxx
< 2017-05-23 18:56:08.253 [Shell] *************************************************************************
< 2017-05-23 18:56:08.253 [Shell]
< 2017-05-23 18:56:08.253 [Shell] WinSCP: this is end-of-file:0
. 2017-05-23 18:56:08.253 [Shell] Detecting variable containing return code of last command.
. 2017-05-23 18:56:08.253 [Shell] Trying "$status".
> 2017-05-23 18:56:08.253 [Shell] echo "$status" ; echo "WinSCP: this is end-of-file:0"
< 2017-05-23 18:56:08.254 [Shell] WinSCP: this is end-of-file:0
. 2017-05-23 18:56:08.254 [Shell] The response is not numerical exit code
. 2017-05-23 18:56:08.254 [Shell] Trying "$?".
> 2017-05-23 18:56:08.254 [Shell] echo "$?" ; echo "WinSCP: this is end-of-file:0"
< 2017-05-23 18:56:08.255 [Shell] 0
< 2017-05-23 18:56:08.255 [Shell] WinSCP: this is end-of-file:0
. 2017-05-23 18:56:08.255 [Shell] Return code variable "$?" selected.
> 2017-05-23 18:56:08.255 [Shell] printenv LANG ; echo "WinSCP: this is end-of-file:$?"
< 2017-05-23 18:56:08.258 [Shell] C
< 2017-05-23 18:56:08.258 [Shell] WinSCP: this is end-of-file:1
. 2017-05-23 18:56:08.258 [Shell] We will not use UTF-8
. 2017-05-23 18:56:08.258 [Shell] Changing directory to "//xxxxxx".
> 2017-05-23 18:56:08.258 [Shell] cd "//xxxxxx" ; echo "WinSCP: this is end-of-file:$?"
! 2017-05-23 18:56:08.259 [Shell] cd: //xxxxxx: EDC5129I No such file or directory.
< 2017-05-23 18:56:08.259 [Shell] WinSCP: this is end-of-file:1
* 2017-05-23 18:56:08.259 [Shell] (ECommand) Error changing directory to '//xxxxxx'.
* 2017-05-23 18:56:08.259 [Shell] Command 'cd "//xxxxxx"'
* 2017-05-23 18:56:08.259 [Shell] failed with return code 1 and error message
* 2017-05-23 18:56:08.259 [Shell] cd: //xxxxxx: EDC5129I No such file or directory..
< 2017-05-23 18:56:08.259 Script: Error changing directory to '//xxxxxx'.
< 2017-05-23 18:56:08.259 Command 'cd "//xxxxxx"'
< 2017-05-23 18:56:08.259 failed with return code 1 and error message
< 2017-05-23 18:56:08.259 cd: //xxxxxx: EDC5129I No such file or directory..
. 2017-05-23 18:56:08.260 [Shell] Getting current directory name.
> 2017-05-23 18:56:08.260 [Shell] pwd ; echo "WinSCP: this is end-of-file:$?"
< 2017-05-23 18:56:08.261 [Shell] /u/xxxxxx
< 2017-05-23 18:56:08.262 [Shell] WinSCP: this is end-of-file:0
. 2017-05-23 18:56:08.262 [Shell] Startup conversation with host finished.
< 2017-05-23 18:56:08.262 Script: Session started.
. 2017-05-23 18:56:08.266 Executing user defined command on command session.
. 2017-05-23 18:56:08.266 [Shell] Changing directory to "//xxxxxx".
> 2017-05-23 18:56:08.266 [Shell] cd "//xxxxxx" ; echo "WinSCP: this is end-of-file:$?"
! 2017-05-23 18:56:08.267 [Shell] cd: //xxxxxx: EDC5129I No such file or directory.
< 2017-05-23 18:56:08.267 [Shell] WinSCP: this is end-of-file:1
* 2017-05-23 18:56:08.267 [Shell] (ECommand) Error changing directory to '//xxxxxx'.
* 2017-05-23 18:56:08.267 [Shell] Command 'cd "//xxxxxx"'
* 2017-05-23 18:56:08.267 [Shell] failed with return code 1 and error message
* 2017-05-23 18:56:08.267 [Shell] cd: //xxxxxx: EDC5129I No such file or directory..
< 2017-05-23 18:56:08.267 Script: Error changing directory to '//xxxxxx'.
< 2017-05-23 18:56:08.267 Command 'cd "//xxxxxx"'
< 2017-05-23 18:56:08.267 failed with return code 1 and error message
< 2017-05-23 18:56:08.267 cd: //xxxxxx: EDC5129I No such file or directory..
> 2017-05-23 18:56:08.268 [Shell] cd //-JES.intrdr ; echo "WinSCP: this is end-of-file:$?"
< 2017-05-23 18:56:08.269 Script: cd: //-JES.intrdr: EDC5129I No such file or directory.
! 2017-05-23 18:56:08.269 [Shell] cd: //-JES.intrdr: EDC5129I No such file or directory.
< 2017-05-23 18:56:08.269 [Shell] WinSCP: this is end-of-file:1
* 2017-05-23 18:56:08.269 (ETerminal) Command 'cd //-JES.intrdr'
* 2017-05-23 18:56:08.269 failed with return code 1 and error message
* 2017-05-23 18:56:08.269 cd: //-JES.intrdr: EDC5129I No such file or directory..
< 2017-05-23 18:56:08.269 Script: Command 'cd //-JES.intrdr'
< 2017-05-23 18:56:08.269 failed with return code 1 and error message
< 2017-05-23 18:56:08.269 cd: //-JES.intrdr: EDC5129I No such file or directory..
. 2017-05-23 18:56:08.270 Script: Failed
> 2017-05-23 18:56:08.584 Script: exit
. 2017-05-23 18:56:08.584 Script: Exit code: 1
. 2017-05-23 18:56:08.584 Closing connection.
. 2017-05-23 18:56:08.584 Sending special code: 12
. 2017-05-23 18:56:08.584 Sent EOF message
. 2017-05-23 18:56:08.585 [Shell] Closing connection.
. 2017-05-23 18:56:08.585 [Shell] Sending special code: 12
. 2017-05-23 18:56:08.585 [Shell] Sent EOF message