bash command to copy file from one computer to another - macos

Wasn't quite sure how to word this but let's say I've used ssh to remote into my friends MacBook (macbook_b) from my MacBook (macbook_a).
What command would I use to copy a file/directory to my MacBook (macbook_a) from my friends MacBook (macbook_b)?
Thank you.

You can use scp (Secure Copy).
To copy FROM your machine to friends:
scp file_to_copy user#remote.server.fi:/path/to/location
In another direction:
scp user#remote.server.fi:/path/locatio/file_name file_name
If you need to copy an entire directory, you'll need to use the recursive flag, like this:
scp -r directory_to_copy user#remote.server.fi:/path/to/location

Assuming you're logged in on macbook_b:
scp file_to_copy username#macbook_a:/path/to/destination
or if you're logged in on macbook_a:
scp username#macbook_b:/path/to/file_to_copy local_destination

I think this link would help you with the answer you are looking for. In this you can use scp ssh source destination example for your scenario you have requested for.
Also refer to this question which has been already answered. It might help.

first do pwd to get the path to the file of your friends macbook then
go into your machine's ssh window and do
scp user_name#machine_name(of your friend's):(copy the path after executing pwd)/file_name .(dot means your your current directory)
enter his password !
voila !!!

Related

Download zip file from s3 using s3cmd issue

I have two issues I need help with on bash, linux and s3cmd.
First, I'm running into linux permission issue. I am trying to download zip files from a s3 bucket using s3cmd with following command in a bash script.sh:
/usr/bin/s3cmd get s3://<bucketname>/<folder>/zipfilename.tar.gz
I am seeing following error: permission denied.
If I try to run this command manually from command line on a linux machine, it works and downloads the file:
sudo /usr/bin/s3cmd get s3://<bucketname>/<folder>/zipfilename.tar.gz
I really don't want to use sudo in front of the command in the script. How do I get this command to work? Do I need to give chown permission to the script.sh which is actually sitting in a path i.e /foldername/script.sh or how do I get this get command to work?
Two: Once I get this command to work, How do I get it to download from s3 to the linux home dir: ~/ ? Do I have to specifically issue a command in the bash script: cd ~/ before the above download command?
I really appreciate any help and guidance.
First, determine what's failing and the reason, otherwise you won't find the answer.
You can specify the destination in order to avoid permission problems when the script is invoked using a directory that's not writeable by that process
/usr/bin/s3cmd get s3:////zipfilename.tar.gz /path/to/writeable/destination/zipfilename.tar.gz
Fist of all ask 1 question at a time.
For the first one you can simply change the permission with chown like :
chown “usertorunscript” filename
For the second :
If it is users home directory you can just specify it with
~user
as you said but I think writing the whole directory is safer so it will work for more users (if you need to)

Cygwin to use my windows username in path?

I'm writing a script where Cygwin needs to cp a file from my desktop.
cp /cygdrive/c/Users/<username>/Desktop/file /tmp/file
How can I make Cygwin get my or the username of the person who is currently running it?
I found it in a different answer,
The profile of the current user is $USERPROFILE.
Putting them together it becomes:
cp $USERPROFILE/Desktop/file /tmp/file

Macos SSHFS produce broken mountpoint

broken mount point, as it seens in mc
I'm trying to mount my work servers to local folder.
"sudo sshfs webuser#rgslb.com:/var/www/webuser/data/www /Volumes/rgslb.com"
It asks me password and silently proceed. But as result I have broken file, in mc it looks like ?rgslb.com, but "ls -l" says that there no this file in /Volumes. And when I unmounted it this mount point directory disappear.
Have any one has same situation? Thank you.
I got simple solution, do sshfs... without sudo, to ~/rgslb.com. And it works.

How do I move a file from one unix based server to another using bash?

I have two servers. I would like to move a file from a directory in server A to a directory in server B using bash. Anyone have any ideas on what the best way to do this would be?
Thanks in advance.
Why don't you use scp (take a look) or rsync (again, you can find some information here) ?
copy it
$ scp user#server:/location/of/file .
delete it
$ ssh user#server 'rm /location/of/file'
Standard commands to "move a file" include "cp" (if the remote directory is mounted), "scp" (the secure successor to "rcp") and, of course, "ftp". Any of these commands can be scripted with "bash". To "move" a file, your script would "rm" the original file.
If you're doing this regularly, for many files, some of which might already exist (and not need to be re-copied), then perhaps "rsync" might be a better approach:
http://www.howtoforge.com/mirroring_with_rsync
'Hope that helps!

scp upload file: no such file or directory

I'm using ssh to connect with a linux server. I'm trying to upload a file from my own computer(windows7) to linux.
When I type scp Desktop/H5.txt xxUserNamexx#mumble-39.xxServerNamexxx:/u/private/
I got following error:
scp Desktop/H5.txt xxUserNamexx#mumble-39.xxxServerNamexxxx:/u/private/
Desktop/H5.txt: No such file or directory
I can guarantee the server name and the file directory is correct. It seems that scp cannot find my file on my local computer.
What's the default path? What path should I type if the file I'm intending to upload is on my desktop?
Thank you
winscp is a nice option to copy files from MS to *nix. Also pscp is useful. SCP have known issues when used between MS and nix. There seems to be some misunderstanding of folder structure by scp.
drap the H5.txt from desktop to you cmd windows, this can avoid you type the wrong path
In the future you could try using winscp when you're dealing with small files. Also I think a cygwin scp should work just fine.
The slashes are incorrect. On Windows, it should be (assuming you are running Command Prompt from your Home directory):
C:\Users\user> scp Desktop\H5.txt junjue#mumble-39.xxServerNamexxx:/u/j/u/junjue/private/

Resources