Topic "winscp automation using powershell"

Author Message
Guest




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: (Smile [], 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: (Smile [], 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: (Smile [], 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]
sessionlog.txt (5.88 KB) [Download]

Description: (none)

Automation-CSV-FTP-Moodle-Emrollments .txt (1.5 KB) [Download]

Description: (none)

Advertisements
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27059
Location: Prague, Czechia
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.
grkraj
[View user's profile]

Joined: 2017-06-29
Posts: 1
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.
sessionlog.txt (13.29 KB) [Download]

Description: (none)

martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27059
Location: Prague, Czechia
Do you mean that you have only changed root to winscpuser? No other change in the code was done? Not even the password?
Advertisements

You can post new topics in this forum

Search

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