scp not working saying its a directory error - backup

I am trying to copy a file to remote server in a certain folder.
Its an adrive backup plan. But it comes with scp. I can copy the file if I don't select directory. Even if I put a directory that doesn't exist it says its a directory.
root#host1 [/usr/src]# scp ftpdelete.sh user#host#scp.adrive.com:/mysql-only/
scp: /mysql-only/: Is a directory

Amazingly enough in my case it was that the directory didn't exists!! :|
Is the error message a bug?... or it's me. Tempted for the latter.

SCP doesn't automatically create you new directory if you want to scp file (it creates directory only if you do recursive copy). There is wrong error message. The error should be No such file or directory or similar.
It is known problem and there is upstream bugzilla about this [1].
[1] https://bugzilla.mindrot.org/show_bug.cgi?id=1768

You are copying the sh file to a new directory on the server, and the directory is expected to be there but in fact not(then the machine thinks you want to change the file to be a directory). Most probably the directory you set is wrong.

-r' Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.
But it doesn't create a directory but you can do below
ssh remote mkdir /diretcory
root#host1 [/usr/src]# scp -r ftpdelete.sh user#host#scp.adrive.com:/complete_path/mysql-only/
or
rsync can do the creating of directory if not exist
its basic command syntax is similar to scp:²
$ rsync -r -e ssh ftpdelete.sh me#my-system:/complete_path/mysql-only/

I saw a similar error, when tried scp to path that relative to home directory. The error fixed after removing unnecessary leading / in path:
# scp ftpdelete.sh user#host#scp.adrive.com:mysql-only/
rather then
# scp ftpdelete.sh user#host#scp.adrive.com:/mysql-only/
^

scp -r source_location user#servername:/target_location

Don't put "/" after the directory's name.

Try to download the file directly to your local root directory and then copy it from there :
root#host1 [/usr/src]# scp user#host:/root/Desktop/file.txt /root/home/

Related

Why can't I SSH from outside the .ssh folder

If I go into /.ssh dir and issue the following command
ssh -i xx.pem user#server.com
It works fine. But it I try the same thing outside that dir I get a "Identity file xx.pem not accessible" error.
I'm on Mac.
I assume your xx.pem files is located in the .ssh directory. As you are using a relative path, ssh won't find the key, unless your working directory is ~/.ssh.
Use an absolute path instead, like ~/.ssh/xx.pem.

scp files from local to remote machine error: no such file or directory

