SCP command works, but I cannot find downloaded file - linux

I used Putty to remote into my Raspberry Pi. I am trying to scp a file from another computer. The scp command works, and it shows that file is downloaded, however, I cannot find anything on my raspberry pi.
Anyone can help me solve this?
Thanks!
Here is the screenshot

You have downloaded that file to /Documents rather than ~/Documents. Change your scp command to:
scp pi#155.198.134.5:test.txt ~/Documents
and you will be able to find it in your documents directory. Alternatively move the already downloaded file to your home directory with:
mv /Documents ~/Documents/test.txt

Related

Location of .bashrc for "Bash on Ubuntu on Windows" in Windows 10

Microsoft just introduced a Linux subsystem in its Windows 10 Anniversary Edition. The installation is pretty straight forward, but I could not locate bash files on Windows.
How does it work? What does ~ refer to in Windows? Where to find .bashrc?
Since the Windows 10 Fall Creators Update, the location changed to:
C:\Users\USERNAME\AppData\Local\Packages\{DIST}\LocalState\rootfs\home\{LINUXUSER}\
Where:
{DIST} is equal to CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
{LINUXUSER} is the user for which you are looking for the .bashrc file
Just for anyone wondering that came here from Google.
Sorry for the misunderstanding, I check on google and it will be at C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME .
I tried and it works, in the cmd just type cd\ && dir *bashrc* /s it will locate the file, and in my case i see the line C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME but when I want to navigate it with the window browser it doesn't work, but if you copy paste it, it works :-)
I found it here.
Considering that you need to know where a file is located you can use the find command.
The syntax of the command is find {search-path} {file-names-to-search} {action-to-take}by default the action to take is printing the file name.
So if you are finding .bashrc file you can use find / -name .bashrc the bash will return you /home/yourusername/.bashrc
Also, if you want to access to your home directory you can use cd ~
Hope my answer will be helpful :-)
just type
vi ~/.bashrc
and that should put you into the file where ever it is.
You can navigate there simply by doing cd ~
List all files with ls -a and you should be able to see it.
~ means that is user home folder, way like /home/%username%/
you can list files like ls -al and see .bashrc file.
Right now on WSL 2 you can find it under /home/{user_name} and the file is hidden.
You can access it from Ubuntu console by {text_editor} .bashrc
If you want to edit that in Windows just type in ubuntu console explorer.exe . and it opens the current folder and shows all hidden files.
It's weird but works fine.
Other answers doesn't work for me using WSL 2.
The LocalState folder contains a virtual disk so rootfs does not exist,
and AppData\Local folder does not have the Lxss folder.
The solution for me is surprisingly simple:
wsl -u root
This will allow you to get into wsl as root.
From here, you have access to the whole linux.
Fix the .bashrc or anything you want.
Don't screw up the root user. :)
I find my .bashrc file in:
/home/your_user_name
you can run cd /home/your_user_name or cd ~ should work as well
If you previously installed git bash for window, you may also find .bashrc file in your window user profile folder. In Linux subsystem, you may local the file under /mnt/c/Users/your_window_user_name/.bashrc However, modifying that file only works for git bash in window but not for the shell terminal of the Linux subsystem.
Note: my installation of the Ubuntu is 20.04 LTS straight from window store.

SFTP - WinSCP: Zip a file/folder

I'm transferring a file to SFTP and then trying to zip it with WinSCP. It's not working.
After my put command, I'm using the following command.
zip -r "!?&SFTP Folder Path\MyFile.txt:?SFTP Folder Path\MyFile.zip!" !&
What am I doing wrong? What should I be doing? If I only want to zip a/any file with specific extension or folder, what changes do I make?
Update:
I'm getting the following log output after a file has been copied over to the sftp
...
batch continue Searching for host...
Connecting to host...
Authenticating...
Using username "admin". Authenticating with pre-entered password. Authenticated. Starting the session...
I'm using the following code after put cmd line.
option batch continue
call zip -r "/sftp folder/Myfile.zip" Myfile.csv
close
exit
Your syntax is a custom command. The custom commands is a GUI feature of WinSCP, it has nothing to do with the scripting.
In WinSCP scripting use the call command.
call zip -r /path/MyFile.zip file1.dat file2.dat ...
Though make sure you are allowed to execute shell commands on the server.

Sub directory not getting copied to remote server using Rsync Linux

