How to determine full names for local Mac filename and remote filname to use SCP - macos

I used SSH to connect to a server and navigate to the folder where I want to store some files from my Mac. I think what I need to do is use SCP to do the copy but I'm not sure exactly about the terminology in the command parameters. And so far everything I've tried gets some sort of "not found" error.
Before logging on to the server the prompt is :
Apples-MacBook-Pro-2:~ neiltayl$
After logging in and navigating to the folder I want to store things in it is :
[neiltayl#cs136 Tracer]$
I need to copy several files from the Tracer folder on my local computer to the Tracer folder on cs136 and cannot fathom the correct parts of the respective FROM and TO parts of SCP to make it work.
This is the nearest I got so far;
Apples-MacBook-Pro-2:~ neiltayl$ ls
Applications Downloads Music Tracer
Desktop Library Pictures c151
Documents Movies Public dwhelper
Apples-MacBook-Pro-2:~ neiltayl$ scp ./Tracer/*.* neiltayl#cs136.cs.iusb.edu:Tracer
neiltayl#cs136.cs.iusb.edu's password:
./Tracer/*.*: No such file or directory

The scp command is -
$ scp File1 username#someting:DIRNAME
Here File 1 is the file that you are sending over to the other computer.
DIRNAME is the path to the directory where you want the file to be stored.
In your case the command would be
scp -r Tracer neiltayl#cs136:New_Tracer
Here Tracer is the folder that contains all the files that you want to copy.

Related

Moving directory from remote host to local

I need to copy a directory from a remote host to my local laptop. I have seen from previous posts that in order to do that I type,
scp -r user#remotehost.ac.uk:/path/to/dirtory/ /home/user/Desktop
But I get,
/home/user/Desktop: No such file or directory
why is that happening?
When you do:
scp -r user#remotehost.ac.uk:/path/to/dirtory/ /home/user/Desktop
The following will happen:
the command will connect to user#remotehost.ac.uk
it will try to copy this folder "/path/to/dirtory/" to the specified location "/home/user/Desktop"
The thing is that folder "/home/user/Desktop" must exist on your computer. You should check that the "/user/" actually exists, maybe you mistyped.

SCP says file has downloaded, but the file does not appear

I am using ssh to work on a remote server, however when I try to download a file using scp in this format:
scp name#website.com:somefile.zip ~/Desktop
It asks me for my password, and shows this:
somefile.zip 100% 6491 6.3KB/s 00:00
however, this file never appears on my desktop. Any help
I think that you are logging into the remote machine using ssh and then running the command on the remote machine. You should actually be running the command without logging into your remote server first.
You need to specify the file path
scp name#website.com:/path/to/somefile.zip ~/Desktop
~/Desktop should actually be a directory, not a file. I suggest that you do the following:
Remove the ~/Desktop file with rm ~/Desktop (or move it with mv if you want to keep its contents).
Create the directory with mkdir ~/Desktop.
Try again to scp the zip file.
BTW, when I need to copy files into directories, I usually put a slash after the directory to avoid such problems (in case I make a mistake), e.g. scp server:file ~/Desktop/; if the directory doesn't exist, I get an error instead of unwanted file creation.
You are doing this from a command line, and you have a working directory for that command line (on your local machine), this is the directory that your file will be downloaded to. The final argument in your command is only what you want the name of the file to be. So, first, change directory to where you want the file to land. I'm doing this from git bash on a Windows machine, so it looks like this:
cd C:\Users\myUserName\Downloads
Now that I have my working directory where I want the file to go:
scp -i 'c:\Users\myUserName\.ssh\AWSkeyfile.pem' ec2-user#xx.xxx.xxx.xxx:/home/ec2-user/IwantThisFile.tar IgotThisFile.tar
Or, in your case, (that is with the VERY strong password you must be using):
cd ~/Desktop
scp name#website.com:/path/to/somefile.zip somefile.zip

How to modify ~/.ssh folder & files in windows?

I feel like I am missing some fundamental concept as to how the .ssh directory works in windows. I have had no issues when working in OSX/Linux like I am having now. My end goal is simply to move my existing ssh key into the default ~/.ssh directory, and update the config if I so choose (you know, normal ssh key related tasks).
However, any time I have tried to move my existing SSH key over to the ~/.ssh directory, or open it, or even create a config file I just get the following error (in either gitbash, puttygen, etc...):
Puttygen (saving the key to disk):
Overwrite existing file C:\Users\me\.ssh?
or in gitbash (attempting to do anything, including just create the config file):
touch: creating `/c/Users/me/.ssh/config': No such file or directory
cd ~/.ssh
sh.exe": cd: /c/Users/me/.ssh: Not a directory
What am I missing/not understanding?
Kind Regards,
u353
This answer for Windows environment:
At the beginning, Windows didn't have .ssh folder.
Create an ssh key file pair like this (ssh-keygen is nowadays a native Windows command, that comes with Windows 10+11):
ssh-keygen -t rsa -b 4096 -C "your_email#example.com" (must run your terminal as administrator).
Your is_rsa and id_rsa.pub files will be placed under C:\Users\your_username\
So, you need to create the folder C:\Users\your_username\.ssh then copy your ssh files (the extensionless private key and the public key ending in .pub) to there.
You also have to create file C:\Users\your_username\.ssh\config and edit it for the first time.
Next ssh will be placed in the .ssh folder automatically.
Note: ~/ under Linux is the equivalent of C:\Users\your_username\ on Windows
I have created and regularly use a ".ssh" directory on Windows 7; as mentioned in the above comments, Windows Explorer doesn't support them, or more specifically, the error-checking in Windows Explorer does not allow you to give a file name that starts with a period. That same restriction does not exist in the command prompt or powershell.
Also, as mentioned above, it appears you have a file called ".ssh" in your home directory, which must be removed before you can create a folder named ".ssh".
Once such a folder exists, you can open it and change/create files in it using Windows Explorer; it just won't let you name a folder/file ".ssh" directly.
Gitbash should directly allow you to run "rm .ssh" and "mkdir .ssh", at which point everything else should work.
It is quite possible to add a . in the beginning of a directories name using File Explorer, it can be easily done by adding a . at the end of the directory name as well. For example:
To create a directory named .shh, just add the name as .ssh. and it will be created without any error.
And as #Bryson mentioned, this can be done from the cli as well, without appending a . at the end.
Coming to this in 2018, given that on Windows 10 you have the Optional Feature OpenSSH client installed it appears that on Windows a .ssh folder is created for you under C:\Users\<your_username>\.ssh
This is a feature that allows you to use PowerShell to SSH into remote hosts, and seems to be pretty similar in usage to the Linux/Unix equivalent. It was already installed for me when I setup my computer, but you can read the following for how to verify it's installed or install it:
You can check if it's installed by going to Settings -> Manage Optional Features, and then checking if you see OpenSSH in the list. If it is then your .ssh folder is probably in your home directory C:\Users\<your_username>\.ssh. If you need to install it then click "Add a feature", locate OpenSSH Client, click it and click install to install it.
Use git bash on windows
go to home directory as
$ cd
then to check .ssh folder on home directory use
$ ls -A
you will be able to see a ./ssh folder there
$ cd ./ssh
$ ls
you will be able to see the config files if exists
To transfer any key-pair or any files to this folder use below command
First to that directory in which you already have key-pair
$ cp name_of_key-pair_file.pem ~/.ssh/
First of all, if you want to generate SSH files, all you need to do is run this command:
ssh-keygen
Once you did, .ssh folder will be generated in this path:
C:\Users\your_username\
For checking what files are in .ssh folder you can easily run this command:
ls ~/.ssh
with this above command, you can see all your ssh files which would be like this:
id_rsa id-rsa.pub
Please note that:
id_rsa : It's a private file and
id-rsa.pub : It's a public file
so, if you like to see inside of that file or whatever you like just type this command :
cat ~/.ssh/id_rsa.pub
To solve this problem I used git batsh console
This isn't supported as Windows doesn't recognize dot files as directories.

Automatically copy contents of FTP folder to local Windows folder without overwrite?

I need to copy all the files of an FTP folder to my local Windows folder, but without replacing the files that already exist. This would need to be a job/task that runs unattended every hour.
This is what the job would need to do:
1. Connect to FTP server.
2. In ftp, move to folder /var/MyFolder.
3. In local PC, move to c:\MyDestination.
4. Copy all files in /var/MyFolder that do not exist in c:\MyDestination.
5. Disconnect.
I had previously tried the following script using MGET * (that runs from a .bat), but it copies and overwrites everything. Which means that even if 1000 files were previously copied, it will copy them again.
open MyFtpServer.com
UserName
Password
lcd c:\MyDestination
cd /var/MyFolder
binary
mget *
Any help is appreciated.
Thanks.
Use wget for Windows.
If you want to include subdirectories (adjust the cut-dirs number according to the depth of your actual remote path):
cd /d C:\MyDestination
wget.exe --mirror -np -nH --cut-dirs=2 ftp://UserName:Password#MyFtpServer.com/var/MyFolder
If you don't want subdirectories:
cd /d C:\MyDestination
wget.exe -nc ftp://UserName:Password#MyFtpServer.com/var/MyFolder/*
The "magic" bit (for this second form) is the -nc option, which tells wget not to overwrite files that are already there locally. Do keep in mind that old files are also left alone, so if a file on your FTP server gets edited or updated, it won't get re-downloaded. If you want to also update files, use -N instead of -nc.
(Note that you can also type wget instead of wget.exe, I just included the extension to point out that these are Windows batch file commands)

DOS ftp listing to local file

I'm trying to find a way to see if a file exists on an ftp site via DOS. I tried a get command on the file hoping that if it didn't exist it wouldn't download it to my local directory. However it seams that it still does, but it's an empty file. This doesn't work for me however because the file I'm looking for is just a empty trigger file so I can't tell the difference.
I would like to dump a listing ls of the ftp directory to a text file on my local drive and so I try
ls > listing.txt.
It creates the listing.txt file locally but it's always empty even though there are files on the ftp site.
What are my options with this?
I have used dir > listing.txt and ls > listing.txt and every time listing.txt is empty even though there are files in the directories I'm running those commands on.
Sorry if I didn't make this clear, but I'm trying to get the listing for an automated process and not simply for my visual when manually doing this.
Unless you're on FreeDOS, you're probably not using DOS. Perhaps you're using ftp.exe in the windows console? If that's the case, don't use a normal file redirect. Instead check here the syntax for ls in the standard Windows ftp client:
ls [RemoteDirectory] [LocalFile]
So you can do a ls . listing.txt to get a list of files in the current remote directory. The listing.txt file will appear in your user directory, e.g. c:\Users\user.

Resources