Scp no such file or directory linux

scp is giving no such file or directory

I am trying to do a simple scp with sshpass command as shown below and running into this error. any ideas really appreciated. Please note that I have tried scp and not cp. Infact this line is in a script, I tried it on the linux command line I got this error. I have also tried escaping the Environment variables with ‘ and » and \ and all combos, but that doesn’t seem to have helped.

root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient/bin# sshpass -p '$H_PASSWORD' scp -v $H_USERNAME@$H_HOSTNAME:server.pem . Executing: cp '--' 'admin@abc-def.brilliant.local' '.' cp: cannot stat 'admin@abc-def.brilliant.local': No such file or directory Executing: cp '--' ':server.pem' '.' cp: cannot stat ':server.pem': No such file or directory root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient/bin# 

If I explicitly use this command i got it to work, not sure why. Please not that hostname in these outputs have been edited to some goofy names

root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# sshpass -p $HSM_PASSWORD scp admin@grs-defcon.brilliant.local:server.pem . ls -lia root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# ls -l | grep ser -rw-r--r-- 1 root root 1172 Apr 28 12:23 server.pem root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# date Sat Apr 28 12:24:29 UTC 2018 root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# 
sshpass -p "$H_PASSWORD" scp -v $H_USERNAME@$:server.pem . 

another thing I have noticed is if I do the env on this container, I see an extra line in the environment variable , could that be an issue. See how this env shows. Note that I have not entered a line on purpose, when I type env command I see line next to the H_HOSTNAME and the H_PARTITION which is weird H_PARTITION=Operator

MYSQL_PORT=tcp://11.123.113.242:3306 LUNAHS=TRUE H_HOSTNAME=grs-defcon.brilliant.local ROOT_PORT_443_TCP_PORT=443 MYSQL_PORT_3306_TCP_ADDR=11.456.231.242 

Источник

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

Your mistake is where you have connected to the remote machine and then typed the command. You should run the command from your own system in the directory where the file exist not when you have connected..

I just had this issue and the problem was where to run the command. If I want to transfer from A to B machine — run ssh on A and connect to B, then run scp command on A ( in another terminal) and enter paths accordingly

Читайте также:  Изменение имя компьютера astra linux

11 Answers 11

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

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 username@remotehost:/path/to/directory/on/remote/host

Thanks for the help. This comes close to solving my problem but not quite yet. I want to be able to send the directory and all of its contents. What I tried is scp -r path/to/directory username@remotehost

In case you need to explicitly specify port number do it by using -P portNumber. e.g.` scp -P 2200 bprajapati@192.168.202.124:/tmp/bs-404 ~/Documents`

Just an important point that tripped me up. If using the scp://user@host:port/path/to/file syntax for a target or source, note that the first ‘/’ after the port number just delimits the port from the path. So, if you want to use an absolute path, use two backslash characters after the port number: scp://user@host:port//my/absolute/path/to/file

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/ 

And make sure you’re using upper-case P instead of p. If you ask me the «no such file» error message given by scp is extremely misleading and possibly even classifiable as a bug. For example if you make the same mistake with ssh, it says «ssh: connect to host 2222 port 2222: Invalid argument» which is MUCH more helpful.

Your problem can be caused by different things. I will provide you three possible scenarios in Linux:

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 must know the File Permission your File has. If you have Read-only you should change it.

Читайте также:  Linux узнать версию nginx

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 .

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 

Источник

«No such file or directory» error when attempting to copy (using scp) from remote host to local machine

I am attempting to copy a file (/home4/user/public_html/website.com/folder_1/folder_2/file_to_copy.zip) from my remote host to my local machine’s desktop (/Users/username/Desktop) using the scp command. In order to accomplish this I run iTerm on my Mac and use the following command:

scp -r user@remotehost.com:/home4/user/public_html/website.com/folder_1/folder_2/file_to_copy.zip /Users/username/Desktop/ 

(It might also be worth noting that I am logged in via ssh to my remote host as I try to execute this command.) When I run the command I am prompted to fill in the password for user@remotehost.com (which I do) and then I receive the following error message:

Similarly, I have been unable to use scp to copy files to my remote host. Any help with this issue is highly appreciated, and I hope that I can receive simple/thorough explanations as I am completely new to using a command line and ssh.

I see, and I find that reasonable since I running this command prompts me to provide the password for user@remotehost.com. When I ran the above command on my local host it timed out. I think this is due to it using the wrong port (22 instead of 2222). How do I change which port it should use when running the command?

