Post a reply

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

Re: Me a Noob ? :-(

Also, I have tried your code. With CONST Protocol_ftp=2 line enabled, it works ok for me.
trh@marcello.no

Re: Me a Noob ? :-(

Yep, that worked. I tried that actually earlier; however seems like that test had other problems (using 5.14 or the fact that it was a 64 bit OS). However, now that I have one working test code I am a bit more optimistic in figuring out other issues ;-)

Thanks.
trh@marcello.no

Me a Noob ? :-(

I might be a noob here, anyhow. Here is the code with some corrections.

Host, username and password is maniuplated in the dump...

Funny thing, if I uncomment CONST Protocol_ftp=2, nothing happens, no errors, no transfer - only the message from my debugf flagged console output:
Transferring C:\Users\tonny.r.holm\Dropbox\Jobb\Programmering\2013 Efaktura-Itella\Work\test\* to destination out/test/data Using:2

You might se I have created a case select to handle other transfer methods, but they are disabled for the moment - only testing FTP.
Debugf=true
' CONST Protocol_ftp=2
' <invalid hyperlink removed by admin>
Result=PutFileFTPWinSCP("ftp.mytestserver.net","Protocol_Ftp","USER","password","C:\Users\tonny.r.holm\Dropbox\Jobb\Programmering\2013 Efaktura-Itella\Work\test\*","out/test/data")
 
Function PutFileFTPWinSCP(strHostname,strProtocol,strUsername,strPassword,strSourcefiles,strDestDir)
  ' Module for Remote connect using WinSCP Assembly.
 
  'strProtocol = Protocol_Sftp/Protocol_Scp/Protocol_Ftp
  'strHostname = "example.com"
  'strUsername = "user"
  'strPassword = "mypassword"
  'strSourcefiles = "d:\toupload\*"
  'strDestDir = /home/user/
  ' .SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
 
   
  ' Setup session options
  Dim sessionOptions
  Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
 
  With sessionOptions
    .Protocol = Protocol_ftp
    .HostName = strHostname
    .UserName = strUsername
    .Password = strPassword
    '.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
  End With
 
  'Select CASE strProtocol
  'Case "Protocol_Sftp"
  '  With sessionOptions
  '    .Protocol = Protocol_Sftp
  '    .HostName = strHostname
  '    .UserName = strUsername
  '    .Password = strPassword
  '    .SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
  '  End With
  'Case "Protocol_Scp"
  '  With sessionOptions
  '    .Protocol = Protocol_Scp
  '    .HostName = strHostname
  '    .UserName = strUsername
  '    .Password = strPassword
  '    .SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
  '  End With
  'Case "Protocol_Ftp"
  '  if debugf then Wscript.echo "Using Protocol_Ftp"
  '  With sessionOptions
  '    .FtpMode  = Passive
  '    .Protocol = Protocol_Ftp
  '    .HostName = strHostname
  '    .UserName = strUsername
  '    .Password = strPassword
  '    '.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
  '  End With
  'End Select
   
  Dim session
  Set session = WScript.CreateObject("WinSCP.Session")
  ' Ignore wrong Assembly version
  Session.DisableVersionCheck=True
   
  ' Connect
  session.Open sessionOptions
   
  ' Upload files
  Dim transferOptions
  Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions")
  transferOptions.TransferMode = TransferMode_Binary
   
  Dim transferResult
  Set transferResult = session.PutFiles(strSourcefiles, strDestDir, False, transferOptions)
 
  if debugf then WScript.Echo "Transferring " & strSourcefiles & " to destination " & strDestDir & " Using:"SessionOptions.Protocol
   
  ' Throw on any error
  transferResult.Check
   
  ' Print results
  Dim transfer
  For Each transfer In transferResult.Transfers
    if debugf then WScript.Echo "Upload of " & transfer.FileName & " succeeded"
  Next
   
  ' Disconnect, clean up
  session.Dispose
 
End function
martin

Re: Using FTP via COM returns Protocol.Sftp or Protocol.Scp

For 5.1.4: I have released development version of the .NET assembly with 5.1.4 by mistake. Will fix it shortly.

I have tested the example VBS code again using 5.1.3 and it works correctly for me. When I set Protocol to Protocol_Ftp, I'm not asked for host key.

Are you using the WSF solution for the enumeration values? Or have you defined the enums yourself (possibly setting the Prototol_Ftp to wrong value, should be 2). The Passive token seems suspicious to me, as the correct syntax would be FtpMode_Passive.

Can you post your complete code? Can you try to print the SessionOptions.Protocol before Session.Open to verify it has correct value?
trh@marcello.no

Using FTP via COM returns Protocol.Sftp or Protocol.Scp

Hello!

I have a project where i shall transfer files to a FTP server. To this, I have tried to use WinSCP with the .NET assembly/COM library.

Using VBscript :oops:

I have tested with following downloaded installations:

winscp514automation.zip/winscp514setup.exe (calling returns that winscp.dll is incompatible, so tested older versions as well):
winscp513automation.zip/winscp513setup.exe
winscp510automation.zip/winscp510setup.exe

I have registered Winscp.dll using:
SET NETVersion=v4.0.30319
call "%WINDIR%\Microsoft.NET\Framework64\%NETVersion%\RegAsm.exe" "WinSCP.dll" /codebase /tlb

Where WinSCP is copied to %ProgramFiles(x86)%\WinSCP and above call is executed in this directory.

I use the example as provided here: https://winscp.net/eng/docs/library_com_wsh#vbscript, with the following modifications:
With sessionOptions
    .FtpMode  = Passive
    .Protocol = Protocol_Ftp
    .HostName = "example.com"
    .UserName = "user"
    .Password = "mypassword"
End With

(Hostname, Username and Password is changed for my environment in my code)

However, on all my computers this fails with:
WinSCP: SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.HostKey is not set.

...and if I provide SessionOptions.HostKey:
WinSCP: SSH host key fingerprint "ssh-rsa1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" does not match pattern .. blah blah.

A SSH key should not be needed for FTP anyhow, so.....

Any tips on what I do wrong?