Automatic synchronizing

Advertisement

Hendrikdegraaf
Joined:
Posts:
2
Location:
Holland

Automatic synchronizing

Hello,
I have a feeling that this is a really stupid question, but I've looked for ages and I can't find wat I am looking for.

I want to create a script that does the following:
Start WinSCP
Start a stored session
Synchronize local [local docs] [docs on server]

or,

The script starts when I start WinSCP
Start a stored session
Synchronize local [local docs] [docs on server]

I hope someone can help, because I really don't get the terminal: it sais I have to work on a seperate shell. Also I don't get the scrips on the website: it seems that many of them are scripts that start other scrips, which all seems a little farfetched.

I'm looking forward to hearing from someone.

Kind regards,
Hendrik

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Automatic synchronizing

Hendrikdegraaf wrote:

I want to create a script that does the following:
Start WinSCP
Start a stored session
Synchronize local [local docs] [docs on server]
script.txt:
open stored_session
synchronize local [local docs] [docs on server]
script.bat
winscp3.exe /console /script=script.txt

_________________
Martin Prikryl

Reply with quote

AMK
Guest

Syncronization

Hi,
I am using a WinSCP sync script in conjunction with Windows Task Scheduler. When a sync occurs and a new local file is identified, are the entire contents of the file added to the remote server or just the new parts. The reason I ask is the files on the local server become quite large (~100MB) and we have about 15 local files that change about once an hour. If the sync is copying the entire contents at each sync, we're going to kill our T1 line.

Can you advise on this matter?

Thanks

Reply with quote

bdornbush
Joined:
Posts:
1
Location:
Santa Rosa, CA

My script to do this

I had a similar need, and after reading through the site, I arrived at this script which allows me to synchronize the files from a remote server to my local PC. I do this so that I have a copy of the most recent backups from my server to my PC.

I was delighted to find WinSCP as it allows me to do secure transfers between my server and my local PC, which I consider to be essential.

I have a directory on my server named "backups." In this directory, I have another directory, "archives" which holds the files that I want to copy. In "backups," I also have the script files to do my backups.

My script was derived from some I found on this site. At first, I planned to copy files from my server to my local PC, but then I found "synchronize" and this works better for me as it only copies the new files, that is, the most recent backups. I left the copy commands for reference. The script is:

# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect
open user@server.org
# Change remote directory
cd backups
# Force binary mode transfer
option transfer binary
# Download file to the local directory
# get archives/* f:\backups\archives\*
# Delete downloaded files
# rm archives/*
# sync from remote to local
synchronize local f:\backups\archives archives
# Exit WinSCP
exit

I used Windows XP Scheduled Tasks to run this program weekly, a few hours after the backup is generated on the server. The command I used in Scheduled Tasks is:

C:\PROGRA~1\WinSCP\WinSCP.exe /console /script=f:\backups\download.txt /log=f:\backups\winscp.txt

This command runs WinSCP and uses the script "download.txt" and logs the results to "winscp.txt" These files are on my F: drive in the backups directory.

I hope that this script is useful to others.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Syncronization

AMK wrote:

I am using a WinSCP sync script in conjunction with Windows Task Scheduler. When a sync occurs and a new local file is identified, are the entire contents of the file added to the remote server or just the new parts. The reason I ask is the files on the local server become quite large (~100MB) and we have about 15 local files that change about once an hour. If the sync is copying the entire contents at each sync, we're going to kill our T1 line.
Entire file content is transferred, as there's no way for WinSCP to verify that contents of the two files matches (apart from downloading the whole file of course :-))
_________________
Martin Prikryl

Reply with quote

mixersoft
Guest

Re: script dies on open session

martin wrote:


script.txt:
open stored_session
synchronize local [local docs] [docs on server]

I'm trying to follow this exactly, but when I run the open command, I always get an interactive window to choose the saved session, and the script seems to die. This is what I am using:

# the script on errors
option batch on

# Disable overwrite confirmations that conflict with the previous
option confirm off 

# Connect
open session_name

What am I doing wrong?[/code]

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Automatic synchronizing

For automation please read FAQ.
_________________
Martin Prikryl

Reply with quote

Advertisement

AlphaUno
Joined:
Posts:
5
Location:
Nashville, TN

