1819704 Members
3446 Online
109605 Solutions
New Discussion юеВ

Re: 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.
Steven Schweda
Honored Contributor

Re: SFTP Script

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

If you say so.

> 3) " to other side " means other application.

SFTP doesn't copy a file to an application,
it uses an SFTP server on the other system.
I was hoping to get some information about
the other system and its SSH/SFTP software.

> I know nothing about SFTP, [...]

Apparently. And I know nothing about the
SSH/SFTP software on your VMS system.

> > [...] Tectia SSH [...]
>
> _Where_ is this installed?

Is that on the VMS system?

Does
sftp "-V"
tell you anything?

"sftp -h"?

With no information about the SSH/SFTP
software on your VMS system, and no
information of any kind about the other
system, I'd rather not guess.
prabhaharan Rajkumar
Occasional Advisor

Re: SFTP Script

1) SFTP set up on both systems (my side and receiver side)

2) Tectia SSH is in receiver side. i think it used for formatting.

3)I checked in my system in the following command

axp_pr$ sftp "-v"

%SD-I-PRIVLOG - System Privilege activity being logged.


Sftp2/SFTP2.C:5183: CRTL version (SYS$SHARE:DECC$SHARE ident) is: V8.3-01


SshFileCopy/SSHFILECOPY.C:1354: Making local connection.
Ssh2SftpServer/SSHFILEXFERS.C:2120: Received SSH_FXP_INIT
Ssh2SftpServer/SSHFILEXFERS.C:2165: version is 999
Ssh2SftpServer/SSHFILEXFERS.C:2227: Sending SSH_FXP_VERSION with sftp-version@op
envms.hp.com as 3
SshFileXferClient/SSHFILEXFERC.C:1432: ssh_file_client_receive_proc: coming in w
ith extension data, OpenVMS host
SshFileXferClient/SSHFILEXFERC.C:1478: vms_plus_sftp_version = 3
SshFileCopy/SSHFILECOPY.C:1293: Connection to local, ready to serve requests.
Sftp2/SFTP2.C:822: Connection ready.
SshReadLine/SSHREADLINE.C:3662: Initializing ReadLine...
sftp>


Steven Schweda
Honored Contributor

Re: SFTP Script

> Does
> sftp "-V"
> tell you anything?

> axp_pr$ sftp "-v"

What's wrong with this picture?


> 1) SFTP set up on both systems (my side and
> receiver side)

Have you (generated and) exchanged public key
data with the remote system? Or did you plan
to script an interactive password? (I'm not
sure that you can. Public-key authentication
would be the usual thing to do.)


> %SD-I-PRIVLOG - System Privilege activity being logged.

It's probably not important, but that doesn't
look like a standard VMS message. Do you
have some extra (third-party?) security
package ("SD"?) installed, too?
prabhaharan Rajkumar
Occasional Advisor

Re: SFTP Script


axp_pr$ sftp

%SD-I-PRIVLOG - System Privilege activity being logged.


sftp> "-v"
Unrecognized command line: '"-v"'
sftp>



yes, we generated public key and exchanged


> %SD-I-PRIVLOG - System Privilege activity being logged.

the above message comes usually. we doesn't care about this message.
Steven Schweda
Honored Contributor

Re: SFTP Script

> sftp> "-v"
> Unrecognized command line: '"-v"'
> sftp>

Sigh. Read it again.
prabhaharan Rajkumar
Occasional Advisor

Re: SFTP Script

ok, what i have to do next.