My problem was a permissions issue on the remote filesystem, once I fixed file permissions, it worked like a charm.

1 Answer 1

scp does not require that you SSH to the remote computer in order to make the copy (and this is where you’re currently running into trouble with your command).

scp essentially works in either a push or pull fashion. You can push files/folders from your local PC to a remote. The command syntax for this method is as follows:

scp /folderpath/tofile/file.txt user@remotehost:/folderpath/tocopyfileto/ 

Which will prompt you for the password of user on remotehost .

You can also pull file/folders from a remote PC to your local PC. The command syntax for this method is as follows:

scp user@remotehost:/folderpath/tofile/file.txt /folderpath/tolocalfolder/ 

Which will also prompt you for the password to user on remotehost .

The problem you were running into with your command above is that you were using the data pull syntax of the scp command in order to grab a file from a remotehost, but you were also SSH’d into that remotehost while running it.

Читайте также:  Посмотреть версию кали линукс

The correct way to run this command is to run it from your local machine

scp -P 2222 user@remotehost.com:/home4/user/public_html/website.com/folder_1/folder_2/file_to_copy.zip /Users/username/Desktop/ 

**Note that I removed the superfluous -r from your original command. It’s not something that will throw off an error, but it’s just that it’s not necessary in your case. The -r option of scp is to be used when recursively copying a folder and all its contents. In your case you were just copying a file so it wasn’t necessary.

**I also added the -P 2222 since subsequent comments from you indicated that you needed to use port 2222 instead of standard port 22.

Источник

Why does scp say «No such file»?

I have a bash script that uses scp to copy a file from my machine to another. The script keeps on exiting after I enter the SSH password with the error:

: No such file or directory 

Yet, in the script, I check the file, and it is just fine. I did set -o verbose at the beginning and here’s what I get at the end of the script:

scp /Volumes/FX4\ HDD/Users/matthewdavies/Downloads/NCIS.S11E01.HDTV.x264-LOL.mp4 root@rpi.local:"/media/3TB/TV\ Shows/NCIS" root@rpi.local's password: /Volumes/FX4\ HDD/Users/matthewdavies/Downloads/NCIS.S11E01.HDTV.x264-LOL.mp4: No such file or directory 

try with scp /Volumes/FX4\ HDD/Users/matthewdavies/Downloads/NCIS.S11E01.HDTV.x264-LOL.mp4 root@rpi.local:»/media/3TB/TV Shows/NCIS»

What’s the difference between that and what I pasted there? And it says «scp: ambiguous target» because it’s missing a «, but I added that in, and it works just fine…

you don’t have to escape the whitespace ` ` in double-quotes. actually, I think it had to be scp /Volumes/FX4\ HDD/Users/matthewdavies/Downloads/NCIS.S11E01.HDTV.x264-LOL.mp4 «root@rpi.local:/media/3TB/TV Shows/NCIS» because the last part(destination) is counted as a whole argument.

1 Answer 1

I’m not entirely sure what you’re doing, but when I try the command you have in your example I get the following:

$ scp /home/saml/projects/Cooks.com\ -\ Recipe\ -\ Coconut\ Chicken.mht \ root@remotey:"/root/some spaced out file.mht" scp: ambiguous target 

This is because you’re quoting the target path and it also includes backslashes which are escaping the spaces. However when the current shell peels off the double quote, it will also peel off the single backslash, leaving the target path as a bare string with spaces. You need to do one of the following to nest it further, so that the spaces are correctly escaped:

Examples

method #1 — double quote, single quote

$ scp /path/with\ spaces/file\ with\ spaces.txt \ user@remotey:"'/home/user/some spaced out file.txt'" 

method #2 — single quote, double quote

$ scp /path/with\ spaces/file\ with\ spaces.txt \ user@remotey:'"/home/user/some spaced out file.txt"' 

method #3 — single quote, backslash

$ scp /path/with\ spaces/file\ with\ spaces.txt \ user@remotey:'/home/user/some\ spaced\ out\ file.txt' 

method #4 — double quote, backslash

$ scp /path/with\ spaces/file\ with\ spaces.txt \ user@remotey:"/home/user/some\ spaced\ out\ file.txt" 

method #5 — triple backslashes

$ scp /path/with\ spaces/file\ with\ spaces.txt \ user@remotey:/home/user/some\\\ spaced\\\ out\\\ file.txt 

Источник

Оцените статью
Adblock
detector