Get filelist.txt from a sftp remote server | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Get filelist.txt from a sftp remote server

UNIX for Dummies Questions & Answers


Tags
listfile, ls, sftp, unix

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-17-2013
warmboy610 warmboy610 is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 31 July 2013, 10:45 PM EDT
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
Tools Get filelist.txt from a sftp remote server

Hi everyone, so I have a script create a login file to log into the sftp remote server, go to a certain directory and get the list of files in that direction into a text file in another folder (local folder). Here is the piece of code

Code:
echo "#!/usr/local/bin/expect -f"                           >> $loginFile
echo "spawn sftp [username]@[server name]"                   >> $loginFile
echo "expect ""password:"""                                           >> $loginFile
echo "send ""[my password]\n"";"                                    >> $loginFile
echo "expect ""sftp> """                                                 >> $loginFile
echo "cd pe_ase/data/vax"                                            >> $loginFile
echo "expect ""sftp> """                                                 >> $loginFile
echo "ls -l $listfile"                                                         >> $loginFile
echo "expect ""sftp> """                                                 >> $loginFile
echo "send ""quit\n"";"                                                   >> $loginFile
chmod 774 $loginFile
$loginFile

But the part:

Code:
echo "ls -l $listfile"                                            >> $loginFile

does seems to work, it gives out:

Code:
Couldn't stat remote file: Failure

if I change the code into:

Code:
echo "ls -l > $listfile"                                         >> $loginFile

Do any know the code to do this, thanks
then it gives out:

Code:
Couldn't stat remote file: No such file or directory

Sponsored Links
    #2  
Old 07-17-2013
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 9 April 2014, 1:31 AM EDT
Location: INDIA, Bangalore
Posts: 2,049
Thanks: 16
Thanked 107 Times in 103 Posts
as far as i know
Quote:
Couldn't stat remote file: Failure
mean file not found error. it wont return the return code like scp
Sponsored Links
    #3  
Old 07-17-2013
warmboy610 warmboy610 is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 31 July 2013, 10:45 PM EDT
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts

Code:
as far as i know 
Quote:
Couldn't stat remote file: Failure
mean file not found error. it wont return the return code like scp

But when I check the listFile, it is empty, which means that it does not work (I am sure that there are files inside that directory)
    #4  
Old 07-17-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 April 2014, 6:29 PM EDT
Location: Saskatchewan
Posts: 18,531
Thanks: 681
Thanked 3,036 Times in 2,856 Posts
File not found quite probably means file not found and is unlikely to mean anything else. Perhaps you're not quite where you meant to be, try doing an 'ls' and seeing what output you get, what files actually are there. Perhaps there's a minor spelling or capitalization issue.

Also, if you set up ssh keys properly instead of brute-forcing the password with expect, your life will be much easier, since sftp will simply do as its told without fanfare and no expect-script (and no insecurely-stored plaintext password!) required.
Sponsored Links
    #5  
Old 07-17-2013
warmboy610 warmboy610 is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 31 July 2013, 10:45 PM EDT
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
I tried to do it manually from the sftp server, the normal "ls" would gives out a long list of file, but the:


Code:
ls -l[listfile path]

or

Code:
ls -l >>[listfile path]

the errrors are the same as the above mentioned
Sponsored Links
    #6  
Old 07-18-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 April 2014, 6:29 PM EDT
Location: Saskatchewan
Posts: 18,531
Thanks: 681
Thanked 3,036 Times in 2,856 Posts
Could you post this long list of file?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SFTP - Get size of file on remote server forums123456 Shell Programming and Scripting 2 03-20-2012 09:51 AM
Help on cat filelist.txt |xargs -n1 find dragonpoint UNIX for Dummies Questions & Answers 2 10-08-2010 04:53 PM
SFTP from one remote server to another remote server from desktop akash.mahakode Programming 1 09-30-2010 03:47 PM
SFTP setting with a remote server - need help panknil Shell Programming and Scripting 1 11-10-2009 03:03 PM
Read from fileList.txt, copy files from directory tree fxvisions Shell Programming and Scripting 1 10-30-2007 05:17 PM



All times are GMT -4. The time now is 11:49 AM.