Scp 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

asked Oct 13, 2014 at 18:12

Liondancer's user avatar

LiondancerLiondancer

15.8k51 gold badges152 silver badges255 bronze badges

2

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

answered Oct 13, 2014 at 18:17

Craicerjack's user avatar

4

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

answered Jan 24, 2019 at 8:44

dw-herrmann's user avatar

dw-herrmanndw-herrmann

4814 silver badges5 bronze badges

0

In my case I had to specify the Port Number using

scp -P 2222 username@hostip:/directory/ /localdirectory/

answered Feb 13, 2018 at 17:38

joelschmid's user avatar

joelschmidjoelschmid

8281 gold badge16 silver badges32 bronze badges

1

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

answered Jan 7, 2019 at 15:47

3edf1w's user avatar

3edf1w3edf1w

1052 silver badges9 bronze badges

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.

answered Sep 8, 2020 at 9:27

Sambada Budiarga's user avatar

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

answered Dec 24, 2020 at 0:55

Adam Winter's user avatar

Adam WinterAdam Winter

1,6781 gold badge12 silver badges27 bronze badges

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…

answered May 21, 2019 at 5:06

Astariul's user avatar

AstariulAstariul

2,2204 gold badges25 silver badges42 bronze badges

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

help-info.de's user avatar

help-info.de

6,70516 gold badges39 silver badges41 bronze badges

answered Oct 27, 2019 at 8:56

BeMyGuest's user avatar

1

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

answered Sep 4, 2020 at 4:15

HuangHudson's user avatar

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

answered Apr 16, 2021 at 16:36

Arpatma's user avatar

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

answered Aug 16, 2022 at 18:32

EngrEric's user avatar

EngrEricEngrEric

4,7921 gold badge8 silver badges6 bronze badges

In my case, the remote folder I was trying to upload to was belonging to root. I had to chown it to the correct user:group.

answered Aug 17 at 15:17

Tim Autin's user avatar

Tim AutinTim Autin

6,0535 gold badges46 silver badges77 bronze badges

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.

SCP stands for Secure Copy Protocol and it is based on the “Secure Shell” protocol. It provides a method for transferring files between computers. In this transfer, either both the computers can be remote hosts or one computer can be a localhost and the other, a remote host. Quite recently, a lot of users have been getting the “No Such File or Directory” Error while trying to copy files with SCP.

No Such File Or Directory Error

In this article, we will discuss some of the reasons due to which this issue is triggered and also provide viable solutions to fix it completely. Also, we will look into some of the reasons due to which it is triggered. Make sure to follow the guide carefully and accurately to avoid conflict.

What Causes the “No Such File or Directory” Error in SCP?

After receiving numerous reports from multiple users, we decided to investigate the issue and devised a set of solutions to fix it completely. Also, we looked into the reasons due to which it is triggered and listed them as follows.

  • Incorrect Command: In some cases, the command that is being used by the user to copy the file might not be correct. You must modify the copy command to fit the current situation in which you are copying. The commands for copying files and a whole directory are different. Also, the command to copy between two computers with different configurations is changed as per the requirements.
  • Port Number: It is also possible that the port number for copying files between computers hasn’t been specified. The correct port must be forwarded before trying to copy files between two hosts.
  • Incorrect Login: If you are currently logged into the server and are trying to copy the files to a desktop, you might experience this error because the server tries to find the local path within the server. This can be prevented by logging out of the server path.
  • File Permissions: In some cases, the permissions of the files that are to be copied might be limited to “Read-Only”. This can prevent the server from accessing the files and from being able to copy them. It is important the Read and Write permissions are provided for the files.

Now that you have a basic understanding of the nature of the problem, we will move on towards the solutions. Make sure to implement these in the specific order in which they are presented to avoid conflict.

Solution 1: Using Correct Commands

You must use the correct command depending upon the configuration of hosts between which you want to transfer the files. For this, we will be listing some of the commands that can be used to transfer files between different host configurations.

To Copy From Local Host to Remote Host

The Localhost is the actual computer to which you have physical access. The Remote Host is the one to which the user doesn’t have any physical access and it is located in a distant server. To transfer files from a Localhost to a Remote Host, you have to use the following command configurations.

$ scp "the_file" your_username@the_remote_host:the/path/to/the/directory

An example to copy a text file named “Alexa.txt” will be as follows.

$ scp Alexa.txt your_username@remotehost.edu:/some/remote/directory

In the same way, you can copy a whole directory in the following way

$ scp -r "the_directory_to_copy" your_username@the_remote_host:the/path/to/the/directory/to/copy/to

An example to copy a directory named “Alexa” would be as follows.

$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

To Copy From Remote Host to Local Host

If you wish to copy a file from the Remote Host to a Local Host, the command configurations differ from the original ones. Below are indicated the appropriate commands to copy files between a Remote Host and a Localhost.

To copy a File, use the following command

$ scp your_username@the_remote_host:the_file /your/local/directory

To copy a file named “Alexa.txt“, use the following commands

$ scp your_username@the_remote_host:Alexa.txt /your/local/directory

Solution 2: Identifying Port Number

The Port Number of the remote host must be identified before copying the file to the computer. For that, we will be adding the port number while initiating the copying process.

You can use the following command to copy between computers while indicating the port number.

$ scp -P port_number your_username@the_remote_host:the_file /your/local/directory

This same command can be used to indicate the port number while copying to or from a remote host. You just need to add the “-P (Port number)” after the “$ scp ” portion of the command.

Solution 3: Changing Permissions

The appropriate permissions must be provided to the file while copying them between computers. Therefore, in this step, we will be indicating the process to change a file’s permissions. For that:

  1. Rightclick on the file that you are trying to copy.
  2. Click on “Properties” and select the “Security” tab.
    Clicking on “Properties”
  3. Make sure that all the permissions are provided to the “System” and the “Administrator“.
    Clicking on “Allow” for all Permissions

Note: Also, make sure that you don’t log in to the server path while copying the files.

Photo of Kevin Arrows

Kevin Arrows

Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.

  • Home
  • News
  • No Such File Or Directory In SCP: How To Fix The Error

By Sarah |
Last Updated

Are you familiar with the error — No such file or directory? Probably you will say yes, right? But do you know what does it mean in SCP? If not, you should read the following content carefully since it introduces the causes of No such file or directory error in SCP and the corresponding measures you should take to solve the problem yourself.

You may see the No such file or directory error now and then in different problems. Here in this article, I will mainly talk about the No such file or directory error in Secure Copy Protocol. What triggers this SCP error? How to fix it in different ways without others’ help? All these questions will be answered below.

No such file or directory

Please pay much attention to MiniTool Solution since it is professional in storage management and problem solving.

No Such File or Directory in SCP

First of all, I’d like to explain what SCP is. As the acronym of Secure Copy Protocol, the SCP refers to a security file transfer protocol between a local host and a remote host or among different remote hosts. SCP is developed on the basis of Secure Shell (SSH) protocol and used to help people transfer files among different devices. The SCP has many in common with FTP (File Transfer Protocol) except that the former adds security and authentication.

However, a lot of people reported recently that come across SCP no such file or directory error when they are trying to copy files with the program. Noticing this, I decide to list some of the common reasons that cause the SCP error and the corresponding solutions to fix it.

Create Script To Copy Files From One Folder To Another On Win10.

Causes of No Such File or Directory Error

There are mainly 4 reasons that should be responsible for the Secure Copy Protocol – no such file or directory.

  • Port number is not specified: the user didn’t specify the certain port number before they copy files between devices. To complete the file copying process successfully, you must forward correct port in advance.
  • File permissions settings are not correct: if the permission of a file is set to read-only, it means you can only access the file and look for information you need. You are not allowed to copy or move it unless the Read and Write permissions are offered for the file.
  • Login is not correct: the SCP error could occur when you are trying to copy files to certain desktop after you have logged into the server. Why? That’s because the server will try to find the local path within it. In this case, you should log out of the server path to solve the problem.
  • Command is not correct: if the command you’re using to copy files between devices is not correct, you will encounter no such file or directory. You should go to modify the command to make it correct. Please remember that the command used to copy a certain file is not the same as that used to copy a whole directory.

How to Fix Secure Copy Protocol Error

* 1: identify the port number correctly.

If you’re not sure about the port number, you should use this command to copy files between devices since it can indicate the port number:

$ scp -P port_number your_username@the_remote_host:the_file /your/local/directory

It can be used to indicate port number when you are trying to copy files to a remote host (or from it).

Note: You should know that the “-P (Port number)” should be added to the command and placed after the “$ scp” portion.

* 2: check and modify permissions.

As said earlier, you must make sure that enough permission is provided to the file you’re copying so as to avoid the Secure Copy Protocol error. So you should do the following things:

  1. Open File Explorer and navigate to the file you want to copy.
  2. Right click on the file and choose Properties.
  3. Uncheck the Read-only option under General tab.
  4. Click on the Apply button to confirm.
  5. Shift to the Security tab and check whether all the permissions are provided to the System and Administrator.

Read-only

How to fix when the File Explorer is not working/responding?

* 3: make sure the command you’re going to use is correct.

Here are some of the most commonly used commands for copying files.

Copy files from local host to remote host:

  • $ scp “the_file” your_username@the_remote_host:the/path/to/the/directory (copy a file)
  • $ scp name.txt y[email protected]:/some/remote/directory (copy a file)
  • $ scp -r “the_directory_to_copy” your_username@the_remote_host:the/path/to/the/directory/to/copy/to (copy a whole directory)
  • $ scp -r foo [email protected]:/some/remote/directory/bar (copy a whole directory)

Copy files from remote host to local host:

  • $ scp your_username@the_remote_host:the_file /your/local/directory
  • $ scp your_username@the_remote_host:name.txt /your/local/directory

That’s it. Do you know how to cope with no such file or directory now?

About The Author

Position: Columnist

Sarah has been working as an editor at MiniTool since she graduated from university. Sarah aims at helping users with their computer problems such as disk errors and data loss. She feels a sense of accomplishment to see that users get their issues fixed relying on her articles. Besides, she likes to make friends and listen to music after work.

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

Понравилась статья? Поделить с друзьями:
  • Scp containment breach ошибка memory access violation
  • Scp 000 ошибка
  • Scotsman mf 56 ошибки
  • Scorn не запускается ошибка unreal engine
  • Scorn ошибка при запуске