Sync Remote Remote directory with a local Directory

Advertisement

ntoreax
Joined:
Posts:
15

Sync Remote Remote directory with a local Directory

Good morning Everyone
I am facing an issue where a wrote this script to sync Remote directory with Local Directory and every time the script runs I get
Nothing to synchronize.
C:\Users\axel.ntore\Documents\Ntore>"C:\Program Files (x86)\WinSCP\winscp.com"  /scri
pt=C:\Users\axel.ntore\Documents\Ntore\syncfilescriptwinscp.txt
batch           abort
confirm         off
Searching for host...
Connecting to host...
Authenticating...
Using username "user001".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] user001@172.28.66.19
Using configured synchronization options different from factory defaults.
Comparing...
Local 'C:\Users\axel.ntore\Documents\031722\031722' => Remote '/'
Nothing to synchronize.

C:\Users\axel.ntore\Documents\Ntore>pause
Press any key to continue . . .
script details
option batch abort
option confirm off
open sftp://user001@172.28.66.19 -hostkey="ssh-ed25519 255 AwCsIqqS6p8caWKAOYNtQwkU2ae2xtG5wnIBHU3gOKg="
synchronize remote C:\Users\axel.ntore\Documents\031722\031722 /
exit
Bat file that calls the script
"C:\Program Files (x86)\WinSCP\winscp.com/script=C:\Users\axel.ntore\Documents\Ntore\syncfilescriptwinscp.txt
 
pause
Please advise what could be the cause and how I can approach this.
If any details missing to understand the file transfer automation let me know.

Axel N

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

Re: Sync Remote Remote directory with a local Directory

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, use /log=C:\path\to\winscp.log 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.

Reply with quote

ntoreax
Joined:
Posts:
15

Sync Remote Remote directory with a local Directory

Good Day,
apologies for the late reply.
Attached is the requested logs. The scripts remains the same but I changed the running machine in case your wondering the difference in the keys :)
Outcome still the same, nothing to sync.
If any clarification needed am here and thanks for your support.
  • logfile.zip (459 KB, Private file)
Description: winscp script logs

Reply with quote

martin
Site Admin
martin avatar

Re: Sync Remote Remote directory with a local Directory

Please, give us a name of one specific file that you expected to get synchronized and explain why.

Reply with quote

ntoreax
Joined:
Posts:
15

Re: Sync Remote Remote directory with a local Directory

Good Day martin

the file name on local machine/server lexaccs_20220313194756514.txt, lexaccs_20220313202756510.txt,... are generated after 1 min and I want those files to be copied to Remote location which is a Linux server / Ubuntu server. And using WinSCP is the best option.
The current script shows the files to be sync, but it does not copy them to remote.
But when I do the same from the GUI (WinSCP) it keeps both source and destination up to date.

And the reason why I wanted to use the script is that on the source (local server) I have 2 different directories that receives such files every one min to be sent to that remote server.
Also in the GUI sometimes hang ... that why the script is the best option for me.

Hope I answered your question. If not am here to clarify and thanks for your time.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

Re: Sync Remote Remote directory with a local Directory

The file 031722lexaccs_20220313194756514.txt already exists in the remote directory and it is newer than the local copy:
. 2022-04-05 15:54:39.145 Remote file '/lexaccs_20220313194756514.txt' [2022-03-30T18:02:23.000Z] [209] is modified comparing to local file 'C:\Users\axel.ntore\Documents\031722\031722lexaccs_20220313194756514.txt' [2022-03-13T17:46:11.017Z] [209]
Though there's something wrong with the paths. Isn't there missing backslash between 031722 and lexaccs_20220313194756514.txt in C:\Users\axel.ntore\Documents\031722\031722lexaccs_20220313194756514.txt. What is even the C:\Users\axel.ntore\Documents\031722(\031722)? Where does it come from? I see that you are synchronizing D:\home\rndps\MTN\user800\BULKUPLOAD. Is that a link to the C:\Users\axel.ntore\Documents\031722?

Can you post a GUI log file that shows that GUI synchronizes 031722lexaccs_20220313194756514.txt right after the script did not?

Reply with quote

ntoreax
Joined:
Posts:
15

Re: Sync Remote Remote directory with a local Directory

Afternoon
as requested here is the newly Captured logs
  • logfile.zip (673.16 KB, Private file)
Description: sharing new log file

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

Re: Sync Remote Remote directory with a local Directory

I do not see any lexaccs_20220313194756514.txt (nor 031722lexaccs_20220313194756514.txt) in the new log.

Can you post logs from both script and GUI that show, how script does not synchronize a specific file (name it) that the GUI does, when executed right after the script? Can you also answer my path questions from my previous post?

Reply with quote

ntoreax
Joined:
Posts:
15

Sync Remote Remote directory with a local Directory

Noted , if i understand you well i capture a screenshot showing the files in source directory that are not being picked and also attach logs showing the results
let me do that hope i did not miss any steps of your request

