Liondancer
Liondancer

Reputation: 16489

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

Upvotes: 72

Views: 304935

Answers (17)

I was logged in the server and trying to download the file to local PC. What you want is to directly (no logging to the server) type that "scp -P [email protected]:path/file.pdf /your/local/directory" and it worked.

Upvotes: 0

Navy
Navy

Reputation: 1

Here is my solution:

  1. Use the local command prompt
  2. Ignore the C:/Users/user1 (it depends on the directory before the > in the command prompt)
  3. if it is a file, add the extension of the file(you can check the extension using dir "/your path/", eg: dir "Downloads")

Here are examples of successful uploads (folder use 1, file use 2, -r means upload all the files inside the folder):

  1. scp -r "Downloads/abc" [email protected]:~/folder1
  2. scp "Downloads/abc.txt" [email protected]:~/folder1

Upvotes: 0

bdbdbd
bdbdbd

Reputation: 503

I had this issue when copying something from my DietPi server to my FreeBSD machine. At first I suspected it was a filesystem issue but it turned out to be OpenSSL instead.

I added the -O flag which apparently enables some compatibility mode since in SCP since OpenSSH 9 and later.

scp -O [email protected]:/local/machine/path/filename filename

Upvotes: 7

Hashim Aziz
Hashim Aziz

Reputation: 6185

In my case this (ridiculously misleading) error was down to not having the right permissions to access the file and the directory. I temporarily changed the permissions of both by SSHing into the server and running the following commands:

chmod 777 /var/lib/mysql-files/
chmod 777 /var/lib/mysql-files/file.txt

I was then able to run:

scp username@host:/var/lib/mysql-files/file-to-download.txt /local/path/to/target/folder

It's also a good idea to set the directory back to its default permissions, especially if it's a system directory. In my case this was 700 for the mysql-files directory.

chmod 700 /var/lib/mysql-files

Upvotes: 1

Alberto Juliao O.
Alberto Juliao O.

Reputation: 2015

Had same error here, I wanted to transfer a cfg file from my router to my local windows pc because it wouldn't let me the other way (router refuses to accept shell command requests from ssh clients). After many tries this worked for me, from the router terminal I can do:

# scp romfile.cfg [email protected]:/Users/

Where admin must be the account username (not the machine hostname), in my case my local ip and the folder 'Users' that is in C:\Users

For this to work you have to install an ssh server on your pc, I used OpenSSH Server because I'm using Windows.

Upvotes: 0

Tim Autin
Tim Autin

Reputation: 6165

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.

Upvotes: 0

EngrEric
EngrEric

Reputation: 4852

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

Upvotes: 0

Arpatma
Arpatma

Reputation: 31

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

Upvotes: 0

Adam Winter
Adam Winter

Reputation: 1944

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' [email protected]:/home/ec2-user/IwantThisFile.tar IgotThisFile.tar

Or, in your case:

cd /local/path/where/you/want/the/file/to/land
scp [email protected]:/local/machine/path/to/directory/filename filename

Upvotes: 1

Sambada Budiarga
Sambada Budiarga

Reputation: 88

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.

Upvotes: 1

HuangHudson
HuangHudson

Reputation: 11

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

Upvotes: 0

BeMyGuest
BeMyGuest

Reputation: 11

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/ [email protected]:/target/folder

Upvotes: 1

Astariul
Astariul

Reputation: 2363

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...

Upvotes: 0

dw-herrmann
dw-herrmann

Reputation: 589

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

Upvotes: 48

3edf1w
3edf1w

Reputation: 115

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 [email protected]:/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 [email protected] /var/www/html

Upvotes: 6

Craicerjack
Craicerjack

Reputation: 6332

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 [email protected]:/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 [email protected]:/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 [email protected]: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 [email protected]: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

Upvotes: 104

Steinbock
Steinbock

Reputation: 868

In my case I had to specify the Port Number using

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

Upvotes: 7

Related Questions