LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-04-2012, 10:55 PM   #1
priyanka mungekar
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Rep: Reputation: Disabled
sftp issue


Hello,

I am using sftp for the first time. I want the output of the command ls -lrt on my local directory from the remote directory?

is that possible? if yes could you please explain with an example?

Thanks,
Priyanka
 
Old 10-04-2012, 11:31 PM   #2
nugat
Member
 
Registered: Sep 2012
Posts: 122

Rep: Reputation: 31
Quote:
Originally Posted by priyanka mungekar View Post
Hello,

I am using sftp for the first time. I want the output of the command ls -lrt on my local directory from the remote directory?

is that possible? if yes could you please explain with an example?

Thanks,
Priyanka
Code:
lls
in an sftp session, you can type "help" to get a list of acceptable commands.
 
Old 10-04-2012, 11:39 PM   #3
priyanka mungekar
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
lls would list the list of files/scripts we have in the local directory. What i want to achieve is how do I get the list of files along with their file size (the files which are on remote server)to my local directory?

For that I need to store the output of ls -lrt that I execute when I am in the sftp mode to a file say, but unable to do so.

Can you help?
 
Old 10-04-2012, 11:55 PM   #4
nugat
Member
 
Registered: Sep 2012
Posts: 122

Rep: Reputation: 31
oh, i see. use ssh for that, e.g.:


Code:
ssh user@remotehost ls -l /dir
you'll be prompted for your password, but then the listing will be sent to STDOUT (your screen). you could also save the output to a variable, or redirect it to a local file.


Code:
listing=$(ssh user@remotehost "ls -l /dir")
Code:
ssh user@remotehost "ls -l /dir" > files.txt
you should set up public/private SSH keys, so that you can SSH around w/o having to enter passwords.

Last edited by nugat; 10-04-2012 at 11:56 PM. Reason: code typos
 
Old 10-05-2012, 01:09 AM   #5
priyanka mungekar
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
tried as suggested, throws the below error

Could not chdir to home directory : A file or directory in the path name does not exist

 
Old 10-05-2012, 01:16 AM   #6
priyanka mungekar
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
what do you exactly mean by should setup public/private ssh keys ? Is there some kind of configuration file or package thats need to be installed on the unix box ?
 
Old 10-05-2012, 02:52 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can do something similar in sftp (in case you haven't got ssh access, but sftp-only). Interactively (when you sit in front of the terminal)
Code:
sftp user@host | tee logfile
or in batch mode in a script
Code:
#!/bin/bash
#
sftp -b- user@host > logfile << EOF
ls -lrt
bye
EOF
In both cases, you may want to remove the sftp> prompt from the session logfile:
Code:
sed -i '/^sftp> /d' logfile
Regarding "Public key authentication" - useful for example in batch mode when you' don't want to be prompted for password - read the AUTHENTICATION section of the ssh man page. Setting it up doesn't require any additional software installation: basically it uses ssh-keygen and ssh-agent. Plenty of tutorials out there! Hope this helps.
 
Old 10-05-2012, 06:12 AM   #8
priyanka mungekar
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
thanks it was helpful!!
 
Old 10-05-2012, 08:47 PM   #9
nugat
Member
 
Registered: Sep 2012
Posts: 122

Rep: Reputation: 31
Quote:
Originally Posted by priyanka mungekar View Post
what do you exactly mean by should setup public/private ssh keys ? Is there some kind of configuration file or package thats need to be installed on the unix box ?
You can create a public and private SSH key pair (which amounts to a couple of text files in your home dir), that you would use as authentication for SSH. You can do this using couple of commands that are part of the OpenSSH package (and are thus likely already on your Linux box).

First create the key pair on host A:
Code:
[user@host-A ~]$ ssh-keygen -t dsa -f ~/.ssh/id_dsa -P ''
if you now look in your ~/.ssh directory, you should see at least these files:
Code:
id_dsa
id_dsa.pub
Create a key pair on host B (the exact same command as above):
Code:
[user@host-B ~]$ ssh-keygen -t dsa -f ~/.ssh/id_dsa -P ''
Back on host A, then copy the public key over to host B:
Code:
[user@host-A ~]$ ssh-copy-id -i ~/.ssh/id_dsa.pub user@host-B
you will be prompted for user's password on "host-B" so that the key can be copied.

Then test logging into host B from host A without getting prompted for a password:
Code:
[user@host-A ~]$ ssh -oPasswordAuthentication=no user@host-B hostname
if it works correctly, you should not get prompted for a password (obviously) and the hostname command should be executed remotely (printing "host-B" or whatever the remote host's hostname is) , on host-B and then return you to the host-A prompt.

if you have problems logging in w/o password, double-check the permissions on the ~/.ssh dir and the key files. They should be owned by you and the .ssh dir and the private key should only be readable by the owner:
Code:
[user@host-A ~]$ ls -ld .ssh .ssh/id_dsa*
drwx------ 2 user users 4096 Jun  7 12:11 .ssh
-rw------- 1 user users  668 Aug 23  2011 .ssh/id_dsa
-rw-r--r-- 1 user users  618 Aug 23  2011 .ssh/id_dsa.pub
Note that you can leave off the -oPasswordAuthentication=no option to ssh normally, we're just try to force it to skip that auth mech, if your ssh is configured to use passwords first.
 
Old 10-08-2012, 04:53 AM   #10
priyanka mungekar
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
change mode to binary in sftp

Hi,

How to change mode to binary while transferring files using sftp ?

Thanks,
Priyanka
 
Old 10-08-2012, 05:14 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by priyanka mungekar View Post
How to change mode to binary while transferring files using sftp ?
The SSH/SFTP protocol is different from FTP and you don't need to change the transfer mode from ASCII to BINARY and viceversa. The files are transferred without modifications and this behaviour matches the binary mode transfer. The sftp coming from openssh-client, the default in Linux, acts like this.

Nevertheless, some proprietary ssh/sftp packages added the "ascii" command but only to manage the newline characters conversion automatically, if they are treated differently in the local and the remote machine. Instead, in Linux you transfer the files unmodified and eventually change the newline characters using the dos2unix command after the files have been transferred and stored onto your local machine.
 
Old 10-08-2012, 07:36 AM   #12
nugat
Member
 
Registered: Sep 2012
Posts: 122

Rep: Reputation: 31
Quote:
Originally Posted by priyanka mungekar View Post
How to change mode to binary while transferring files using sftp ?
Is there something that makes you think that SFTP is not transferring in binary mode? Or are you just asking this out of habit, as colucix has pointed out?
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sftp issue - logs attached td3201 Linux - Server 5 01-05-2012 07:28 PM
sftp issue pgte3 Linux - Newbie 3 11-24-2010 09:07 AM
[SOLVED] sftp issue c0pe Red Hat 3 07-12-2010 09:02 AM
Sftp log issue on RHEL 4 ZAMO Linux - Enterprise 3 03-10-2010 11:32 AM
sftp issue on rhel 5.4 protos78 Red Hat 12 01-12-2010 02:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:12 PM.

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