session.FileExists hangs when no file but returns 'true' when when there is as expected.

Advertisement

supermankelly
Joined:
Posts:
10
Location:
Essex

session.FileExists hangs when no file but returns 'true' when when there is as expected.

Hi,

I'm using VB .net within Visual Studio but the FileExists hangs and does nothing when no file exist on remote SFTP server. ie it doesn't receive a 'false'. PutFiles and GetFiles seem fine.

  
          
If session.FileExists(toFile) Then                                                                        
    session.RemoveFiles(toFile)
End If

Also MoveFiles also hangs if the file moved to exists. Is there a overwrite for this? Or at least return an error code so it can be handled.

And RemoveFiles hangs if no file exists to remove.


Just used this sites exact sample as provided and this hanged when the GET file didn't exist???

    Public Function Main() As Integer

        Try
            ' Setup session options
            Dim sessionOptions As New SessionOptions
            With sessionOptions
                .Protocol = Protocol.Sftp
                .HostName = "xx-xxxx.xxx-xxx.xxxx"
                .UserName = "xxxxxx"
                .PortNumber = "8822"
                .SshHostKeyFingerprint = "ecdsa-sha2-nistp521 x xx:ex:xx:fe:xx:bc:ex:cx:xx:xx:xx:xx:cx:xc:xb:xx"
                .SshPrivateKeyPath = "C:\xxxx\xxxxx\Documents\private_key.ppk"
            End With

            Using session As New Session
                ' Connect
                session.Open(sessionOptions)

                ' Download files
                Dim transferOptions As New TransferOptions
                transferOptions.TransferMode = TransferMode.Binary

                Dim transferResult As TransferOperationResult
                transferResult = session.GetFiles("\Test\Outbox\Pricelists\xxxx-pricebooks-global.xml", "C:\Users\Documents\xxxx-pricebooks-global.xml", False, transferOptions)

                ' Throw on any error
                transferResult.Check()

                ' Print results
                For Each transfer In transferResult.Transfers
                    Console.WriteLine("Download of {0} succeeded", transfer.FileName)
                Next
            End Using

            Return 0
        Catch e As Exception
            Console.WriteLine("Error: {0}", e)
            Return 1
        End Try

    End Function


Cheers
Andrew

Reply with quote

Advertisement

supermankelly

Looks like this isn't isolated issue (https://winscp.net/forum/viewtopic.php?t=15326) with FileExists hanging when returning an error condition. This works on another of our SFTP servers. So I will post up the differences of the two shortly once our admin sends me a summary.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: session.FileExists hangs when no file but returns 'true' when when there is as expected.

Please attach a full session log file showing the problem (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.

Reply with quote

Advertisement

You can post new topics in this forum