rsyncing using cygwin's rsync from the Windows Command Prompt - cmd

I am pushing a local file to a folder in a remote location using cygwin's rsync from the Windows Command Prompt.
The below command
D:\My Folder>C:/cygwin/bin/rsync.exe -avh data.csv ec2-user#someserver.com::~"overhere/"
returns the error, "failed to connect to someserver.com : connection timed out"
When I try the following command to place the file in the remote location root folder,
D:\My Folder>C:/cygwin/bin/rsync.exe -avh data.csv ec2-user#someserver.com~
it says "sending incremental file list" but I am not able to find the file in the root folder in the remote location.
What am I doing wrong?

The timeout most likely occurs because there is no rsync daemon running on the server known as someserver.com.
Using :: after the remote host name will cause rsync to try to connect to the rsync daemon running on that machine. If you use : instead, rsync will attempt a shell access to copy your data.
Your second call to rsync.exe succeeds because rsync.exe -avh data.csv c2-user#someserver.com~ creates a copy of data.csv in your current working directory named ec2-user#someserver.com~.
If you use shell access, you can directly provide the path after the :, if using the rsync daemon, you have to provide the module name as configured in /etc/rsyncd.conf on the server after the ::. So in your case it is either ec2-user#someserver.com:~/overhere/ for shell access or ec2-user#someserver.com::MODULE for the daemon.
But as I suspect that you have no rsync daemon running on the remote machine, you'd have to install and configure it first for the second version to work. The first version will do through normal SSH access.
So as a first attempt you can try: D:\My Folder>C:/cygwin/bin/rsync.exe -avh data.csv ec2-user#someserver.com:overhere/
This will create a folder named overhere in the ec2-user's home directory on someserver.com if it doesn't already exist and copy the local data.csv into that directory.

Related

Jmeter-Transfer a file from server ( using ssh sftp) to local

