How to use rsync for Windows on both ends? - windows-10

I install rsync for Windows through git-bash. If the remote end is Linux, it works fine. However, it does not work if the remote end is Windows. I install rsync on the remote end and test working as well, but it seems somehow it cannot locate its counterpart on the remote end.
$ rsync file user#host:
'rsync' is not recognized as an internal or external command,
operable program or batch file.
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(228) [sender=3.2.3]
Note, ssh and scp between the two Windows work well.

I ran into the same problem recently, none of the methods described on the Internet satisfied my needs, so I came up with another one:
https://medium.com/#vitezslav.kot/two-way-file-synchronization-using-rsync-and-ssh-public-key-authentication-on-windows-c99323c7a308

Related

Cannot run rsync when pushing to linux server

When I try to sync a directory with the following command
rsync -r ssh /path/to/file user#IP:/destination
I get the following error code
rsync: Failed to exec ssh: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(84) [sender=3.0.7]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(603) [sender=3.0.7]
First off I know there are tons of links out there with this exact same problem but none of them have been helpful for me. Quite a lot of them recommend installing openssh which I already have and works fine on its own. I don't use cygwin either, so many other posts weren't helpful. Also, I've tried many variants of the above command line.
Some details of my implementation are that my local laptop uses Windows 10, the server I am trying to push to uses Ubuntu 18.04. I can easily create an ssh link between the two and rsync works perfectly fine on both devices when they are just copying files locally.
I don't know where my rsync package comes from because it was already installed on my computer when I got it, but the executable is located here: C:\Windows\SysWOW64\Empirum\rsync.exe
and ssh is located here C:\Windows\System32\OpenSSH\ssh.exe
the openssh folder is in my path so I don't know why rsync would have trouble finding it. I've been banging my head on this problem for a while now so any help would be very appreciated

xcopy, net use not working from Linux machine

I am trying to copy files from windows server to network shared folder via VPN . Here is my code from batch file. This is working fine without any issues.
net use \\servername\test_folder password /user:user_name
xcopy C:\Apache\htdocs\arul\xias \\servername\\test_folder
But when I try to run this from Linux machine it is not working. This Linux machine is also connected to network shared folder via VPN. So I tried below on Linux machine in .sh file.
net use \\servername\test_folder password /user:user_name
cp C:\Apache\htdocs\arul\xias \\servername\\test_folder
I am getting errors like net command is not found and cp: -r not specified;
How to achieve this from Linux machine ?
The commands "net use" and "xcopy" are specific to Windows and will newer work on linux.
You should use some smb specific commands instead (of course, the kernel must support them).

SCP error: Bad configuration option: PermitLocalCommand

When I execute this command below:
scp -P 36000 hdfs#192.168.0.114:~/tmp.txt SOQ_log.txt
I get an error:
command-line: line 0: Bad configuration option: PermitLocalCommand
Does anyone know why?
scp runs a copy of the ssh program to create the communications channel, and it runs ssh with the options:
-oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes
So that explains where the "PermitLocalCommand" option is coming from in the first place. I'll add that sftp uses the same options to run ssh, so it'll probably display the same behavior.
"PermitLocalCommand" is normally a valid ssh configuration option. If your copy of ssh is complaining about it, then it seems that your copy of ssh isn't the normal copy of ssh that goes with your copy of scp.
This serverfault question suggests that the error could be due to someone installing a malware version of ssh (ie, a rootkit) on your system. This forum thread also suggests that the problem is due to having an altered version of ssh, which was fixed by removing and reinstalling the OpenSSH client utilities.
An alternate explanation would be that someone--maybe your Linux distro maintainer--has installed a version of ssh on your system with that option removed, and you're using it unawares. Or you have a very old version of the ssh program for some reason, which doesn't support the option.
My system is CentOs 5.9
I'm facing the same problem, I found it to be due to this configuration line in /etc/ssh/sshd_config:
# override default of no subsystems
Subsystem sftp /opt/libexec/sftp-server
But I cannot run /opt/libexec/sftp-server, it is broken for some reason
now it is solved by reinstall the remote openssh-server:
yum erase openssh-server
yum install openssh-server
now the changes to
# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server
and /usr/libexec/openssh/sftp-server is runnable
don't forget to execute:
/etc/init.d/sshd restart
Sometimes command cannot parse this kind of stuff
:~/
Id change it to the full path.

