winscp automation using powershell

Advertisement

Guest

winscp automation using powershell

I am trying to automate a process which involves copying a file from a windows share to a redhat linux 7.2 server. I am using power shell for this and attached is the script (Automation-CSV-FTP-Moodle-Emrollments QA). When I runt the script it is breaking at the open session with error . The same script executes ok the QA server. I checked that firewalld is dead. No iptables.
Any ideas please . I am running this scrip on my machine and I can connect manually using winscp to the same server with no issues.


Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0.
Authentication log (see session log for details):
Using username "root".
Authentication failed."
At D:\Automation-CSV-FTP-Moodle-Emrollments LMS.ps1:28 char:1
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException

Exception calling "PutFiles" with "4" argument(s): "Session is not opened"
At D:\Automation-CSV-FTP-Moodle-Emrollments LMS.ps1:38 char:1
+ $session.PutFiles("$SourceSuspendOldPath", "$DestinationSuspendOldPat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException

Exception calling "PutFiles" with "4" argument(s): "Session is not opened"
At D:\Automation-CSV-FTP-Moodle-Emrollments LMS.ps1:43 char:1
+ $session.PutFiles("$SourceTodayPath", "$DestinationTodayPath", $False ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException


error log : tail -f /var/log/secure
Jun 29 11:32:01 xxxxxxx sshd[23287]: error: Received disconnect from xxxxxxxxxx: 13: Unable to authenticate [preauth]

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,658
Location:
Prague, Czechia

Re: winscp automation using powershell

Your code does not seem to match the log file. In the log file, I cannot see any password being passed in.

When I run your code I can clearly see the password being used in the log file:

. 2017-06-30 16:23:56.362 User name: XXX (Password: Yes, Key file: No, Passphrase: No)
> 2017-06-30 16:23:56.362 Script: open sftp://XXX:***@XXX -hostkey="..." -timeout=15

While your logs says:

. 2017-06-29 11:43:37.509 User name: root (Password: No, Key file: No, Passphrase: No)
> 2017-06-29 11:43:37.509 Script: open sftp://root@xxx.xxx.xx.xxx -hostkey="..." -timeout=15

Something does not match.

Reply with quote

grkraj
Joined:
Posts:
1

Automation using power shell

Martin, Thank you for replying
You are right, It is odd.
In the code I changed user name to different admin account (instead of root) and it works. You can see in the attached log that it is passing the password.
What is going on here?. Why is it not working as root

Please ignore that it is failing at the end because it cannot find the files.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,658
Location:
Prague, Czechia

Re: Automation using power shell

Do you mean that you have only changed root to winscpuser? No other change in the code was done? Not even the password?

Reply with quote

Advertisement

You can post new topics in this forum