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

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!
Jaya

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

There's no log file attached to your post.
Jaya

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"
martin

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

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.
Jaya

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.
martin

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

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

So you have some .exe file built from your code? Is it VB6?
Jaya

It gives error at this line- Upload mySession
Error-Automation error
error number-2146234304
Jaya

martin wrote:

Where do you run the code from?


Command prompt--> Running as Administrator
martin

Where do you run the code from?
Jaya

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

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
martouf

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).
Jaya

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

Connection unexpectedly closed

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

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

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