1748016 Members
4197 Online
108757 Solutions
New Discussion юеВ

SFTP Script

 
SOLVED
Go to solution
prabhaharan Rajkumar
Occasional Advisor

SFTP Script

Hi,

I am going to sed a file through SFTP. I have no idea about SFTP. could anyone please send the sample script
15 REPLIES 15
James R. Ferguson
Acclaimed Contributor

Re: SFTP Script

Hi:

You need to setup public keys on your servers to eliminate the need for passwords in scripts. You can use Perl or a pure shell script. In a shell:

# cat .mysftp
HOST=$1
FILE=$2
sftp -b - <lcd /tmp
cd /tmp
put -P ${FILE} ${FILE}.backup
EOF
RC=$?
print -u2 "\nSFTP returned ${RC}"
exit ${RC}

...run as;

# ./mysftp somehost somefile

As for the public key setup and more about the Secure Shell in general, see :

http://sial.org/howto/openssh/publickey-auth/

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1254688

These two links should provide you the information you need to easily do this. The 'known_hosts' file contains the public host keys for all known hosts. The per-user version is maintained automatically. Thus, whenever you connect from an unknown host, its key is added to the per-user file if you choose to acknowledge the fingerprint. If you don't, the connection can still be made, but you will be prompted the next time as if you had never connected.

The manpages for 'sshd' and 'ssh' offer more information.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: SFTP Script

Shalom,

SFTP is part of a suite of tools that includes ssh, scp.

You really don't need to write an sftp script.

Exchange public keys and use a simple scp command. Works just like rcp.

http://www.hpux.ws/?p=10

SEP
hpuxadmin in gtalk
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
John Guster
Trusted Contributor

Re: SFTP Script

does this work between UNIX and window file transfer?
prabhaharan Rajkumar
Occasional Advisor

Re: SFTP Script

Hi friends,

Thanks for your reply.
but I have the following information.
1) I am going to send the file from AlphaVMS(development server) to other side.
2)In our VMS support(admin team) have configured Tectia SSH and provided Public key.
3) what my question is :

Extracted files sent to receiver server thru NDM link, i already written.

$!===========================================================================
$! Transfer file thru NDM
$!===========================================================================
$ type/output=copy_cmds.sql sys$input:
$ deck!======================================================================
drop table tmp_ndm_cmds1
\p\g
create table tmp_ndm_cmds1
as
select num = 1,
cmd = '$ copy/log ie_acctinfo.dat '+e1.value+e2.value+'ie_acctinfo.dat'
from environment e1, environment e2
where e1.name = 'dd_node' and e2.name = 'dd_dir'
\p\g
insert into tmp_ndm_cmds1
select num = 2,
cmd = '$ copy/log nl: '+e1.value+e2.value+'ie_acctinfo.dat_ack'
from environment e1, environment e2
where e1.name = 'dd_node' and e2.name = 'dd_dir'
\p\g
select cmd, num from tmp_ndm_cmds1
order by num
\p\g
drop table tmp_ndm_cmds1
\p\g\q
$ eod!=======================================================================
$ DELETE/log dbout.txt;
$ DELETE/log acctinfo_final.sql;
$ CLOSE outf
$ UNLOCK/LOG ie_acctinfo.dat
$ P = "Client-Account:"
$ SHOW SYMBOL P
$ SHOW SYMBOL COUNT
$!===========================================================================
$! Transfer file thru NDM
$!===========================================================================
$ type/output=copy_cmds.sql sys$input:
$ deck!======================================================================
drop table tmp_ndm_cmds1
\p\g
create table tmp_ndm_cmds1
as
select num = 1,
cmd = '$ copy/log ie_acctinfo.dat '+e1.value+e2.value+'ie_acctinfo.dat'
from environment e1, environment e2
where e1.name = 'dd_node' and e2.name = 'dd_dir'
\p\g
insert into tmp_ndm_cmds1
select num = 2,
cmd = '$ copy/log nl: '+e1.value+e2.value+'ie_acctinfo.dat_ack'
from environment e1, environment e2
where e1.name = 'dd_node' and e2.name = 'dd_dir'
\p\g
select cmd, num from tmp_ndm_cmds1
order by num
\p\g
drop table tmp_ndm_cmds1
\p\g\q
$ eod!=======================================================================
$ sql custody copy_cmds.txt
$ OPEN /WRITE outf1 copy_cmds.con
$ OPEN /READ inf1 copy_cmds.txt
$ loop_cmd:
$ read /end_of_file=cmd_done inf1 line
$ IF (F$EXTRACT(0,2,line) .NES. "|$") then goto loop_cmd
$ second_bar = f$locate("|",F$EXTRACT(1,F$LEN(line)-1,line))
$ lin_out = F$EDIT(F$EXTRACT(1,second_bar,line),"TRIM")
$ WRITE/symbol outf1 lin_out
$ goto loop_cmd
$ cmd_done:
$ close inf1
$ close outf1
$!copy/log ie_acctinfo.dat MEDDEV::NDM_SEND:ie_acctinfo.dat
$!copy/log nl: MEDDEV::NDM_SEND:ie_acctinfo.dat_ack
$@copy_cmds.con
$delete/log copy_cmds.sql;
$delete/log copy_cmds.txt;
$delete/log copy_cmds.con;
$exit

This one i tested from my side thr' NDM.
but now i should send the file thr' SFTP.
I think now you can understand clearly.
please advice and help me.
i really appriciate your help.
James R. Ferguson
Acclaimed Contributor
Solution

Re: SFTP Script

Hi (again):

> I am going to send the file from AlphaVMS(development server) to other side.

Then why didn't you post this in the OpenVMS formum?!?

http://forums.itrc.hp.com/service/forums/familyhome.do?familyId=288

Since I don't know anything about VMS I can't comment further except to say you might want to consider a Perl SFTP solution.

Regards!

...JRF...
prabhaharan Rajkumar
Occasional Advisor

Re: SFTP Script

Hi,

Then where do i post my query and get the answer.

I am new in this forum.
please advice.
Steven Schweda
Honored Contributor

Re: SFTP Script

> I am going to sed a file [...]

So, "sed" was really "send"? There is a
program named "sed", you know.

> Then where do i post my query and get the
> answer.

How did you find the _wrong_ forum?

http://forums.itrc.hp.com/service/forums/home.do
http://forums.itrc.hp.com/service/forums/familyhome.do?familyId=288

> This one i tested from my side thr' NDM.

What is "NDM"?

Someone may want to analyze your whole
command procedure, but I sure wouldn't. If
your question is, "How do I transfer a file
using SFTP?", then ask that question.

I'd start by trying to get it to work
manually. _Then_ I'd move on to making it
work in a procedure.

> [...] Tectia SSH [...]

_Where_ is this installed?
Steven Schweda
Honored Contributor

Re: SFTP Script

And one more thing, ...

> [...] to other side.

What is "other side"?
prabhaharan Rajkumar
Occasional Advisor

Re: SFTP Script

steven,

1) yes, you are right. " i am going to send the file"

2) NDM -- this is also a file transfer protocol

3) " to other side " means other application.

I developed a new file(. com). Usually we trasfer the file through NDM setup.

But this project i have to use SFTP to transfer the file.
They(receiver) have given the "HOST NAME and DIRECTORY/ FOLDER NAME"

I know nothing about SFTP, how I use to transfer the file.
what commands use in file and how I transfer from Alpha server(development environment)

axp>sftp

.. like

could you please guide me.