I want to be able to transfer a directory and all its files from my local machine to my remote one. I dont use SCP much so I am a bit confused.
I am connected to my remote machine via ssh and I typed in the command
scp name127.0.0.1:local/machine/path/to/directory filename
the local/machine/path/to/directory is the value i got from using pwd in the desired directory on my local host.
I am currently getting the error
No such file or directory
Looks like you are trying to copy to a local machine with that command.
An example scp looks more like the command below:
Copy the file "foobar.txt" from the local host to a remote host
$ scp foobar.txt your_username#remotehost.edu:/some/remote/directory
scp "the_file" your_username#the_remote_host:the/path/to/the/directory
to send a directory:
Copy the directory "foo" from the local host to a remote host's directory "bar"
$ scp -r foo your_username#remotehost.edu:/some/remote/directory/bar
scp -r "the_directory_to_copy" your_username#the_remote_host:the/path/to/the/directory/to/copy/to
and to copy from remote host to local:
Copy the file "foobar.txt" from a remote host to the local host
$ scp your_username#remotehost.edu:foobar.txt /your/local/directory
scp your_username#the_remote_host:the_file /your/local/directory
and to include port number:
Copy the file "foobar.txt" from a remote host with port 8080 to the local host
$ scp -P 8080 your_username#remotehost.edu:foobar.txt /your/local/directory
scp -P port_number your_username#the_remote_host:the_file /your/local/directory
From a windows machine to linux machine using putty
pscp -r <directory_to_copy> username#remotehost:/path/to/directory/on/remote/host
i had a kind of similar problem. i tried to copy from a server to my desktop and always got the same message for the local path. the problem was, i already was logged in to my server per ssh, so it was searching for the local path in the server path.
solution: i had to log out and run the command again and it worked
In my case I had to specify the Port Number using
scp -P 2222 username#hostip:/directory/ /localdirectory/
Your problem can be caused by different things. I will provide you three possible scenarios in Linux:
The File location
When you use scp name , you mean that your File name is in Home directory. When it is in Home but inside in another Folder, for example, my_folder, you should write:
scp /home/my-username/my_folder/name my-username#127.0.0.1:/Path....
You File Permission
You must know the File Permission your File has. If you have Read-only you should change it.
To change the Permission:
As Root ,sudo caja ( the default file manager for the MATE Desktop) or another file manager ,then with you Mouse , right-click to the File name , select Properties + Permissions
and change it on Group and Other to Read and write .
Or with chmod .
You Port Number
Maybe you remote machine or Server can only communicate with a Port Number, so you should write -P and the Port Number.
scp -P 22 /home/my-username/my_folder/name my-usernamee#127.0.0.1 /var/www/html
You also need to make sure what is in the .bashrc file of the user.
I've also got this ridiculous error because I put cd and ls commands in there, as it was mean to let them see the current files & directories when the user is has logged in from ssh.
The filename should go at the end of the path to the directory. That is, it should be the full path to the file. 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:
cd /local/path/where/you/want/the/file/to/land
scp name#127.0.0.1:/local/machine/path/to/directory/filename filename
Be sure the folder from where you send the file does not contain space !
I was trying to send a file to a remote server from my windows machine from VS code terminal, and I got this error even if the file was here.
It's because the folder where the file was contained space in its name...
If you want to copy everything in a Folder + have a special Port use this one.
Works for me on Ubuntu 18.04 and a local machine with Mac OS X.
-r for recursive
-P for Port
scp -rP 1234 /Your_Directory/Source_Folder/ username#yourdomain.com:/target/folder
As #Astariul said, path to the file might cause this bug.
In addition, any parent directory which contains non-ASCII character, for example Chinese, will cause this.
In that case, you should rename you parent directory
This happened to me and I solved it.
This problem can be because the file you are trying to get is not existing (typo in the name of file or folder?) or because it is invisible to the user that you enter in scp.
The problem in my case was that the files that I wanted to get from remote machine were created by another user (root on my case), so, those files were invisible
To fix, I did:
ssh myuser#myserver
chown myuser:myuser myfile
exit
scp mysuer#myserver:/home/myuser/myfile /localfolder/myfile
For me on my mac,
I just have to run the command from my MAC terminal
scp -r root#ip_addres:/root/source /Users/path/Desktop/others/destination

File location if target path not specified with scp command

To copy a folder from local computer to server I use
scp -r local_folder user#server:path
Now I forgot to specify the target path the first time:
scp -r local_folder user#server
Does anyone now if the folder has been copied and if yes, where in the server is it located at?
I issued the correct command later and copied the folder to my user directory but I just want to know whether the folder is also copied somewhere on the server the first time and find and delete it. I am a user and don't have permission to search the whole server. Thanks.
When you use user#server without a ':' character, scp interprets user#server as the file name on the local machine to which you would like to copy your file. So, you should find a file (or in this case a directory) called user#server in the directory from which you issued the scp -r local_folder user#server command.

Is it possible to make SCP ignore symbolic links during copy?

