2

I'm trying to auto sync local files with a server using WinSCP. I'm getting the following script error:

enter image description here

Here is my vba code:

Public Sub pullwinscp()
Shell "wscript C:\Users\Aaron\Desktop\SyncSftp.vbs", vbNormalFocus
End Sub

And here is the script I'm trying to call (saved as .vbs):

open sftp://User:Password@webaddress.org -hostkey="aaaaa-aaa2 aaaaa256 7a:4a:aa:aa:aa:aa:aa:aa:a1:aa:aa:aa:aa:aa:aa:aa"
synchronize local C:\Users\Aaron\Documents\test /home/FTP/Acct Hourly Acctg

Any ideas why I'm getting this error?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
guice99
  • 55
  • 9

1 Answers1

1

Your ".vbs" is not VBScript code. That's WinSCP script.

To run WinSCP script from VBA, use:

Call Shell("C:\path\winscp.com /ini=nul /script=c:\path\SyncSftp.txt")

(after you rename SyncSftp.vbs to SyncSftp.txt, as it's not VBScript)

See also Using VBA to run WinSCP script.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I've tried this several different ways and keep getting "file not found". here is how my last attempt looks: Call Shell("C:\Users\Aaron\Desktop\Sync.txt\winscp.com /ini=nul /script=C:\Users\Aaron\Desktop\Sync.txt") Probably way off, I'm new at this. – guice99 Jan 27 '19 at 21:04
  • `C:\Users\Aaron\Desktop\Sync.txt\winscp.com` looks like a nonsense, if `C:\Users\Aaron\Desktop\Sync.txt` is a file. You need to use a path to `winscp.com` - For example `C:\Program Files (x86)\WinSCP\WinSCP.com` - in which case you need to wrap it to double-quotes as it contains spaces (and the double-quotes need to be doubled in VBA string). – Martin Prikryl Jan 27 '19 at 21:18
  • Martin, when the cmd screen pops up it says searching for host and then times out. Any suggestions? – guice99 Jan 27 '19 at 21:46
  • Does your WinSCP command-line/script work, when you execute it from command-line (`cmd`)? – Martin Prikryl Jan 28 '19 at 07:12
  • It seems I'm unable to enter anything into the console command-line. When my code runs, the console pops up and reads: "option batch abort; option confirm off; searching for host..." and then times out. I tried double quotation marks and that didn't make a difference. – guice99 Jan 28 '19 at 17:06
  • finally got to use my script in the cmd line and it says "too many parameters for cmd synchronize". – guice99 Jan 28 '19 at 18:11
  • As the second path contains a space, it needs to be surrounded by double-quotes: `synchronize local C:\Users\Aaron\Documents\test "/home/FTP/Acct Hourly Acctg"` – Martin Prikryl Jan 28 '19 at 18:29
  • now its saying "host does not exist". I'll keep playing with it. Thank you Martin – guice99 Jan 28 '19 at 19:49
  • How can it now fail on `open` command already, when it previously passed it and failed on `synchronize`? You must have changed something. – Martin Prikryl Jan 28 '19 at 20:19
  • finally got it! Thanks again – guice99 Jan 28 '19 at 21:36
  • Martin, I am trying to implement this at work where we have shared network folders. When I run script it fails to update the local folder that resides on our shared network. Any suggestions? open sftp://passwork:username@xxx.xxx.x.xx/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:82:40:be" synchronize local S:\sharednetworkpath\WinSCP\ftpfiles "/Home/MC FTP/MC Hourly Acctg/" exit – guice99 Jan 29 '19 at 20:54
  • Looks good. Consider asking a new proper question with details on your problem, including a session log file. – Martin Prikryl Jan 29 '19 at 21:43