I tried with copying directory and files to remote Linux machine using rsync and incrontab.
It's working fine copying files to remote server.
Incrontab
/data/AMOS_SHARE/CHV_BE/ IN_MODIFY,IN_CREATE,IN_DELETE,IN_CLOSE_WRITE,IN_MOVE /data/AMOS/jboss/chv_rsync.sh
Rsync
#!/bin/bash
chmod -R 775 /data/AMOS_SHARE/CHV_BE
rsync -avuzh /data/AMOS_SHARE/CHV_BE/ jboss#xx.xx.xx.xx:/data/AMOS_SHARE/CHV_BE/
I created some files in /data/AMOS_SHARE/CHV_BE/ folder. It worked fine as well as I created folder in that, it is also working fine. But whenever I creat files in a sub folder, it's not working.
Please help me out.
In incrond recursively monitoring is not implemented yet, so the events in sub-directories are not monitored. You can do it by adding a additional watchers to sub-dirs but I would recommended to use
another tool:
Watcher
Also you can try ionotifywait tool (example)
inotifywait /tmp/test_dir -m -r
and parse the output of this command.

Is this the correct syntax to scp a downloaded file into Ubuntu?

I downloaded the latest version of swig that I need to move to Ubuntu. I was hoping someone could help identify what part of my syntax is incorrect. I've tried a number of variations but I can't quite seem to get it write.
I've tried
scp swig-3.0.2 user_name#111.111.11.111: swig-3.0.2
swig-3.0.2 is a directory (not copied)
scp swig-3.0.2 drubio#192.168.56.101: /home/drubio/swig-3.0.2
No such file or directory
I've tried implementing directions that I've found on askubuntu.com reproduced here:
# copy a file from local machine to server1.com
user#local-machine# scp ./somefile.txt user1#server1.com:/home/user2
# copy a file from server1.com to server2.com
user#local-machine# ssh user1#server1.com
user1#server1# scp ./somefile.txt user2#server2.com:/home/user2
user#server1# logout
# copy a file from server2.com to server1.com
user#local-machine# ssh user2#server2.com
user2#server2# ls
somefile.txt otherfile.txt
user2#server2# scp ./otherfile.txt user1#server1.com:/home/user1
user2#server2# logout
# can't copy a file TO local-machine because it's not accessible from internet
All I'm trying to do is to copy the downloaded swig-3.03 located on my local machine's Desktop on to Ubuntu. I've checked on my local machine where I'm at and I've verified that I am in the Desktop directory. My username is correct and the path is right. I'm assuming that the mistake is the destination point. Am I wrong to assume this?
The correct syntax is:
scp swig-3.0.2 user_name#111.111.11.111:swig-3.0.2
scp swig-3.0.2 drubio#192.168.56.101:/home/drubio/swig-3.0.2
Without the spaces!
The usage is for copy local to remote:
scp /path/to/my_local_file user#host:/path/to/my_copy_file
or for copy remote to local:
scp user#host:/path/to/my_remote_file /path/to/my_copy_file