also to clarify on the file name (lexaccs_20220313194756514.txt ...) in the new log.
am running the script on both my test machine and prod to see if its not a box issue

let me share logs from my prod box since its where am running it but file name will be different you will see it in the logs
let me capture all the information and thanks for your support

Reply with quote

Advertisement

ntoreax
Joined:
Posts:
15

Sync Remote Remote directory with a local Directory

As Requested
attach are the logs and the screenshot
  • screenshotSync.png (20 KB, Private file)
Description: SynccmdScreenshot
  • logfile.zip (2.26 MB, Private file)
Description: WINSCPLGOS

Reply with quote

ntoreax
Joined:
Posts:
15

Sync Remote Remote directory with a local Directory

Thanks for the quick feedback
all the files with new were not picked, I attach a new set of logs with more details
  • when I run the script it check but does not pick the files (3 files highlighted)
  • when I log to WinSCP and do keep remote sync the files are being picked not sure why on the script it shows nothing to sync
  • logfile.zip (816.48 KB, Private file)
Description: logswhenirunthescript
  • scriptResultCmd.png (34.69 KB, Private file)
Description: result of the script that is suppose to pick the files and move them to the server
  • beforescriptrun.png (45.13 KB, Private file)
Description: before script run

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

Re: Sync Remote Remote directory with a local Directory

You are synchronizing "existing files only":
. 2022-04-28 13:05:54.517 Collecting synchronization list for local directory 'D:\home\rndps\MTN\user800\BULKUPLOAD' and remote directory '/', mode = Remote, params = 0x6 (NoConfirmation, ExistingOnly), file mask = ''
I assume that unintentionally. Your script is not isolated from your GUI configuration, what is against recommendations:
https://winscp.net/eng/docs/scripting#configuration

The script even warns you about that:
< 2022-04-28 13:05:54.517 Script: Using configured synchronization options different from factory defaults.
Adding /ini=nul to WinSCP command line should fix your problem.

Reply with quote

Advertisement

ntoreax

Sync Remote Remote directory with a local Directory

Thank you very much the issue is fix.
Indeed the problem was with /ini=nul part the isolation was the key.

Reply with quote

ntoreax
Joined:
Posts:
15

Keep Remote Server Up to Date

Dear martin
I wrote another Script almost similar to the one on this post
# Connect to the Linux server
open sftp://sftpusername:ServerPassword@ServerIp
# Change to the remote directory where you want to copy the files
cd /var/pswift/ESICIA
# Change to the local directory where the files are located
lcd D:\home\lbo\lbo.extracts\ESICIA
# Set transfer mode to binary
option transfer binary
# Copy all new files to the remote directory
synchronize remote -criteria=newer
# Disconnect from the Linux server
close
# Exit the script
exit
the bat Script that exec the file
@echo off
 
set WINSCP_PATH=C:\Program Files (x86)\WinSCP\WinSCP.com
set SCRIPT_PATH=C:\Users\axeln\Music\ecisciaScript.txt
set LOG_PATH=C:\Users\axeln\Music\ecisciaScript.log
 
"%WINSCP_PATH%" /log="%LOG_PATH%" /command "open sftp://sftpusername:SFTPPass@serverip" "option transfer binary" "cd /var/pswift/ESICIA/" "lcd D:\home\lbo\lbo.extracts\ESICIA" "synchronize remote -criteria=newer" "exit"
 
pause /b %errorlevel%
when I execute it, get nothing to be synchronize.
Logs are attached on the file please advise what could be the issue and how I can sort it thank you.
If any info needed let me know.
  • ecisciaScript.log (25 KB, Private file)
Description: logs of sync Script

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

Re: Keep Remote Server Up to Date

@ntoreax: Can you give us a name of one specific file that you expected to get synchronized by your command? From the logs it looks like the newer files are in a remote directory. But you are synchronize local to remote (synchronize remote). Maybe you wanted to synchronize remote to local (synchronize local)?

Btw, there's nothing like -criteria=newer
See https://winscp.net/eng/docs/scriptcommand_synchronize#criteria

Reply with quote

ntoreax
Joined:
Posts:
15

Keep Remote Server Up to Date

Good day @Martin

Thanks for the prompt feedback and I would like to confirm the source is local server and destination is a remote server which is why I used the synchronization script am attaching the logs and the names and screenshot showing the missing files that were not sent when I run the script.

Missing files are ESICIA_202360421, ESICIA_202360422, ESICIA_202360423, ESICIA_202360424.
  • ecisciaScript.log (26.21 KB, Private file)
Description: logfile Recent

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,392
Location:
Prague, Czechia

Re: Keep Remote Server Up to Date

From the log, it does not look like those files existed in the local directory, at the time the WinSCP script was executed.

If you believe otherwise, add this to your batch file before and after WinSCP commandline:
dir D:\home\lbo\lbo.extracts\ESICIA
"%WINSCP_PATH%" ...
dir D:\home\lbo\lbo.extracts\ESICIA
And post complete output of your batch file, along with WinSCP script.

Reply with quote

Advertisement

You can post new topics in this forum