SCP command not working - need to copy file from Windows localhost to Linux - linux

I need to copy file admin.zip from C:\wamp\www\jdhemumbai060714\webfiles (Windows) to /var/www/html/ (Linux). I am using following command::
scp C:\wamp\www\jdhemumbai060714\webfiles\admin.zip username#hostname:/var/www/html/
But it does not work and gives error::
ssh: Could not resolve hostname C: Temporary failure in name resolution
I am logged in Linux server using SSH

I think that it is bug in SCP port.
Only way is skip "C:" and use only "\wamp\www\jdhemumbai060714\webfiles\admin.zip"
It will work if current directory is on the same disk like file for upload.
Or you can use pscp.exe

Well firstly is your DNS server able to resolve the HOSTNAME your copying too? My Advice would be to use IP Address.
scp C:\wamp\www\jdhemumbai060714\webfiles\admin.zip username#192.168.0.2:/var/www/html/

BELOW ANSWER APPLICABLE ONLY FOR EC2 OR WHICH HAS PEM KEY.
Open Windows CMD, and Type
scp -i Keypair_Along_with_Path.pem YOUR_FILENAME_ALONG_WITH_PATH.txt USERNAME#PUBLIC-IP:DESTINATION_PATH
Real Example:
scp -i C:\Users\Keypair.pem C:\Users\File.txt ubuntu#1.1.1.1:/tmp/.
You are done.

Related

Issues with using Jump Host

How do I transfer a file from my local machine to a remote host to which I need to get through a jump host? These are the steps I follow to connect to the remote host
1. ssh myname#jump-host
2. enter password
3. sudo su - another-random-name
4. ssh name#remote-host
Now I want to transfer a file from my local machine to the remote-host. How would I achieve this? I have already tried scp -oProxyCommand but I don't quite know where I should include step 3 as part of this command?
Use port forwarding to get third host ssh port on your localhost, in this way:
ssh -L 2222:remote-host:22 myname#jump-host
then (on another tab/shell on first host):
scp -P 2222 file myname#localhost:
will copy directly to remote host.
On the jump host under another-random-name run
ssh -L 2222:remote-host:22 myname#jump-host
then on your local computer you can run
scp -P 2222 file name#jump-host:
SCP will try to connect to jump-host, while in fact this connection will be forwarded to jump-host. And will use name as it is connecting to remote-host.
You are probably still facing problem with certificate for another-random-user. You can either create certificate on your machine for your-local-user and put public key on remote-host in user allowed keys.

is it posible to SCP remote server to remote server to local in one command line?

I am connected to a bridge server and from there I am connected to another server, so I wanted to know if it's possible to use SCP command to copy files or folders in just one line, without having to stand on the bridge and scp from remote to bridge and then scp from bridge to local.
If its not possible I will understand.
Thank you for any response.
Yes, if your first server supports IO redirect:
scp -oProxyCommand="ssh -W %h:%p user1#server1" user2#server2:/path/to/remote.file local.file

Sending .csv file from linux to windows

I want to send files (txt or csv) from linux to windows.
I already have a script to get information and put it into a .txt or .csv file, tried with many ways to send this file from linux to my computer.
there is a ping from server to my computer IP, but when i use below commands it gives:
ssh: connect to host 10.10.X.X port 22: Connection timed out
scp -r fname.lname#10.10.X.X:/home/ test.txt
or
scp test.txt fname.lname#10.10.X.X:/C:/Data
Please could you help, simply I wanna have a copy of file (that I have it in server) in my computer, to use it.
there is some similar questions with no answer here.
You need a ssh server installed on windows. Windows does not currently have out of the box ssh server. They are thinking of implementing OOB ssh servers in future releases of windows 10.
Have a look at this link https://winscp.net/eng/docs/guide_windows_openssh_server
Also, if the file transfer that you want is a one time transfer, you can use putty with a reverse scp to retrieve the file or you can use WINscp ( https://winscp.net/eng/download.php )
I usually use the command 'nc' for file transmission.
But since on Windows you have to install a cygwin to use nc, so I think the simplest solution may be like the following.
On linux, go to the directory of those files, and then type:
python -m SimpleHTTPServer 1234
Then on windows you can visit 10.10.X.X:1234 in your browser, and download those files.
Note that 1234 can be replaced by any other port which is not currently used on linux.

Using SCP command to download files from Linux server to client server

I'm creating files on a Linux server that I'm logged into and I'm adding the ability for the user to download these files from the Linux server on to the connecting computer. I'm writing a scrip and using the scp command to download these files:
scp data.txt user#usraddress:/home/usr
However, I don't want to specify "user#usraddress:/home/usr" to be just my computer. I want whoever is logged onto the linux server to be able do download these files. Is there a way to get the address of the connecting computer?
How would I do this?
Forgive me if this seems elementary, I'm very new to scripting.
When you open a remote session in a GNU/Linux machine, the ssh server sets the environment variable SSH_CONNECTION with some connection information. You can use this variable and the $USER variable to fill that parameters:
scp data.txt $USER#${SSH_CONNECTION%% *}:/home/$USER
Note that as far as I know you couldn't assume the client home directory is at /home. As said by chepner, you could omit the destination directory to use the default location, the home directory.
scp data.txt $USER#${SSH_CONNECTION%% *}:

How to put a .jsp file on tomcat in Linux terminal?

I want to ask a question about the tomcat and the Linux terminal. I have a jsp file and a tomcat server. After I use the terminal to login in my Linux computer, I want to put the file to the tomcat server. However, I don't know the cmd of this action. Does anyone can help me?
P.S can also provide some basic cmd for the Linux system?
Do you mean a Remote linux terminal ? Do you use ssh ? Or you are sitting in front of it. If so, you type command "locate tomcat" it should print out the path, and then "cd path" as it was printed out. Then "cp /home/user/path/to/your/file.jsp ./"
But it's just a hint how to do that, not exact instructions. If it is on remote server, you need to run "$ ssh username#hostname.org" This way you can get to the remote server and copy the file from your home and do there whatever you want. Or the other way around. Copy jsp from your home and then ssh to the remote server
Copy the file "file.jsp" from the local host to a remote host
$ scp file.jsp username#remotehost.com:/path/to/tomcat/dir
Copy the file "file.jsp" from a your home to the linux host after you SSHed
$ scp username#remotehost.com:file.jsp /path/to/tomcat/dir
scp filename.jsp username#servername:/location-of-tomcat-servlet-root

Resources