Trying to find the best feed to post this

Hi I am wanting to create some script that will move all the files from an one of my servers to another. This is going to be used for backup purposes and run often.

I see the synchronization is the way to go and I have easily created some batch files that will do this with winscp.

However my problem lies in that I don't want all files from that folder moved only ones with the a file name that begins with "cl"

Here is my code.



open asp1_checks

pause


synchronize -filemask="cl.*" local "Y:\checks\" "/asp1/luminx/naa/live/jacob/checks/" 

exit

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Trying to find the best feed to post this

AlphaUno wrote:

However my problem lies in that I don't want all files from that folder moved only ones with the a file name that begins with "cl"

...
open asp1_checks

pause


synchronize -filemask="cl.*" local "Y:\checks\" "/asp1/luminx/naa/live/jacob/checks/" 

exit
Duplicate post:
https://winscp.net/forum/viewtopic.php?t=11712

Reply with quote

Guest

Re: I cannot get a synchronization script to work!

YIKES. I butchered that. Let me try again:

I've tried many different example scripts and none of them seem to work for me. Can someone help me troubleshoot?

The most recent attempt, straight from the example scripts:

bat:

winscp.com /script=script.txt /parameter // %1 "/internet/remotedirectory/%~n1%~x1"

txt:

# Being intended for interactive session, we are not enabling batch mode
# Connect
open sftp://user:pword@sftp.address.gov -hostkey="ssh-rsa 1024 9c:b7:21:5c:ad:02:bb:30:c5:27:a5:bc:41:1a:ab:a0"
# Synchronize paths provided via environment variables
synchronize remote "%1%" "%2%"

I run this bat file and the window closes at: Authenticating with pre-entered password.

What I really want to do is synchronize the local folder to the remote folder, but for the sake of learning, I'm just trying to get any script working.

Previously, I had tried:

option batch abort
option confirm off
open sftp://user:pword@sftp.address.gov -hostkey="ssh-rsa 1024 9c:b7:21:5c:ad:02:bb:30:c5:27:a5:bc:41:1a:ab:a0"
synchronize local H:\LocalDirectory /internet/remotedirectory
exit

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: I cannot get a synchronization script to work!

Anonymous wrote:

I've tried many different example scripts and none of them seem to work for me. Can someone help me troubleshoot?

The most recent attempt, straight from the example scripts:

bat:

winscp.com /script=script.txt /parameter // %1 "/internet/remotedirectory/%~n1%~x1"
...

Your duplicate post on superuser.com:
https://stackoverflow.com/q/33680432/850848

The same answer:
Your script is generally correct. But we need to see a log file to help you. Add /log=c:\path\winscp.log to command-line.

Reply with quote

MCG
Guest

Access Problem

I have connected my ftp server and my aim is to get my camera records from there to my desktop.
I have already thicked Passive Mode.

When I tried to access my records in there, I got this error on my screen.
"
Error Listing Directory "X"
Could not retrieve directory listing
Invalid path specified"
"

By the way, when I clicked on the file and push the "Calculate" button it shows that there are X files and they hold X size in disk.

When I examined the permission options, all of them are not thicked initially. When I wanted to change them it also gave this error.
"Cannot change properties of file. Unknown command SITE"

Another interesting this is that I have already accessed all of my files with Filezilla.

Do you have any solution for this problem ?

Thanks a lot.

Reply with quote

MCG
Guest

Re: Access Problem

martin wrote:

Again, log file please.

CWD /110/
250 CWD command successful.
PWD
257 "/110/"
TYPE A
200 Type A Accepted
PASV
227 Entering Passive Mode (x,x,x,x,27,89) ..
LOST
Connecting to x.x.x.x:7000
125 Connected, Starting Data Transfer..
<Empty Directory Listing>
550 Invalid path specified
Could not retrieve directory listing

(ECommand) Error listing directory "110".
Could not retrieve directory listing
Invalid path specified.

This is the log file.

It says its invalid path but i have already accessed this path from filezilla.

Thanks for reply.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Access Problem

No this is not a log file.

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

A log file from FileZilla would be helpful too.

Reply with quote

bmwlover
Guest

Cant' get files

Hi,

I have video files in one server which is ftp server.
I have already list directories and video files using winscp script. These video files seems that have no file extension. When I got the video files list, I saw that "name" there is no file extension like .mpeg or whatever it is.

