Need to List files using shell script

Need to list files from remote server using sftp. How can I list the files.

Error:Can’t ls filename not found : is the statement listed.

Please help me to figure it out how to list files from the remote folder location using sftp.
Will folder have restriction to list only particular files from folder…?

When you login in to any computer you have the permissions of the user. So depending on the situation yes it could restrict.

If you have permissions your command could be straight forward. I prefer SSH as it is secure and you can pass the key ( see man page ) prior so an automated script could grab without storing the password in plain text.

#! /bin/bash
    echo $(DATE) > Stored-Data 
    echo '-------- File Listing ---------------------------' >> Stored Data
    ssh kevin@ 'ls -l' > > Stored-Data.txt 
1 Like

Hi Tux,

I was using SFTP instead of ssh. I am not sure what exactly difference between SFTP & SSH. I need to investigate on this. why it didn’t work with SFTP & why it is working with SSH. Can you let me know the exact difference, what make exactly work…

For some of the remote servers, I am able to list and for few of them I am getting fallowing error:
Pseudo-terminal will not be allocated because stdin is not a terminal

Thanks for sharing the details…

satish has given u sample for SSH
i think u can do the same for SMTP

smtp user/pass@server <file.text