Problem in SFTP using heredoc


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in SFTP using heredoc
# 8  
Old 03-16-2011
Thanks for the reply.

I heard from my colleague that, there is some restriction set in sftp server, that's why heredoc is executing only one command. If I put get as a first command in heredoc, I'm able to get file from sftp server. Colleague told me that he faced this problem and resolved this by using batch file.

I'm having doubt that, Is it possible to make such restrictions in server?
Have anyone of you faced these kind of problem before?
# 9  
Old 03-16-2011
If you are able to run the commands explicitly with the same user, there shouldn't be any problem regarding access. [ Though I don't have much idea about that part ]. May be other could help us.

Just for a try, you could try to run those commands on command line (with here doc).
Press "enter" after each line and see what happens.

Code:
$>> sftp user@host <<FTP
lcd /WEBSERVER_LINK/data_logs/
ls -l pub/csidata/GeneralAppFields_8_1_Feed.out
get pub/csidata/GeneralAppFields_8_1_Feed.out
quit
FTP

# 10  
Old 03-16-2011
Thanks anchal.

I tried this heredoc in command line, I'm getting the same result which I'm getting in script.
Code:
bash-3.00$ /export/opt/SCssh/3.7.1_C0/bin/sftp  csi@192.168.1.100 <<FTP
> lcd /WEBSERVER_LINK/data_logs/
> ls -l pub/csidata/GeneralAppFields_8_1_Feed.out
> get pub/csidata/GeneralAppFields_8_1_Feed.out
> quit
> FTP
You are authorized to use this System for approved business purposes only.
Use for any other purpose is prohibited. All transactional records, reports,
e-mail, software, and other data generated by or residing upon this System
are the property of the Company and may be used by the Company for any purpose.
Authorized and unauthorized activities may be monitored.

sftp>
/WEBSERVER_LINK/data_logs
sftp>
-rw-r--r-- 1000416  300017   10631705 Mar 15 20:09 GeneralAppFields_8_1_Feed.out
sftp>

---------- Post updated at 08:43 PM ---------- Previous update was at 08:42 PM ----------

Quote:
Originally Posted by zaxxon
Is using ssh and/or scp instead an option?
Please explain clearly, because I couldn't understand this.

Last edited by zaxxon; 03-16-2011 at 12:45 PM.. Reason: code tags
# 11  
Old 03-16-2011
Quote:
Originally Posted by bheeshmaraja
Thanks anchal.

I tried this heredoc in command line, I'm getting the same result which I'm getting in script.
...but you're still not using -b -, which I really suggest you do. The noninteractive behavior may be quite different.

scp does a simple file-copy. scp local-source username@host:path/to/remote/dest
scp username@host:pub/csidata/GeneralAppFields_8_1_Feed.out path/to/local/dest && ls -l path/to/local/dest Timestamps on the retrieved file should match timestamps on the remote one.

ssh is of course secure shell. You can use it to grab files by using a pipe:
Code:
ssh -T username@host cd pub/csidata/ '&&' tar -cf - GeneralAppFields_8_1_Feed.out |
    tar -C path/to/destdir/ -xf -

will retrieve the GeneralAppFields_8_1_Feed.out file and extract it on your local machine, including proper timestamps.

Or, in general, you can just do the one command, the retrieval, and do the rest locally.

Last edited by Corona688; 03-16-2011 at 12:24 PM..
# 12  
Old 03-16-2011
Quote:
ls -l pub/csidata/GeneralAppFields_8_1_Feed.out
Sorry to labout this point but the above command will attempt to write a directory listing to file called pub/csidata/GeneralAppFields_8_1_Feed.out .

Code:
Use:
ls -l
Or:
ls pub/csidata/GeneralAppFields_8_1_Feed.out
Not:
ls -l pub/csidata/GeneralAppFields_8_1_Feed.out

# 13  
Old 03-16-2011
Thanks Corona.
Now my heredoc is working fine.
Code:
Code:
 
/export/opt/SCssh/3.7.1_C0/bin/sftp -B - csi@192.168.1.100 <<FTP
lcd /WEBSERVER_LINK/data_logs/
ls pub/csidata/GeneralAppFields_8_1_Feed.out
get pub/csidata/GeneralAppFields_8_1_Feed.out
quit
FTP