scp from Linux to Windows [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I am running a putty client on a Windows machine to connect successfully to a Linux box. Now I want to be able to copy a file from the Linux machine under the path /home/ubuntu/myfile to C:/Users/Anshul/Desktop on my local computer. The user at the Windows machine is anshul. I am giving the following command on putty but it is not working:
scp /home/ubuntu/myfile ip_address_of_windows_machine:C:/Users/Anshul/Desktop
I think the path for the Windows machine is wrong. Please help as I have banged my head on a large number of forums but none seem to give correct path for Windows server. Don't suggest alternate options like WinScp
This one worked for me.
scp /home/ubuntu/myfile username#IP_of_windows_machine:/C:/Users/Anshul/Desktop
Download pscp from Putty download page, then use it from Windows Command Line CMD as follows:
pscp username_linux_machine#ip_of_linux_machine:/home/ubuntu/myfile.ext C:\Users\Name\Downloads
Copying starts once you enter the password for the Linux machine.
Try this, it really works.
$ scp username#from_host_ip:/home/ubuntu/myfile /cygdrive/c/Users/Anshul/Desktop
And for copying all files
$ scp -r username#from_host_ip:/home/ubuntu/ *. * /cygdrive/c/Users/Anshul/Desktop
Access from Windows by Git Bash console (also works for CMD and PowerShell):
scp user#ip:/dir1/dir2/file "D:\dir1\dir2"
You could use something like the following
scp -r linux_username#linux_address:path/to/file path/to/local/directory
This will copy file to the specified local directory on the system you are currently working on.
The -r flag tells scp to recursively copy if the remote file is a directory.
Windows doesn't support SSH/SCP/SFTP natively. Are you running an SSH server application on that Windows server? If so, one of the configuration options is probably where the root is, and you would specify paths relative to that root. In any case, check the documentation for the SSH server application you are running in Windows.
Alternatively, use smbclient to push the file to a Windows share.
For all, who has installed GiT completly with "Git Bash": You can just write:
scp login#ip_addres:/location/to/folders/file.tar .
(with space and DOT at the end to copy to current location). Than just add certificate (y), write password and that's all.
Your code isn't working because c:/ or d:/ is totally wrong for linux just use /mnt/c or/mnt/c
From your local windows10-ubuntu bash use this command:
for download:
(from your remote server folder to d:/ubuntu) :
scp username#ipaddress:/folder/file.txt /mnt/d/ubuntu
Then type your remote server password if there is need.
for upload:
(from d:/ubuntu to remote server ) :
scp /mnt/d/ubuntu/file.txt username#ipaddress:/folder/file.txt
Then type your remote server password if there is need.
note: I tested and it worked.
I had to use pscp like above Hesham's post once I downloaded and installed putty. I did it to Windows from Linux on Windows so I entered the following:
c:\ssl>pscp username#linuxserver:keenan/ssl/* .
This will copy everything in the keenan/ssl folder to the local folder (.) you performed this command from (c:\ssl). The keenan/ssl will specify the home folder of the username user, for example the full path would be /home/username/keenan/ssl. You can specify a different folder using a forward slash (/), such as
c:\ssl>pscp username#linuxserver:/home/username/keenan/ssl/* .
So you can specify any folder at the root of Linux using :/.
To send a file from windows to linux system
scp path-to-file user#ipaddress:/path-to-destination
Example:
scp C:/Users/adarsh/Desktop/Document.txt root#127.0.0.1:/tmp
keep in mind that there need to use forward slash(/) inplace of backward slash(\) in for the file in windows path else it will show an error
C:UsersadarshDesktopDocument.txt: No such file or directory
.
After executing scp command you will ask for password of root user in linux machine.
There you GO...
To send a file from linux to windows system
scp -r user#ipaddress:/path-to-file path-to-destination
Example:
scp -r root#127.0.0.1:/tmp/Document.txt C:/Users/adarsh/Desktop/
and provide your linux password.
only one you have to add in this command is -r.
Thanks.
Here is the solution to copy files from Linux to Windows using SCP without password by ssh:
Install sshpass in Linux machine to skip password prompt
Script
sshpass -p 'xxxxxxx' scp /home/user1/*.* testuser#x.x.x.x:/d/test/
Details:
sshpass -p 'password' scp /source_path/*.* windowsusername#windowsMachine_ip:/destination_drive/subfolder/
As #Hesham Eraqi suggested, it worked for me in this way (transfering from Ubuntu to Windows (I tried to add a comment in that answer but because of reputation, I couldn't)):
pscp -v -r -P 53670 user#xxx.xxx.xxx.xxx:/data/genetic_map/sample/P2_283/* \\Desktop-mojbd3n\d\cc_01-1940_data\
where:
-v: show verbose messages.
-r: copy directories recursively.
-P: connect to specified port.
53670: the port number to connect the Ubuntu server.
\\Desktop-mojbd3n\d\genetic_map_data\: I needed to transfer to an external HDD, thus I had to give permissions of sharing to this device.
Open bash window. Preferably git bash.
write
scp username#remote_ip:/directory_of_file/filename 'windows_location_you_want_to_store_the_file'
Example:
Suppose your username is jewel
your IP is 176.35.96.32
your remote file location is /usr/local/forme
your filename is logs.zip
and you want to store in your windows PC's D drive forme folder
then the command will be
scp jewel#176.35.96.32:/usr/local/forme/logs.zip 'D:/forme'
**Keep the local file directory inside single quote.
I know this is old but I was struggling with the same. I haven't found a way to change directories, but if you just want to work with the C drive, scp defaults to C. To scp from Ubuntu to Windows, I ended up having to use (notice the double back-slashes):
scp /local/file/path user#111.11.11.111:Users\\Anshul\\Desktop
Hope this helps someone.
Try this:
scp /home/ubuntu/myfile C:\users\Anshul\Desktop
If you want to copy paste files from Unix to Windows and Windows to Unix just use filezilla with port 22.

Resources