Operating System - HP-UX
1825775 Members
1974 Online
109687 Solutions
New Discussion

Re: SFTP script assistance

 
David Bell_1
Honored Contributor

SFTP script assistance

First, I know this should be done with RSA but I need to perform some testing first. Here's what I'm hoping to accomplish:

I'm attempting to automate a process that checks for the existence of files in a top level directory with 4 subdirectories, if it exists, it launches sftp to transfer the file to some location, it validates the send, then deletes the file. The structure would be something like this:

/scproot/dir_out
/scproot/dir_out/dir1
/scproot/dir_out/dir2
/scproot/dir_out/dir3
/scproot/dir_out/dir4

Each subdirectory may contain *.xml file.

I know this is not secure but it is for testing only at this time:

the sftp portion would be something like

#!/usr/bin/sh
HOST='myhost.com'
USER='username'
PASSWD='password'

sftp $USER@$HOST <${PASSWD}

binary
cd /dir1/dir2/
put some_file

Can someone help me script this appropriately?

Thanks,

Dave
4 REPLIES 4
Rick Garland
Honored Contributor

Re: SFTP script assistance

A quick glance - you do not need to specify binary transfer. The sftp handles this fine.
If you configure the keys you do not need to worry about having the $USER and $PASSWD hardcoded in the script.

Another option could be to use scp. If the file exists then secure copy the file. If the file does not exist, then the logic in the script will indicate this. After all tranfers are completed, you could use ssh to issue the rm command
David Bell_1
Honored Contributor

Re: SFTP script assistance

Rick,

Thanks for the information. In this particular case, I will need ot use sftp. I'm actually hoping to make it scp shortly but I can't at this time. The RSA keys will follow in time as well, making the username/passwd unneccesary as you stated. I'm still going to need to create a script to do the search of the directories for *.xml and then do an sftp. Perhaps the sftp could be in a separate script.

Dave
David Bell_1
Honored Contributor

Re: SFTP script assistance

All,

I know I can't pass the password in a configuration file even in batch mode so I'll have to go to RSA key exchnage. However, I would still appreciate some assistance on finding the *.xml files and creating an sftp script that can pass the RSA keys. I would like to use scp but at least for now, I must use sftp.

Thanks for the input.

Dave
David Bell_1
Honored Contributor

Re: SFTP script assistance

I have written the script using "expect" for the time being until I can exchnage RSA Keys.