Is it possible to do so:
I am on Windows system and telnet Unix/Linux remotely. Then I would like to download file from telnet mode and download to Windows system. Any Unix/Linux command are able to do so? like rcp or ftp. How to do so? Does it require any configuration on both system?
i try to write the shell script on Unix/linux side. and i telnet Unix/linux system remotely from local Windows machine and log in to Unix/linux system, run the script on Unix/linux side. some files will be transfered or download automatically to my windows system.
assume permission is not a problem
You can use x/y/zmodem to transfer file if both ends support that.
On Linux/Unix, you can use sz command to send file via zmodem.
On Windows, both Secure CRT (commercial) or Le Putty (open source) are capable of zmodem.
I think you want PSCP (command line) or WinSCP (GUI).
Usually people use ftp session to transfer files. If permissions is not a problem why don't you run ftp from your Windows computer?
You can create a windows batch script to load your file. Try something like
ftp hostname
user
password
cd /path/to/file
get myfile
quit
If you must do it through the existing connection, look at protocols such as ZMODEM and the rz and sz commands for them on Linux. You will need a terminal program on Windows that supports that protocol though.
For small files, I just uuencode (or gzip -c | uuencode name.gz) on the command line over the telnet session, then cut and paste to uudecode on my local windows computer (using cygwin).
You can use this:
telnet hostname 80 > filename_to_download_in
GET /path/to/file HTTP/1.0
Related
I have a remote file that I edit regularly. I would like to edit it with a quick, simple command that would work likely via SSH. At present, my workflow is to connect to the remote computer via SSH, open the file using an editor (say vim or nano), edit, save and then close the connection.
I am aware that I can mount the remote computer filesystem using SSHFS or Nautilus capabilities, but I'm really looking for a single command to run in the terminal which shall open the file in an editor, allow me to save and then exit, closing all connections to the remote computer.
Currently, I am trying to do this by passing a command to the remote computer via SSH, but I am running into difficulties. For VIM, the command is something like the following:
ssh user1#computer1 "vim /path/laboratory_notebook_1.md"
Using this procedure, VIM does not run correctly and presents the following error:
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
For nano, the command is something like the following:
ssh user1#computer1 "nano /path/laboratory_notebook_1.md"
Using this procedure, nano does not run and the following error is presented:
Error opening terminal: unknown.
I'm not sure how to proceed on this line of thought. I would appreciate assistance on this method and suggestions on other ways to edit remote files briskly with a minimum amount of interaction.
Force Pseudo-TTY Allocation
You can force pseudo-tty allocation with one or more -t flags. The SSH(1) man page says:
-t Force pseudo-tty allocation. This can be used to execute arbi-
trary screen-based programs on a remote machine, which can be
very useful, e.g. when implementing menu services. Multiple -t
options force tty allocation, even if ssh has no local tty.
Example
Using your own example, slightly modified, the following would work if you have a local TTY or PTY:
ssh -t user1#computer1 'vim /path/laboratory_notebook_1.md'
It works fine for me with OpenSSH_6.2p2. Your mileage (and operating environment) may vary.
If you are using vim. Vim comes with a plugin called netrw which will allow you to do this.
vim scp://hostname/path/to/file
Will copy the file to you local machine and on save reupload it.
Take a look at netrw's documentation :h netrw
I am struggling with a problem. I have:
ServerA (is closer to me and much faster)
ServerB (is my website where I want the final file to stay)
so what I want to do with the shell script (either Windows batch or linux, I have cygwin installed) is, passing the filename as parameter:
1) upload with FTP a file to ServerA
2) login with ssh on serverB and wget the file from serverA
I managed to do 1 with a shell script, but I don't understand how to do step2 in the shell?
Thanks
I would recommend using scp to accomplish step 2. You can use the syntax:
scp path/to/file serverb#hostname:/path/to/destination.
You can read more about the syntax for scp here: http://www.hypexr.org/linux_scp_help.php
You could use TeraTerm which has a powerful scripting language to automate both tasks.
I have a remote file that I edit regularly. I would like to edit it with a quick, simple command that would work likely via SSH. At present, my workflow is to connect to the remote computer via SSH, open the file using an editor (say vim or nano), edit, save and then close the connection.
I am aware that I can mount the remote computer filesystem using SSHFS or Nautilus capabilities, but I'm really looking for a single command to run in the terminal which shall open the file in an editor, allow me to save and then exit, closing all connections to the remote computer.
Currently, I am trying to do this by passing a command to the remote computer via SSH, but I am running into difficulties. For VIM, the command is something like the following:
ssh user1#computer1 "vim /path/laboratory_notebook_1.md"
Using this procedure, VIM does not run correctly and presents the following error:
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
For nano, the command is something like the following:
ssh user1#computer1 "nano /path/laboratory_notebook_1.md"
Using this procedure, nano does not run and the following error is presented:
Error opening terminal: unknown.
I'm not sure how to proceed on this line of thought. I would appreciate assistance on this method and suggestions on other ways to edit remote files briskly with a minimum amount of interaction.
Force Pseudo-TTY Allocation
You can force pseudo-tty allocation with one or more -t flags. The SSH(1) man page says:
-t Force pseudo-tty allocation. This can be used to execute arbi-
trary screen-based programs on a remote machine, which can be
very useful, e.g. when implementing menu services. Multiple -t
options force tty allocation, even if ssh has no local tty.
Example
Using your own example, slightly modified, the following would work if you have a local TTY or PTY:
ssh -t user1#computer1 'vim /path/laboratory_notebook_1.md'
It works fine for me with OpenSSH_6.2p2. Your mileage (and operating environment) may vary.
If you are using vim. Vim comes with a plugin called netrw which will allow you to do this.
vim scp://hostname/path/to/file
Will copy the file to you local machine and on save reupload it.
Take a look at netrw's documentation :h netrw
Although I have never tried this, it is apparently possible to remotely edit a file in vim as described here. In my particular case the server I need access to can only be accessed from on campus, hence I have to log into my university account like so:
ssh user#login.university.com
then from there log into the secure server like so:
ssh user#secure.university.com
I have keyless ssh set up, so I can automate the process like so:
ssh user#login.university.com -t "ssh user#secure.university.com"
is there anyway to remotely edit a file such as secure.university.com/user/foo.txt on my local machine?
EDIT:
My intention is to use vim on my local machine as it is impractical (move .vim folder, copy .vimrc) and in some cases impossible (recompile vim with certain settings, patch vim source, install language beautifiers) to make vim on the remote machine behave the way I want it to behave. What I want is to issue something like this (this is not accurate scp, I know)
vim scp://user#login.university.com scp://user#secure.university.com//home/user/foo.txt
OK after a little working around I figured it out. First you have to edit (or create) your .ssh/config file as described here. For our purposes, we will add a line like this, which essentially adds a proxy.
Host secure
User Julius
HostName secure.university.com
ProxyCommand ssh Tiberius#login.university.com nc %h %p 2> /dev/null
Then we can simply copy (via scp) the file secure.university.com:/home/Julius/fee/fie/fo/fum.txt to the local computer like so
scp secure:/home/Julius/fee/fie/fo/fum.txt fum.txt
Extending on this, we can load it into vim remotely like so:
vim scp://secure//home/Julius/fee/fie/fo/fum.txt
or using badd like so:
:badd scp://secure//home/Julius/fee/fie/fo/fum.txt
To simplify my life, I added this shortcut to my .vimrc file for the most commonly used subfolder:
nnoremap <leader>scp :badd scp://secure//home/Julius/fee/fie/fo/fum.txt
So far vim has proven to be pretty aware that this is a remote file, so if the C file includes a file like so:
#include "foo.h"
it won't complain that "foo.h" is missing
Once you SSHed in the machine you can run any command(also vim) in remote host on your shell. After logging run vim as you are running in your machine.
Since you are using ssh, you basically have access to the server via the CLI, as if you were sitting in front of the machine itself. With that said, you can use any program on that machine, just like you would use it on your own machine. Assuming that the secure.university.com/user/foo.txt means that there is a text file called foo.txt at location /user on the secure server, then the following commands would work after logging in through ssh:
cd /user
vim foo.txt
You could also use nano or any other CLI based editor that is installed on the machine.
on windows exist command:
start myfile.mp3
start myfile.txt
on mac:
open myfile.mp3
open myfile.txt
Are there analogue command under Ubuntu?
xdg-open if you have a freedesktop.org-compatible environment.
There are several commands in Linux that help you open application associated files. If you know the application to open the file, then this may work . I am not sure if you are looking for this
env DISPLAY=:0.0 firefox "google.com"
opens Firefox with google.com opened in it. You can replace the application name and file name and use this command.
Try "gnome-open", for Gnome powered distros.
gnome-open random-file.torrent will open my torrent app.