How to transfer file from Windows to Linux server, process it with shell script, and download results back

I normally do this using WinSCP: I transfer a .tex file from my local Windows machine to a Linux server. I run a script (on the server) to pdflatex the file for me. And I use WinSCP again to copy the output .pdf to my local Windows machine again. I would like to automate the copying process in my script.
So the first step is to copy file.tex from C:\Doc...\source to ~/Documents. I think I need to use the scp command, but the server sees my local machine as a remote machine. That's why I'm confused as to how the first directory needs to be specified:
$scp C:\Doc...\source\file.tex ~/Documents
doesn't work because the server doesn't know how to talk to my local machine. I have the same issue for the scp command I need to use to copy file.pdf back to my local Windows machine.
Can anybody help me with these two scp commands?
Thanks in advance!
You can use WinSCP in scripting mode. It (naturally) supports the upload/download. But it can also execute the shell script on the server with call command (with some limitations, which should not matter in your simple case):
winscp.com /log=winscp.log /command ^
"open scp://username:password#example.com/" ^
"cd /remote/path" ^
"put my.tex" ^
"call pdflatex ..." ^
"get my.pdf" ^
"exit"
(I'm the author of WinSCP)

Change size of files on Windows machine from remote Linux machine

I need to change somehow size of files (increase or decrease) on Windows machine using bash scripts. (Content of files doesnt matter) But i have to run this scripts from remote linux machine. I've selected truncate command for size changing, this is exactly that i need, cause i need to change size exactly of chosen file, without changing it's descriptor. It is very important.
But i DO NOT have truncate on my linux machine and i CANNOT install it there (So dont tell me to install it there plz :)). I cannot install nothing on my linux machine it has specific kernel - this is a main option of all my problems.
So i've decided to install cygwin on my Windows machine, cause it has truncate command. Also i know that there are fallocate command, but my linux machine also doesnt have it, and cygwin doesnt have it too. So if there is some another command i wanna know it :)
Then after this steps i tried to change file size from cygwin terminal via truncate and all works perfectly. And the last problem that i had to solve was just run cygwin's bash from my remote linux, i've chosen winexe for that.
Finally the way that i've chosen is:
I run winexe command on my linux machine that runs:
winexe myHost "c:\cygwin\bin\bash.exe myScriptWithTRUNCATE"
on my Win machine.
But it doesnt work and i dunno why. truncate command doesnt change size of files at all. When i type
truncate --help
all works, i can see result of help option on my linux terminal, but e.g.
truncate -s someSize myFile
doesnt work, size of file doesnt change. Also error code from truncate -s someSize myFile is 0
Any suggestions?
try giving the name of your script that is "myScriptWithTRUNCATE" directly in winexe command .
example:-
winexe myHost "c:\cygwin\bin\bash.exe myScriptWithTRUNCATE"
also check debug log of winexe by modifying winexe command as :-
winexe -d 5 myHost "c:\cygwin\bin\bash.exe myScriptWithTRUNCATE"
see in this log what actually is sent over to windows as command in place for your script.
specifically see in " CTRL: sending command : run xxxxx"
see what "xxxxx" is in that debug log.
winexe gives you the control of windows command line(cmd.exe).
Try running you script after it has got control of cmd.exe.
Based on some findings above , try this link for more help
http://blog.dotsmart.net/2011/01/27/executing-cygwin-bash-scripts-on-windows/

Resources