Topic "Connection has been unexpectedly closed. Server sent command exit status 0"

Author Message
Jaya

Guest


Hi I am using the belowcode to connect to SFTP Through WinSCP. It gets connected only once.Next time when I run the code I get the error at this line
"mySession.Open mySessionOptions"

connection has been unexpectedly closed. Server sent command exit status 0.Authentication failed
Please Help.


Option Explicit

Sub Connect_To_SFTP()

Dim mySession As New session


' Enable custom error handling
On Error Resume Next

Upload mySession

' Query for errors
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Description

' Clear the error
Err.Clear
End If

' Disconnect, clean up
mySession.Dispose

' Restore default error handling
On Error GoTo 0

End Sub

Sub Upload(ByRef mySession As session)
Dim works As String

' Setup session options
Dim mySessionOptions As New sessionOptions
'bool GiveUpSecurityAndAcceptAnySshHostKey
With mySessionOptions
.Protocol = Protocol_Sftp
.HostName = "lab.com"
.UserName = "*****"
.Password = "******"
.GiveUpSecurityAndAcceptAnySshHostKey = True
End With

' Connect
mySession.Open mySessionOptions

' Upload files
Dim transferOptions As New transferOptions
'Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions")
transferOptions.TransferMode = TransferMode_Binary

Dim transferResult
Set transferResult = mySession.GetFiles("/Result/Output_TXT/*", "c:\toupload\", False, transferOptions)

' Throw on any error
transferResult.Check

' Print results
Dim transfer
For Each transfer In transferResult.Transfers
Debug.Print "Download of " & transfer.Filename & " succeeded"
Next
' Disconnect, clean up
mySession.Dispose

End Sub
Advertisements
martouf

Guest


Try following the thread of execution but focus only on the mySession variable.

Connect_To_SFTP()
.
.
Dim mySession
.
.
Upload( mySession ) -> passed by reference
.
.
Dispose mySession
.
.
Return to Connect_To_SFTP()
.
.
Dispose mySession
.
.
Return to <caller>
Jaya

Guest


Hello yesterday I did windows update. Now its giving me Automation error-2146234304
Please help me with this first.
so that i can check the above solution
martouf

Guest


sorry, but "the above" is not a SOLUTION but a big HINT of what the problem is likely to be.

i could be wrong, but a double DISPOSE is not likely to give good results.

in general, it is my understanding that good coding practice is to perform a Dispose only in the method or subroutine that performed the variable allocation ("Dim") -especially- if the variable is passed around by reference (and not by value).
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
Jaya wrote:
Hello yesterday I did windows update. Now its giving me Automation error-2146234304
Please help me with this first.
so that i can check the above solution

Try to unregister (!) and then re-register the .NET assembly.
https://winscp.net/eng/docs/library_install#registering
Jaya

Guest


martin wrote:
Jaya wrote:
Hello yesterday I did windows update. Now its giving me Automation error-2146234304
Please help me with this first.
so that i can check the above solution

Try to unregister (!) and then re-register the .NET assembly.
https://winscp.net/eng/docs/library_install#registering



Hello I unregisterd using the command
SET WorkFolder= '<directory>'
regasm.exe /unregister %WorkFolder%\xxx.dll

And re registerd it.

Still getting the same error
Please help
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
Where do you run the code from?
Jaya

Guest


martin wrote:
Where do you run the code from?


Command prompt--> Running as Administrator
Jaya

Guest


It gives error at this line- Upload mySession
Error-Automation error
error number-2146234304
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
So you have some .exe file built from your code? Is it VB6?
Jaya

Guest


martin wrote:
So you have some .exe file built from your code? Is it VB6?


No .exe files.Have .tlb and .dll files.
It's VB 7.1.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
Sorry, I have no idea how VB works. So again, do you build some .exe from your code? Or how do you run it?
Jaya

Guest


martin wrote:
Sorry, I have no idea how VB works. So again, do you build some .exe from your code? Or how do you run it?



Calling Winscp.exe and COM object accessing Microsoft .NET framework.
Jaya

Guest


martin wrote:
Sorry, I have no idea how VB works. So again, do you build some .exe from your code? Or how do you run it?


I have restored the system.Now no automation error.
Please help me with this.

I am using the above code to connect to SFTP Through WinSCP. It gets connected only once.Next time when I run the code I get the error at this line
"mySession.Open mySessionOptions"

connection has been unexpectedly closed. Server sent command exit status 0.Authentication failed
Please Help.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
Jaya wrote:
I am using the above code to connect to SFTP Through WinSCP. It gets connected only once.Next time when I run the code I get the error at this line
"mySession.Open mySessionOptions"

connection has been unexpectedly closed. Server sent command exit status 0.Authentication failed
Please Help.

Please attach a full session log file for both sessions (using the latest version of WinSCP).

To generate the session 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 can mark the attachment as private.
Jaya

Guest


martin wrote:
Jaya wrote:
I am using the above code to connect to SFTP Through WinSCP. It gets connected only once.Next time when I run the code I get the error at this line
"mySession.Open mySessionOptions"

connection has been unexpectedly closed. Server sent command exit status 0.Authentication failed
Please Help.

Please attach a full session log file for both sessions (using the latest version of WinSCP).

To generate the session 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 can mark the attachment as private.



i have attached the code.
Registered regasm.exe using commands
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe WinSCPnet.dll /codebase /tlb:WinSCPnet32.tlb"
"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe WinSCPnet.dll /codebase /tlb:WinSCPnet64.tlb"
Book1.xls (27.75 KB) [Download]

Description: (none)

code.txt (1.34 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
There's no log file attached to your post.
Jaya

Guest


martin wrote:
There's no log file attached to your post.


what are log files?. I'm new to VBA I don't know what are log files.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26138
Location: Prague, Czechia
Jaya wrote:
what are log files?. I'm new to VBA I don't know what are log files.

Read my previous post carefully again!
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