Now I'm able to get files from FTP server.
# 14  
Old 03-16-2011
You sure its working?
"-B" is for buffer size. You must use "-b".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Information on heredoc

Hi , I am using ksh on Aix 7.1 and found the below code in a script which is a bit confusing to me, any help will be appreciated <<comments put ${pathforfiles}/${ftpfilename} put ${logs}/${filename}.sch put ${logs}/${filename}.tgr comments I have searched for information on heredoc but... (2 Replies)
Discussion started by: zulfi123786
2 Replies

2. UNIX for Beginners Questions & Answers

SFTP problem

i have a problem no a dream :) i have a list and i want to do : cat lista_olo for file in `cat list` do sftp myuser@myip << EOF ls -l mydir/$file/ EOF but there is an error . Syntax error at line 11 : `<' is not matched How can i do ? Regards. (1 Reply)
Discussion started by: Francesco_IT
1 Replies

3. Shell Programming and Scripting

How To Concatenate Two Commands in script using heredoc?

Hello, I am trying to place two commands in heredoc below is the snippet if ;then actionOnTux="$actVerb" else actionOnTux="$actVerb" fi echo "Performing ACTION: $action on $tux@$srv .....\n" if ; then ... (5 Replies)
Discussion started by: kataria.anand
5 Replies

4. Shell Programming and Scripting

Problem with sftp

I have an sftp script which is uploading file into a directory which is not specified wth the cd command . For example: sftp sftpserver >>lcd /abc >>cd /tmp/bef >> put /abc/abc.txt /tmp/bef/abc.txt Uploading file from /abc/abc.txt to /xyz/wxy/tmp/bef/abc.txt >>quit The file is getting... (2 Replies)
Discussion started by: NP1
2 Replies

5. Shell Programming and Scripting

Echo multi-line string via heredoc syntax

$ cat bashtest #!/usr/local/bin/bash echo <<<"EOF" line1 line2 line3 EOF $ ./bashtest ./bashtest: line 3: line1: command not found ./bashtest: line 4: line2: command not found ./bashtest: line 5: line3: command not found ./bashtest: line 6: EOF: command not found What am i doing... (4 Replies)
Discussion started by: urello
4 Replies

6. Shell Programming and Scripting

Calling sqlplus from Korn shell heredoc issue

Hi, I am facing an issue wherein some temporary files (here docs) are getting created in /tmp and are not getting deleted automatically. When i check the list of open files with below command i can see one file is getting appended continuously.(In this case /tmp/sfe7h.34p) The output is... (4 Replies)
Discussion started by: Navin_Ramdhami
4 Replies

7. Shell Programming and Scripting

Variables in heredoc

I currently use this message to send e-mails in a script but I would also like to save the output of this code to a file as well while preserving the variables. What's the easiest way to accomplish this? #Sending mail notification when=`/bin/date` /usr/sbin/sendmail -t >2 <<-EOM... (2 Replies)
Discussion started by: woodson2
2 Replies

8. Shell Programming and Scripting

heredoc error check

Hi, Is there any way to check the error in heredoc? Code: /export/opt/SCssh/3.7.1_C0/bin/sftp -B - csi@192.168.1.100 <<FTP lcd /WEBSERVER_LINK/data_logs/ ls pub/csidata/GeneralAppFields_8_1_Feed.out get pub/csidata/GeneralAppFields_8_1_Feed.out quit FTP Now I want to check... (1 Reply)
Discussion started by: bheeshmaraja
1 Replies

9. Shell Programming and Scripting

HEREDOC with fdisk

Hi folks What I'm trying is to build a partitioning script. I can pass a HEREDOC to fdisk just fine. Like this: fdisk /dev/sda << EOF p q EOF but I don't know how to put that HEREDOC into a varible to pass it to fdisk. This is what I have tried so far (no luck) #!/bin/bash ... (3 Replies)
Discussion started by: latenite
3 Replies

10. Cybersecurity

sftp problem

Hi, I'm in the process of writting some scripts using sftp2 on a HP UX 11.11 machine. I've found that when I do an 'ls' command , even when in batch mode, it asks for me to 'press any key to continue or q to quit' after a screenful of data. Of course in batch mode this cause the script to hang.... (0 Replies)
Discussion started by: sudojo
0 Replies
Login or Register to Ask a Question