I need to reinstall one of ours servers, and as a precaution, I want to move /home, /etc, /opt, and /Services to backup server.
However, I have a problem: because of plenty of symbolic links a lot of files are copied multiple times.
Is it possible to make scp ignore the symbolic links (or actually to copy link as a link not as a directory or file)? If not, is there another way to do it?
I knew that it was possible, I just took wrong tool. I did it with rsync
rsync --progress -avhe ssh /usr/local/ XXX.XXX.XXX.XXX:/BackUp/usr/local/
I found that the rsync method did not work for me, however I found an alternative that did work on this website (www.docstore.mik.ua/orelly).
Specifically section 7.5.3 of "O'Reilly: SSH: The Secure Shell. The Definitive Guide".
7.5.3. Recursive Copy of Directories
...
Although scp can copy directories, it isn't necessarily the best method. If your directory contains hard links or soft links, they won't be duplicated. Links are copied as plain files (the link targets), and worse, circular directory links cause scp1 to loop indefinitely. (scp2 detects symbolic links and copies their targets instead.) Other types of special files, such as named pipes, also aren't copied correctly.A better solution is to use tar, which handles special files correctly, and send it to the remote machine to be untarred, via SSH:
$ tar cf - /usr/local/bin | ssh server.example.com tar xf -
Using tar over ssh as both sender and receiver does the trick as well:
cd $DEST_DIR
ssh user#remote-host 'cd $REMOTE_SRC_DIR; tar cf - ./' | tar xvf -
One solution is to use a shell pipe. I have a situation where I got some *.gz files and symbolic links generated by some software to link to the same *.gz files with a slightly shorter name. If I simply use scp, then the symbolic links will be copied as regular files and resulting in duplicates. I know rsync can ignore symbolic links, but my gz files are not compressed with syncable options, and sync is very slow in copying these gz files. So I simply use the following script to copy over the files:
find . -type f -exec scp {} target_host:/directory/name/data \;
The -f option will only find regular files and ignore symbolic links. You need to give this command on the source host. Hope this may help some user in my situation. Let me know if I missed anything.
A one liner solution which can be executed at client to copy folder from server using tar + ssh command.
ssh user#<Server IP/link> 'mkdir -p <Remote destination directory;cd <Remote destination directory>; tar cf - ./' | tar xf - C <Source destination directory>
Note: mkdir is must, if the remote destination directory is not present then the command will simply compress the entire home of the remote server and extract it to client.

Putty ssh commands zip all the files within this folder then download

oh so i cd into my folder
ls
cgi-bin wp-comments-post.php wp-mail.php
googlec3erferfer228fc075b.html wp-commentsrss2.php wp-pass.php
index.php wp-config-sample.php wp-rdf.php
license.txt wp-config.php wp-register.php
php.ini wp-content wp-rss.php
readme.html wp-cron.php wp-rss2.php
wp-activate.php wp-feed.php wp-settings.php
wp-admin wp-includes wp-signup.php
wp-app.php wp-links-opml.php wp-trackback.php
wp-atom.php wp-load.php xmlrpc.php
wp-blog-header.php wp-login.php
(uiserver):u45567318:~/wsb454434801 >
What i want to do is zip all the files within this folder then download it to my computer i am really new to ssh and this is a clients website but really want to start to use command line for speed, i have been looking a this reference http://ss64.com/bash/ to find the right commands but would really like some help from somebody please??
Thanks
cd path/to/folder/foldername
zip -r foldername.zip foldername * [use * if it has any sub directory]
Please try this code, it will solve your problem.
If you are in directory itself then
zip -r zipfilename.zip *
Go to folder path using cd command
zip -r foldername.zip foldername
Ex : zip -r test-bkupname.zip test
Here test is the folder name.
tar zcvf ../my_directory.tar.gz .
will create my_directory.tar.gz file.
scp ../my_directory.tar.gz username#your-ip:/path/to/place/file
will transfer file to your computer.
Looks like this is the webroot directory.
Why not zip the directory above (httpdocs / html / whatever) and then move this into the website space, and download from there?
i.e. go into the directory above the web root. For example, if your web root is /var/www/html/ go into /var/www/ and run the following commands:
zip -r allwebfiles.zip html
mv allwebfiles.zip /html/allwebfiles.zip
Then in your web browser go to http://mydomain.com/allwebfiles.zip and just download that file.
When extracting, you'd just need to either extract into /var/www/ OR extract into webroot and move all files up one level.
Use the following Ssh command to download multiple files at one time
mget ./*