LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-21-2011, 04:16 AM   #1
Abscissa256
Member
 
Registered: Aug 2011
Posts: 79

Rep: Reputation: Disabled
ssh/sftp/scp: Use remote system without always switching tools/connections?


First of all: I know my way around the command line, at least enough to get by, but I'm far from being any sort of unix expert. I'm a programmer (mostly C-derived languages), and I can do basic shell scripts, but I'm no script-fu wiz.

I have basic familiarity with using ssh (for a secure remote shell), sftp and scp. But I've noticed I typically need to switch between them a lot for various tasks (which also means lots of opening/closing ssh connections to the same remote machine). From what I can tell, this seems to be due to limitations in each of them.

Maybe I'm wrong, but as I understand things:

ssh shell:
Can do: Pretty much anything you can do at a normal shell.
Can do: Multiple commands in one session/connection.
Cannot do: File transfers.
Cannot do: "batch" mode (like sftp) that'll bail out at the first error.

sftp:
Can do: Multiple commands in one session/connection.
Can do: Transfer files.
Can do: Delete files and empty dirs.
Can do: Explore/query the remote filesystem.
Can do: Batch mode (-b) that'll bail out at the first error.
Cannot do: Transfer/delete entire non-empty directory trees.

scp:
Can do: Transfer entire non-empty directory trees.
Cannot do: Multiple commands in one session/connection.
Cannot do: Delete things.
Cannot do: Move/rename things.

So, for example, suppose I want to do all the following, and automate it in a script:

1. Upload a bunch of misc standalone files to various places (ie, wildcards won't help).
2. Delete the tree 'foo'.
3. Upload a new 'foo' tree.
4. Do some logic, both remote and local.
5. Some other step that completely depends on the results of #4

As far as I'm aware:
#1 needs to use sftp (could use scp, but that would be wasteful - a new connection for every file?).
#2 needs to be ssh (could use sftp in theory, but that's be a royal PITA).
#3 needs to be scp (again, sftp would be theoretically possible, but a royal pain).
#4 can only be ssh.
#5 could end up needing to be anything.

So, AFAIK, I can't just simply pass a block of script in batch mode to ssh or sftp. That simple set of tasks involves switching between all those separate programs, and with each making a separate new connection.

Now, I can certainly do all that. But it seems to me I must be missing something.

Is there some better way to do all of this? To do it all in one connection? Or not have to keep switching between the different tools?
 
Old 09-21-2011, 04:25 AM   #2
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
Lightbulb



I believe you are spot on but this may help somewhat.


http://www.linuxjournal.com/article/8904


sshfs could make some of those tasks around file management easier.
 
Old 09-27-2011, 06:05 PM   #3
Abscissa256
Member
 
Registered: Aug 2011
Posts: 79

Original Poster
Rep: Reputation: Disabled
Wow, that sshfs is absolutely freaking AWESOME! I just tried it and it seems to be working fine. Thanks!
 
Old 09-28-2011, 04:12 AM   #4
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
No problem. Enjoy
 
Old 09-28-2011, 06:13 PM   #5
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
You can open multiple xterms. So you could have one xterm which you use to ssh in and whatever you do there. Then you can have another xterm which you use for scp for example. There's no need to limit yourself to one xterm.
 
Old 09-28-2011, 09:49 PM   #6
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 91
Quote:
Originally Posted by Abscissa256 View Post
Wow, that sshfs is absolutely freaking AWESOME! I just tried it and it seems to be working fine. Thanks!
I tried it today. Had never heard of sshfs. It's the ticket, boys. I'll be using it a lot from now on. Thanks very much jv2112 for enlightening us.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Chroot SSH problem: ssh working, not SFTP & SCP. NaCo Linux - Security 3 02-01-2009 02:23 AM
allow ssh, scp and sftp? javier_ccs Linux - Newbie 6 09-12-2006 08:11 AM
SFTP with Chrooting and without SSH and SCP toraghun Linux - Security 1 07-10-2006 05:11 AM
SSH - where are scp and sftp satimis Linux - Networking 2 11-15-2003 10:27 AM
ssh working, but not sftp scp hardigunawan Linux - Networking 2 05-02-2003 02:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration