Shell : sftp autologin not working ...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell : sftp autologin not working ...
# 1  
Old 03-27-2013
Shell : sftp autologin not working ...

Hi folks,

for sftp autologin, while browing in unix.com forums.. I got the below code. I tried to execute that code but no luck.

Code:
#!/bin/sh
HOST=yourservername
USER=yourusername
PASS=yourpassword
echo "sftping file ..."
lftp -u ${USER},${PASS} sftp://${HOST} <<EOF
cd /tmp
get tmpfile
bye
EOF
echo "done"

the error message is as follows

Code:
ubuntu1[johng]/mypath>sh sftp_new.sh
sftping file ...
sftp_new.sh: line 8: lftp: command not found

Could anyone please help me what went wrong....
# 2  
Old 03-27-2013
Quote:
Originally Posted by scriptscript
Code:
sftp_new.sh: line 8: lftp: command not found

You don't have lftp installed.
This User Gave Thanks to hergp For This Post:
# 3  
Old 03-27-2013
shell : error while sftp'ng the lastest file

Now I have installed the lftp and it is running fine.

If I sftp only one single file it is working fine...

But I am trying to ftp only the latest file from the remote machine to local machine with the below code.

Code:
#!/bin/sh  
HOST=myhost
USER=myuser
PASS=mypass

echo "sftping file ..."  

lftp -u ${USER},${PASS} sftp://${HOST} <<EOF 
cd /mypath/
SOURCE_FILE=$(ls -ltr file*.txt |tail -l)
get "$SOURCE_FILE"
bye 
EOF  
echo "done"

it is showing the below error message
Code:
sftp_.sh: line 13: warning: here-document at line 7 delimited by end-of-file (wanted `EOF')
ls: cannot access file*.txt: No such file or directory
Unknown command `SOURCE_FILE='.
get: Access failed: Failure

I made sure that files exist in the directory but still it is the showing "No such file or dierctory" error..

Could anyone please help me on this ?

---------- Post updated at 05:34 AM ---------- Previous update was at 04:45 AM ----------

The below code is sending all the files but I need to send only the latest file only.

Could anyone please help me?

Code:
#!/bin/sh
HOST=myhost
USER=myuser
PASS=mypass
echo "sftping file ..."

lftp -u ${USER},${PASS} sftp://${HOST} <<EOF
cd /mypath/
mget  carlog*.txt
bye
EOF
echo "done"

Actually in the directory.. there are 3 files with names
carlog_2013_03_19.txt
carlog_2013_03_21.txt
carlog_2013_03_24.txt

So from the above.. I need to get only the latest one.. i.e., carlog_2013_03_24.txt

Regards,
J
# 4  
Old 03-27-2013
The ls command is run on the local machine, not the remote machine.

You could find the name of the most recent file in a first call to lftp. You can write the output into a temporary file, grep the filename out and then call lftp a second time to actually transfer the file.
This User Gave Thanks to hergp For This Post:
# 5  
Old 03-27-2013
@above.. thanks Sir..

But it doubles the work... if not wrong...I had the below ftp code and expected the same can be done to the sftp also.. In case you are right.. but Is there any other way(jst like below ftp code)

Code:
cd /mypath/
SOURCE_FILE=$(ls -rt myfile*.DAT |tail -l)
ftp -i -n -v <<-!
open myipaddress
user "IUSER\netrep1" 1132115c
lcd /localpath/
cd /remotePath/
put "$SOURCE_FILE"
close
quit
!
echo 'The file has been successfully FTPed to the server'

Thanks in advance....
# 6  
Old 03-27-2013
The here document is completely prepared, before "lftp" is started. So it cannot react on lftp's output.

Another hint would be to try "expect". It is a tool to interact with programs and react on their outputs, often used to control telnet/ssh/ftp/...-sessions.
This User Gave Thanks to hergp For This Post:
# 7  
Old 03-27-2013
thanks Sir...

Just now I had installed expect rpm package in my machine..

Could you please help with sample sftp code with expect which pulls only the lastest file from the remote server.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Sftp command not working

What is wrong with this sftp command being used in one line: sftp /Data/SEmisstn.gz lsmsadit@144.226.213.23:/test/lsms.SEmisstn.gz The ssh key is already setup. The node is valid and i can ssh to it as well as do a manual step by step sftp to the server. However, for some odd reason, i... (10 Replies)
Discussion started by: mrn6430
10 Replies

2. Shell Programming and Scripting

Sftp commands not working in shell script

hi, i am having 2 linux boxes as source and 1 linux box as destination.i want to create a shell script containing code to transfer a csv file from either of the 2 linux boxes (file will be present in just one box, i need to check both the boxes to see which box has the csv file) to 3rd linux box... (1 Reply)
Discussion started by: linuxlearn2013
1 Replies

3. Shell Programming and Scripting

sftp autologin is working but ...

Dears, I am new to linux scripting and I was look for a way to auto login to a server using sftp to download a file. I found one and it is working fine. But i don't know the meaning of <<EOF in the code. Any one explain it to me: #!/bin/sh HOST=yourservername USER=yourusername ... (1 Reply)
Discussion started by: torabi
1 Replies

4. Solaris

Why is sftp working but ftp not

I am not very familiar with the use of FTP, and trying to run it I found out that standard "ftp" is not working" but "sftp" is. If sftp is allowed will that block ftp ? and if so where is this set ? I thought there is no relationship, is that right ? If so look here: inetadm | grep ftp enabled... (11 Replies)
Discussion started by: manni2
11 Replies

5. Web Development

Autologin Shell

Hello friends, I'm working on portal for Auto login servers without asking for credentials. Credentials are stored in database/file. Script fetches credentials from db/file and autologin the server. I have installed AjaxTerm for it but don't know exactly how to login remote servers using it. ... (0 Replies)
Discussion started by: nrbhole
0 Replies

6. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

7. Shell Programming and Scripting

Automate SFTP is not working

Hi All:cool:, i tried to automate SFTP process after passwordless authendication. Stil i am getting error... Can anyone help.... ------------------- sample code below ------------------- sftp -v $mdskk@100.4.4.75 << EOF cd /data mget *.tar.gz bye EOF... (2 Replies)
Discussion started by: senthil_seera
2 Replies

8. UNIX for Dummies Questions & Answers

sftp not working as cronjob

hi, I have a script that will automatically login into a server and get a file. it is working fine if i run it on a command line. however, when i tried to run it as a cron job, it is not working. what should i do? set timeout -1 spawn /usr/bin/sftp user1@server1 match_max 100000 expect... (3 Replies)
Discussion started by: tungaw2004
3 Replies

9. Shell Programming and Scripting

SFTP not working in cron

Hi, I have a simple script that is trying to put a file that resides on a local machine to a remote machine. It runs fine manually but does not complete when scheduling to run in cron. Here is what the script looks like. Any idea what I am doing wrong here? #!/bin/ksh cd /path sftp... (4 Replies)
Discussion started by: ewilson0265
4 Replies

10. UNIX for Dummies Questions & Answers

sftp/scp autologin

Ive have 2 unix machines i need to transfer files from one to the other. Im trying to use either sftp or scp as ftp is out of the question. Ive created the RSA key on one machine and copied it across but im still prompted for a password. Assume this is due to the fact that im not using the same ID... (8 Replies)
Discussion started by: devid
8 Replies
Login or Register to Ask a Question