Sftp : not able to print the echo statements after the sftp transfer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sftp : not able to print the echo statements after the sftp transfer
# 1  
Old 03-27-2013
Sftp : not able to print the echo statements after the sftp transfer

I had the below sftp script working perfectly but the problem is I am not able to send the echo statements .

Code:
#!/bin/sh
echo "Starting to sftp..."
sftp admin@myip << END_SCRIPT
cd /remotepath/
lcd /localpath/
mget myfiles*.csv
bye
END_SCRIPT
echo "Sftp successfully."
echo
echo "program ended"
echo

Now the files has been successfully copied but the echo statments were not printed after the completion of sftp. i.e., "Sftp successfully" and "program ended" were not printed...

Could anyone please let me know what went wrong and how to print the echo statments at the end.

Thanks in advance..

Regards,
J
# 2  
Old 03-27-2013
Hmm, works here.

The second END_SCRIPT, which ends the here-document, must start at the beginning of the line, no leading blanks or tabs are allowed. But you should get a warning from the shell, if this is not the case.
This User Gave Thanks to hergp For This Post:
# 3  
Old 03-27-2013
Thanks sir...

I have verified and executed the script once again.. but no luck.. As you said.. second END_SCRIPT here statement started exactly at the beginning of the file and not sure that it executed for you..

Are there any other possibilities ??

Regards,
J
# 4  
Old 03-27-2013
Since it works here, there must be something in the real script, which is not present in your example.

Try to replace "END_SCRIPT" with something different, shorter, like "EOF" for example (maybe there is a typo there). Try to execute sftp step by step manually and see, if something unusual happens, which your script does not take into account. It's a try-and-error approach, I'm afraid.
This User Gave Thanks to hergp For This Post:
# 5  
Old 03-27-2013
I'm not sure this is right. << END_SCRIPT
Try <<END_SCRIPT
# 6  
Old 03-27-2013
Well, SFTP is a very different client to FTP. I don't think that SFTP will accept in-stream commands (well, that's what MVS used to call them) You will need to use the batch mode of SFTP.

my-stuff.sftpb
Code:
cd /remotepath/
lcd /localpath/
mget myfiles*.csv
bye

Script
Code:
#!/bin/sh
echo "Starting to sftp..."
sftp -b my-stuff.sftpb admin@myip
if [ $? -eq 0] 
then
   print "Sftp successfully.\n\nprogram ended\n"
else
   print "Sftp error.\n\nprogram abended\n"
fi

Of course, this is wholly automated, so you cannot pause for passphrase entry or anything. The server fingerprint must already be in known_hosts, but you've probably tried a manual SFTP or SSH which will establish that for you anyway.



I hope that this helps.

Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 7  
Old 03-27-2013
Quote:
Originally Posted by rbatte1
Well, SFTP is a very different client to FTP. I don't think that SFTP will accept in-stream commands (well, that's what MVS used to call them) You will need to use the batch mode of SFTP.
I've found most sftp clients are able to accept here-documents.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execute a script after SFTP transfer

Hi All, I am having an issue with the script execution. I am having a SFTP process that send files to a location . I want to execute a script once it transfer the file to that location. Right now I am leveraging autosys file watcher to do that. Is there any way like MFT PPA that can execute... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

2. UNIX for Dummies Questions & Answers

Sftp transfer doing as single row

Hi All, I have a file in windows when I transfer it using sftp it is getting as single line. I tried to do both ascii and binary File: is transfered as Can you please let me know how can do the transfer as same as XML file Thanks, Arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

3. UNIX for Dummies Questions & Answers

SFTP File transfer issue

Hi guys, Need a quick and urgent help on below issue. One of our application is try to transfer the file to another host thru sftp process My file is about 1 GB. Job is getting hung while transferring the file. So when I login as sftp and check the file system space is only in MB... (2 Replies)
Discussion started by: Vinoth Kumar G
2 Replies

4. Shell Programming and Scripting

File transfer using SFTP

Hi, I want to a transfer file from remote machine to a local machine using SFTP where both my local and remote machines are Ubuntu machines.So i wanted to write a unix bash script which uses SFTP command to transfer the file from remote to local machine. My remote server is 178.28.30.106. ... (14 Replies)
Discussion started by: shree11
14 Replies

5. Shell Programming and Scripting

Passwordless file transfer using sftp

Hello all, I have a requirement, in which we need to stage a package to Unix remote server in an automation (we cant use ssh key generation) , do u have any idea how we can transfer the package to remote server using sftp .if you have any script plz share it to me (4 Replies)
Discussion started by: Ramji Sundaram
4 Replies

6. UNIX for Dummies Questions & Answers

SFTP transfer does not complete

I am able to connect to a site and start a file transfer via SFTP, but when the file reaches "100%" -- the file does not complete and "stop". The 100% transfer status does not change (obviously), but the timer for SFTP keeps going and will not complete. This also happens when I try to get a file.... (2 Replies)
Discussion started by: loganban
2 Replies

7. Shell Programming and Scripting

SFTP with ASCII file transfer

Hello - I have text file and need to load the data in Oracle through sqlloader. I need to move this file to unix server and load into oracle. When i SFTP(unfortunately i do not have FTP) to unix box, each line is appended with ControlM character... since it is transferring in BINARY... (4 Replies)
Discussion started by: govindts
4 Replies

8. Shell Programming and Scripting

sftp file transfer

hi i am trying to login to remote server using SFTP Protocol and trying to upload a file butit is asking for the password. Note: I am trying to connect to FrontEnd server sftp SFTREGUP1@14.71.26.6 Connecting to 14.71.26.6... Password Authentication Password: Please help (14 Replies)
Discussion started by: Satyak
14 Replies

9. UNIX for Advanced & Expert Users

sftp command for file transfer

hi, I need to sftp a file from one unix system to another unix system. eg: filename is test.txt servername : abc@xyz please give me the sftp command for that. thanks in advance.. mohan.p (2 Replies)
Discussion started by: mohanpadamata
2 Replies

10. Shell Programming and Scripting

SFTP Transfer Across Multiple Servers

Hello everyone, Have a question which I'm not entirely sure about, but will ask anyway. We have three servers (A/B/C), 'A' being the local host, 'B' being a SFTP server on the DMZ, and 'C' being the intended remote host. The task is to transfer file/s from server 'A' to server 'C' via server... (0 Replies)
Discussion started by: Cameron
0 Replies
Login or Register to Ask a Question