Topic "Scripting help!!"

Author Message
jrp78
[View user's profile]

Joined: 2016-10-07
Posts: 16
Location: SoVA
I'm struggling to understand scripting. I can do exactly what I want in the GUI but can't figure out how to script it all. I'm connecting to an SFTP server with a private key and synchronizing files remotely to a local copy. It works awesome in the GUI but I need to setup a script to run every hour. I have attached a screenshot of all the settings I'd like to have in the script. Could someone be so kind as to help me out or point me to a good example of everything I'm trying to do.

Needs:
1. Syntax for opening connection to SFTP server with PPK
2. Syntax for all the options as shown in the attached screenshot.

Here's what I started trying to piece together but I no clue if it's right.

WinSCP.com /command ^
"option batch abort" ^
"option transfer binary" ^
"option synchdelete on" ^
"option exclude "D:\inetpub\web\alert.xml;D:\inetpub\web\emergency.xml;D:\inetpub\web\.htaccess;D:\inetpub\web\notice.xml;D:\inetpub\web\sitemap.xml;D:\inetpub\web\web.config;D:\inetpub\web\wincache.php;D:\inetpub\web\fileshare\;D:\inetpub\web\xml-sitemap-generator\" ^
"open sftp://username@xxx.xxx.xxx.xxx/ /privatekey=C:\scripts\Puttygen\privkey.ppk" ^
"synchronize local d:\inetpub\web\ /web/" -preview ^
"close" ^
"quit" ^
/log="C:\scripts\WinSCP-5.9.1-Portable\t4log!Y_!M_!D_!T.log" /loglevel=0

[/img]
settings.PNG (71.7 KB) [Download]

Description: (none)

Advertisements
Guest




Well, I got it working but I'm still concerned if I have the settings in the command line matching the GUI exactly? See previous post for pic. Thanks again.

@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\scripts\WinSCP-5.9.1-Portable\t4log_!Y_!M_!D_!T.log" /loglevel=0 /ini=nul ^
/command ^
"open sftp://username@serverip/ -hostkey=""ssh-rsa 2048 xx:xx:xx:xx"" -privatekey=""C:\scripts\Puttygen\privkey.ppk""" ^
"option batch abort" ^
"option transfer binary" ^
"option synchdelete on" ^
"synchronize local d:\inetpub\web\ /web/ -criteria=both -filemask=""| alert.xml; emergency.xml; .htaccess; notice.xml; sitemap.xml; web.config; wincache.php; fileshare/; xml-sitemap-generator/""" ^
"close" ^
"quit" ^
"exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)

exit /b %WINSCP_RESULT%
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Would be easier, if you explicitly name the options, we should look for.

You are definitely missing the -delete switch for the Synchronize options > Delete files.
Guest




martin wrote:
Would be easier, if you explicitly name the options, we should look for.

You are definitely missing the -delete switch for the Synchronize options > Delete files.


Thanks. I was under the impression "option synchdelete on" was the accomplishing the sync delete. If -delete in the sync string does it, do I even need "option synchdelete on" in my script?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Quote:
Thanks. I was under the impression "option synchdelete on" was the accomplishing the sync delete. If -delete in the sync string does it, do I even need "option synchdelete on" in my script?

Ok, I've missed the synchdelete. It does the same as the -delete, but it's deprecated.
Use the -delete switch instead.
jrp78
[View user's profile]

Joined: 2016-10-07
Posts: 16
Location: SoVA
martin wrote:
Quote:
Thanks. I was under the impression "option synchdelete on" was the accomplishing the sync delete. If -delete in the sync string does it, do I even need "option synchdelete on" in my script?

Ok, I've missed the synchdelete. It does the same as the -delete, but it's deprecated.
Use the -delete switch instead.


Cool, thanks Martin.
jrp78
[View user's profile]

Joined: 2016-10-07
Posts: 16
Location: SoVA
Martin,

I was just reviewing my code and I'm wondering if I have the criteria switch is incorrect.

Documentation states: -criteria=<criteria> Comparison criteria. Possible values are time, size, either and none. Ignored for both mode.

"synchronize local d:\inetpub\web\ /web/ -criteria=both -filemask=""| alert.xml; emergency.xml; .htaccess; notice.xml; sitemap.xml; web.config; wincache.php; fileshare/; xml-sitemap-generator/"""

I have both in there but am I reading the documentation incorrectly? I want it to compare both time and file size. Should I be using -criteria=either instead?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
The either is the correct option, as documented.

But the both is also accepted for a backwards compatibility reason, with the same meaning as the either.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License