WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: morenos1 on August 13, 2019, 08:53:04 AM

Title: SFTP using WinSCP dotNet.
Post by: morenos1 on August 13, 2019, 08:53:04 AM
Need help attempting SFTP using WinSCP dotNet and key file for auth..

WinSCP GUI works and it generates this code:

// Set up session options
SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = "ftp.site.com",
    UserName = "oaklawnilgate",
    SshHostKeyFingerprint = "ssh-ed25519 256 0XGaH0U6ISK5XioqtUJbdMfelRWmlL9ljbbwEKOKN/E=",
    SshPrivateKeyPath = @"C:\Temp\oaklawnil_rsa.ppk",
};

sessionOptions.AddRawSettings("AgentFwd", "1");

using (Session session = new Session())
{
    // Connect
    session.Open(sessionOptions);

    // Your code
}


When I attempt it with WinBatch code:

; Define Protocol
;  Possible values are Protocol.Sftp (default), Protocol.Scp and Protocol.Ftp.
objProtocol = ObjectClrNew( 'WinSCP.Protocol' )
Sftp = ObjectClrType( 'WinSCP.Protocol', objProtocol.Sftp ) ; Sftp

objSessionOptions.Protocol = Sftp  ; Sftp, Ftp or Scp                    ; MODIFY TO FIT YOUR NEEDS
objSessionOptions.HostName = 'ftp.site.com'                ; MODIFY TO FIT YOUR NEEDS
objSessionOptions.UserName = 'oaklawnilgate'  ; MODIFY TO FIT YOUR NEEDS
objSessionOptions.SshPrivateKeyPath = '@"C:\Temp\oaklawnil_rsa.ppk"'
;objSessionOptions.Password = 'password'                                  ; MODIFY TO FIT YOUR NEEDS
If IsDefined(Sftp)
   objSessionOptions.SshHostKeyFingerprint = "ssh-ed25519 256 0XGaH0U6ISK5XioqtUJbdMfelRWmlL9ljbbwEKOKN/E=" ;REQUIRED by SFTP     ; MODIFY TO FIT YOUR NEEDS
   objSessionOptions.AddRawSettings("AgentFwd", "1");
EndIf


It fails (see attachment error) ...

Any hint will be greatly appreciated.....
Title: Re: SFTP using WinSCP dotNet.
Post by: morenos1 on August 13, 2019, 09:04:22 AM
I think the @ before file name is not needed...

Thanks....
Title: Re: SFTP using WinSCP dotNet.
Post by: stanl on August 16, 2019, 07:26:36 AM
Not related to your specific question, but did raise that I had forgotten WinSCP writes Powershell code for connections. As I have requirements for loading to SAP Hana using an authentication key, WINSCP wrote Powershell code which worked and could be converted to WB if needed.


Thanks!!!