Re: Me a Noob ? :-(
Also, I have tried your code. With
CONST Protocol_ftp=2
line enabled, it works ok for me.
CONST Protocol_ftp=2
line enabled, it works ok for me.
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
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
Protocol_Ftp
, I'm not asked for host key.
Prototol_Ftp
to wrong value, should be 2
). The Passive
token seems suspicious to me, as the correct syntax would be FtpMode_Passive
.
SessionOptions.Protocol
before Session.Open
to verify it has correct value?
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
Winscp.dll
using:
SET NETVersion=v4.0.30319
call "%WINDIR%\Microsoft.NET\Framework64\%NETVersion%\RegAsm.exe" "WinSCP.dll" /codebase /tlb
%ProgramFiles(x86)%\WinSCP
and above call is executed in this directory.
With sessionOptions
.FtpMode = Passive
.Protocol = Protocol_Ftp
.HostName = "example.com"
.UserName = "user"
.Password = "mypassword"
End With
WinSCP: SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.HostKey is not set.
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.