Pls HELP: Redirecting input to SFTP connection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pls HELP: Redirecting input to SFTP connection
# 1  
Old 04-11-2016
Pls HELP: Redirecting input to SFTP connection

Hi,

Can somebody please let me know if we can redirect variable value to the sftp connection. I am trying to run the attached snippet but facing an error.

Code:
dev@UAT.com> export USER1=ftp
dev@UAT> export HOST1=XX.XX.XX.XX
dev@UAT> export INPUTDATA2='lcd /Z02/apps/output/UAT/CMUP/incoming cd apl/apl001/download get UPLOAD.DAT bye'
dev@UAT> sftp -oProxyCommand='/usr/bin/nc -v -X 5 -x proxy:99 %h %p' -oPort=22 ${USER1}@${TARGETHOST1} < ${INPUTDATA2}
ksh: lcd /Z02/apps/output/UAT/CMUP/incoming cd apl/apl001/download get UPLOAD.DAT bye: cannot open [No such file or directory]

Please note that the operations which needs to be done after sftp connection is stored in
Code:
INPUTDATA2

Could someone suggest a better way to do that or identify the mistake I am making?

Regards,
# 2  
Old 04-12-2016
The redirection command < pathname feeds the contents of the file whose name is pathname into the standard of the command specified by command.

It would seem that you want something more like:
Code:
USER1=ftp
TARGETHOST1=XX.XX.XX.XX
printf '%s\n' 'lcd /Z02/apps/output/UAT/CMUP/incoming' \
	'cd apl/apl001/download' \
	'get UPLOAD.DAT' \
	'bye' |
    sftp -oProxyCommand='/usr/bin/nc -v -X 5 -x proxy:99 %h %p' -oPort=22 ${USER1}@${TARGETHOST1}

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 04-12-2016
Thanks Don !! I will check and update.

---------- Post updated 04-12-16 at 04:03 AM ---------- Previous update was 04-11-16 at 10:26 PM ----------

Thanks it did worked.

Just out of curiosity can the same be achieved by using
Code:
<

The script I am changing was using
Code:
< ${INPUTDATA2}

while making a FTP connection and I am changing it to use SFTP connection.

Regards,
# 4  
Old 04-12-2016
sftp reads its commands from stdin, no matter if this is filled from the terminal, a pipe that forwards another program's output, or a redirection ("<") that opens a file to read from. But - it has to be a file! Your sample above offers the commands in a shell variable, which is interpreted as a filename and thus leads to the error message posted.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 04-12-2016
If working in a recent shell, you may want to lookup "Here Documents" that offer another way to redirect stdin.
This User Gave Thanks to RudiC For This Post:
# 6  
Old 04-12-2016
Thanks Rudic for the elaboration.

The link was not functional. Could you please paste it again?

Regards,
# 7  
Old 04-12-2016
No link. man bash or man ksh.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sftp connection with password

I am running this script to copy pattern files in local but it is asking for password even passing the hardcode value Script:- PASSWORD="xyz" sftp -oport=1002 user@host:/dir/archive/file*.txt /di/data/ << EOF $PASSWORD quit EOF Got error :- -bash-4.1$ sh sftp_with_password.sh... (5 Replies)
Discussion started by: himanshupant
5 Replies

2. Shell Programming and Scripting

Pls Help: SFTP Error Handling for transfers

I am working on a shell script where after making sftp connection to a remote server the file are being transferred. The problem is how to capture return code for the file which is missing at the remote location. I have tried to capture the return code which return value of "0" even the transfer of... (4 Replies)
Discussion started by: Khan28
4 Replies

3. Red Hat

New sftp connection

Dear All , I have a openssh 4.3p2 , but i need to configure sftp for a user which is present in the server. This user has to see only the specific directory not all. I tried to do the changes in sshd_config for openssh 4.9p1 , but for openssh 4.3p2 how to do it. Any one pl help. ... (1 Reply)
Discussion started by: jegaraman
1 Replies

4. UNIX for Dummies Questions & Answers

SFTP: Connection problem

HI, I have generated public key and placed in remote server. When I am trying to do SFTP for that remote server the below error I am getting. Please help me to resolve Connecting to hostname... Sun_SSH_1.1.4, SSH protocols 1.5/2.0, OpenSSL 0x0090704f debug1: Reading configuration data... (4 Replies)
Discussion started by: rangarasan
4 Replies

5. Shell Programming and Scripting

How to check sftp connection

Hi All, in our system , the sftp server is continuously up. but suddenly it is brought down. how can i find out the reason behind of these , is their any log files or how can i check the connectvity with sftp. please help me to solve this issue (1 Reply)
Discussion started by: aish11
1 Replies

6. UNIX for Dummies Questions & Answers

SFTP Connection error

Hi I when I trying to SFTP a file to a server I am getting this below error: Connecting to 3.12.911.100... ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory Host key verification failed. Connection closed Can you please help me in debugging this error. ... (3 Replies)
Discussion started by: krishna87
3 Replies

7. UNIX for Dummies Questions & Answers

redirecting output retaining the input

Hi Guys, I am trying to redirect output from a file to another file while retaining the contents of the input file. For ex: cat /tmp/Out1.cfg > test.txt Now, test.txt would contain the value of Out1.cfg.,ie say for ex "12" What i require is to have the value as "/tmp/Out1.cfg 12" in the... (2 Replies)
Discussion started by: kiran1112
2 Replies

8. Shell Programming and Scripting

SFTP connection problem

Dear All, I'm trying to configure the passwordless connection between two servers say Server A and Server B. My requirement is a passwordless connection from Server A to Server B. I have done the configuration in both the servers. In Server A its successfull but from Server B its everytime... (7 Replies)
Discussion started by: panknil
7 Replies

9. UNIX for Advanced & Expert Users

SFTP Connection Closed

Hey when trying to connect to a server using a key I get sftp -o 'Port=22' -o'IdentityFile=/home/datatel/.ssh/id_dsa_xei' becker_xei@host Connecting to host... ANGEL SFTP ServerConnection closed by host Connection closed Any ideas? (1 Reply)
Discussion started by: ed.browne
1 Replies

10. Shell Programming and Scripting

input parameters pls help!

Hi i am a newbie who is trying to input parameters into this script, but not sure where to start. The parameters that need to be input are the baseline label "abc.0111.BL " mantioned bellow, and database string "abc/abcp@db2 @counter.sql " Environment: Windows XP Running script: Cygwin 3.2 ... (2 Replies)
Discussion started by: yarik20
2 Replies
Login or Register to Ask a Question