Search code examples
.netvb.netsftpwinscpwinscp-net

WinSCP Session.GetFiles error No such file or directory


Using WinSCP with variables to automate downloading of specific file from remote root folder. I have no problem connecting, but the code generates error 'No such file or directory' when attempting download.

Here's the code:

' Setup session variables, connect, and download file
Dim remotefile As String = "text.zip"
Dim localpath As String = "D:\Work\Returns\"

Dim sessionOptions As New SessionOptions
With sessionOptions
   .Protocol = Protocol.Sftp
   .HostName = myftpaddress
   .UserName = myftpuser
   .Password = myftppass
   .SshHostKeyFingerprint = SSH         
End With

Using session As New Session
  'go ahead & connect
  session.Open(sessionOptions)

  Dim transferOptions As New TransferOptions
  transferOptions.TransferMode = TransferMode.Binary
  Dim transferResult As TransferOperationResult
  'now get the file
  transferResult = session.GetFiles("/" & remotefile, localpath, False, transferOptions)
End Using

Solution

  • The file you are trying to download does not exist.

    You are most probably using a wrong path. Are you sure the account is chrooted? Isn't the path rather like /user/home/text.zip, rather than /text.zip?

    Use WinSCP GUI to find the correct path to the file.

    You can even have WinSCP GUI generate the correct SFTP VB.NET download code for you.


    If this does not help, we need to see your code session log file (set Session.SessionLogPath), as well as WinSCP GUI log file showing a download of the same file.