I need to copy file from remote server to local and trying it by using SSH SFTP using JMETER.I gave login credentials and in "File Transfer" section , selected
Actions-- PUT
source path -- remote path ( /ftp/xxx/yyy)
Destination -- local path.
Received error as `
java.io.FileNotFoundException: C:\apache-jmeter-5.1.1\bin\ftp\xxx\yyy)
So I changed the Actions-- GET in View results tree for SSH SFTP response I see data of file,
but file is not copied to local directory
Any help would greatly appreciated.
All the parts of the "Destination path" must exist, i.e. you need to create all /ftp/xxx/yyy folder structure using mkdir command like:
mkdir -p /ftp/xxx/yyy
The user which executes JMeter must have write permissions to the destination path, give him the appropriate permissions using chmod command
You need to set "Print file content" to false
More information: Load Testing FTP and SFTP Servers Using JMeter
Also according to JMeter Best Practices you should always be using the latest version of JMeter so consider upgrading to JMeter 5.4.1

How to stop an actively running for loop

This might be a silly question. I wanted to copy thousands of files from a remote server to my local machine using scp. I ran the below command directly on the command line of the remote server (after logging in with ssh)
for file in $(ls <SOURCE_DIR>)
do scp $file <LOCAL_ID>#<LOCAL_IP_ADDRESS>:<TARGET_DIR>
done
But after running this I realized that <TARGET_DIR> is owned by root, so the for loop requests a password, and if I enter the password it throws a Permission denied error message. This is repeating over and over again every loop cycle. Is there any way to get out of the for loop without pressing Ctrl + C thousands (the number of files in <SOURCE_DIR>) of times? Both the server and local use Ubuntu 18.04.
Bash itself will not let you access remote host , but you can use SSH:
Step 1: On your local PC generate key to perform password-free authentication later
$ ssh-keygen
It will ask you to enter passphrase. If you want your bash script to be fully non-interactive, you can opt not to use any password.
Step 2: Copy you public key to the remote host and paste it in .ssh/authorized_keys
Step 3: Use scp to copy files:
$ scp -ir .ssh/sshfile username#host:/sourcedirectory targetdirectory
The above command will copy all the files and folders in the respective source directory in the server

Copy folder from an http source to a local directory

I am trying to copy a folder from an http source using the following statement:
FileUtils.cp_r 'http://else.repository.labs/static/lit/MDMInternalTools/', 'c:\Users\Public\Desktop\'
However I get this error:
EINVAL: Invalid argument - https://else.repository.labs/static/lit/MDMInternalTools/
If that's a folder on a server that you have access to via ssh, then you can use scp to copy individual files, or a folder with all subfolders/files, using the -r option. The command will be something like
scp -r username#http://else.repository.labs:/path/to/rails/public/static/lit/MDMInternalTools c:\Users\Public\Desktop
This is assuming you can use scp. It looks like you're in windows, you'll need a decent command-line shell where you can install ssh.
https://en.wikipedia.org/wiki/Secure_copy
You can check if the server supports webdav, have an ftp or an ssh access.
Otherwise your only choice could be to use wget to get a local mirror:
wget -mk http://else.repository.labs/static/lit/MDMInternalTools/

rsync to move file from local to remote machine and execute command on remote machine

I have one file in my local Linux machine and I want to move that one to remote machine and then execute one command on remote machine to restart the service. The issue is after moving the file the remote connection get closed. I have used the following command:
rsync --remove-source-files -av -e ssh -t /home/testdata.txt root#vdstvmaster:/home/; service restart
If I execute the above command file is successfully moved to remote machine. But the second command (service restart) is not executed on remote machine.
rsync can use a remote shell to perform the copy operation. But it is not meant as a "general-purpose" remote shell application. Just invoke the second command over SSH locally after the rsync command like this:
rsync --remove-source-files -av -e ssh -t /home/testdata.txt root#vdstvmaster:/home/
ssh root#vdstvmaster service restart
BTW some people may consider remotely logging into another machine as root bad security.

Moving a folder from Desktop to the server?

I have a folder in my Desktop. I want to copy it to my server in Terminal.
I tried this unsuccessfully
[~/bin]# cp -r /Users/Sam/Desktop/tig-0.14.1 ~/bin/
cp: cannot stat `/Users/Sam/Desktop/tig-0.14.1': No such file or directory
[edit]
I run the command in my server. The problem seems to be in the fact that "/Users/Sam/Desktop/tig-0.14.1" is a folder in my Mac, not in my server.
Perhaps, I cannot move the folder so simply to my server because my server do not know where my folder locates.
I have always moved the folder by GUI. Is the same possible also just in terminal?
From the server:
scp -r username#A.B.C.D:~/Desktop/tig-0.14.1/ ~/bin/
username is your shortname on your local mac.
A.B.C.D is the IP address of your local mac as seen by the server.
You will be prompted for your password.
Or if you wanted to push from your local client:
scp -r ~/Desktop/tig-0.14.1/ serveruser#W.X.Y.Z:~/bin/
serveruser is the user on the server whose ~/bin you want to copy into.
W.X.Y.Z is the IP address of the server as seen by your client.
You will be prompted to enter serveruser's password.
scp is part of ssh. See 'man scp' (from the terminal) for more info.
From your Mac (not the server):
# scp -r ~/Desktop/tig-0.14.1 myUsername#myServerName:~/bin
replace myUsername and myServerName appropriately.
cp is not the correct command. Try scp instead; it has similar use and you can use it like this: (see the manual for reference)
from linux client:
scp user1#host1://Users/Sam/Desktop/tig-0.14.1 ~/bin/
if you use a windows client you can use winscp to do this in "drag&drop" style
cp: cannot stat/Users/Sam/Desktop/tig-0.14.1': No such file or directory`
That's the problem, alright: the file you're trying to copy is not where you thought, or not named what you typed. As suggested in comments you can try using tab completion at the prompt to make sure you have everything correct:
# cp /Users/Sam/Desk<TAB>
# cp /Users/Sam/Desktop/tig<TAB>
# cp /Users/Sam/Desktop/tig-0.14.1.tar.gz
Note that tig-0.14.1.tar.gz is probably the actual file name, as found in the wild...

Resources