I tried to get this file and I wrote this code:
get /myDirectory/myVideoFile and it said to me this file/folder is not found
get /myDirectory/myVideoFile.* and it also said to me this file is not found.
* shows that i tried all possible video file extension.

Do you have any idea to solve this problem ?

Thanks.

Reply with quote

bmwlover
Guest

Re: Cant' get files

bmwlover wrote:

Hi,

I have video files in one server which is ftp server.
I have already list directories and video files using winscp script. These video files seems that have no file extension. When I got the video files list, I saw that "name" there is no file extension like .mpeg or whatever it is.

I tried to get this file and I wrote this code:
get /myDirectory/myVideoFile and it said to me this file/folder is not found
get /myDirectory/myVideoFile.* and it also said to me this file is not found.
* shows that i tried all possible video file extension.

Do you have any idea to solve this problem ?

Thanks.

Also this is my log file FYI.
  • mylog.log (9.12 KB, Private file)
Description: myLogFile

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Cant' get files

bmwlover wrote:

I have video files in one server which is ftp server.
I have already list directories and video files using winscp script. These video files seems that have no file extension. When I got the video files list, I saw that "name" there is no file extension like .mpeg or whatever it is.

I tried to get this file and I wrote this code:
get /myDirectory/myVideoFile and it said to me this file/folder is not found
get /myDirectory/myVideoFile.* and it also said to me this file is not found.
* shows that i tried all possible video file extension.
Your code looks ok. Can you download the file anyhow? In GUI? Or in other FTP client?

Reply with quote

Advertisement

bmwlover
Guest

Re: Cant' get files

martin wrote:

bmwlover wrote:

I have video files in one server which is ftp server.
I have already list directories and video files using winscp script. These video files seems that have no file extension. When I got the video files list, I saw that "name" there is no file extension like .mpeg or whatever it is.

I tried to get this file and I wrote this code:
get /myDirectory/myVideoFile and it said to me this file/folder is not found
get /myDirectory/myVideoFile.* and it also said to me this file is not found.
* shows that i tried all possible video file extension.
Your code looks ok. Can you download the file anyhow? In GUI? Or in other FTP client?

Yes.

I can download this file from Filezilla obviously and also can play and download in GUI.
I don't know what is going wrong.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Cant' get files

bmwlover wrote:

I can download this file from Filezilla obviously and also can play and download in GUI.
I don't know what is going wrong.
So show us a log from the GUI please.

Reply with quote

pankaj1111
Guest

atomatic synchronization

option batch on
option confirm off
open CSBJ01@efg.hdfcbank.com
cd backups
option transfer binary
get /Shree_Samarth_Sah_Bank_ltd* E:\testlocal*
synchronize local E:\testlocal Shree_Samarth_Sah_Bank_ltd
exit




sir this my code or script but it doenst work and Shree_Samarth_Sah_Bank_ltd this is the folder on my server and i have to get it on my local computer when computer is on so pls do

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: atomatic synchronization

pankaj1111 wrote:

option batch on
option confirm off
open CSBJ01@efg.hdfcbank.com
cd backups
option transfer binary
get /Shree_Samarth_Sah_Bank_ltd* E:\testlocal*
synchronize local E:\testlocal Shree_Samarth_Sah_Bank_ltd
exit




sir this my code or script but it doenst work and Shree_Samarth_Sah_Bank_ltd this is the folder on my server and i have to get it on my local computer when computer is on so pls do
Please start a new thread for your problem. In the new thread, describe what does it mean "it doenst work". What does it do? Do you get any errors? Or wrong behaviour?

Also, why do you use both get and synchronize? It does not make sense.

Reply with quote

Advertisement

pankaj1111
Guest

Sir i want to atomaticaly copy my remeote server files to my local pc so i have wrrinten this script and i am etering this script in to task scheduler but it does'nt work so help me for this...

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

pankaj1111 wrote:

Sir i want to atomaticaly copy my remeote server files to my local pc so i have wrrinten this script and i am etering this script in to task scheduler but it does'nt work so help me for this...
I've asked you to start a new thread. You also didn't answer my question.

Reply with quote

Advertisement

You can post new topics in this forum