- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need help with ftp to sftp command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2010 01:24 PM
08-21-2010 01:24 PM
Need help with ftp to sftp command
ftp
ftp -i -v ${SVC_HOST} >> ${TMP} 2>&1 <<+
sftp
sftp -o PreferredAuthentications=publickey losapp02@${SVC_HOST} >> ${TMP} 2>&1 <<+
the 2>&1 <<+ at the end causes the sftp not to work, what am i doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2010 02:52 PM
08-21-2010 02:52 PM
Re: Need help with ftp to sftp command
uname -a
ssh -V
> [...] causes the sftp not to work, [...]
Which variety of "not to work" is this?
> what am i doing wrong?
What, exactly, are you _trying_ to do?
(And what, exactly, happens when you do
whatever you do?)
man sftp
Look for "-b"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2010 05:09 PM
08-21-2010 05:09 PM
Re: Need help with ftp to sftp command
unlike ftp, sftp sees 2>&1 as invalid sytax and replies with the help screen showing the switches.
if the stderr can't be captured and grep'd then i may have to check the return code
-b is for batch mode, and not useful in this script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2010 05:42 PM
08-21-2010 05:42 PM
Re: Need help with ftp to sftp command
> then does a get or put then bye
Which "the script" is this? I can't see it.
> unlike ftp, sftp sees 2>&1 as invalid sytax
> and replies with the help screen showing
> the switches.
I doubt that sftp "sees 2>&1". The _shell_
may see (and interpret) that sort of
redirection, however. We might make more
progress if you reported what you actually
did, and what actually happened when you did
it, rather than what you think it all means.
> if the stderr can't be captured and grep'd
> then i may have to check the return code
You may. Probably a good idea in any case.
> -b is for batch mode, [...]
Yes, it is. And what is that "<<+" doing?
> and not useful in this script
You know, if I could see "this script", then
I might agree with that or not.
> What, exactly, are you _trying_ to do?
> [...]
Still shrouded in mystery.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2010 05:28 AM
08-23-2010 05:28 AM
Re: Need help with ftp to sftp command
sudo -u USERNAME scp -B USERNAME@hostname:/SOURCEDIR/filename /DESTDIR/
you can also initiate remote shell scripts with SSH.
If you do the Key exchange you don't have to pass the Authentication params in your connection, it assumes trust.
I am not sure what your <<+ does, if the intent is to read in a carriage return it wouldn't work for either SFTP or FTP.
NOTE "\r" in script below passes carriage return.
One thing you might consider is using expect.
#!/usr/bin/expect -f
# This script needs three argument to(s) connect to remote server:
# password = Password of remote UNIX server, for root user.
# ipaddr = IP Addreess of remote UNIX server, no hostname
# set Variables
set password "REALPASS"
set ipaddr "REALHOST.DOMAIN.TLD"
set arg1 [lrange $argv 3 3]
set timeout -1
# now connect to remote UNIX box (ipaddr)
spawn sftp REALUSER@$ipaddr $arg1
match_max 100000
expect {
-re ".*Are.*.*yes.*no.*" {
send "yes\r"
exp_continue
#look for the password prompt
}
"password:" {
send -- "$password\r"
}
}
expect "sftp>"
send "lcd /SOURCEDIR/\r"
expect "sftp>"
send "put sourcefile\r"
expect "sftp>"
send "ls \r"
expect "sftp>"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2010 05:37 AM
08-23-2010 05:37 AM
Re: Need help with ftp to sftp command
###############################################################################
# DEFINE ENVIRONMENT VARIABLE DEFINITIONS
###############################################################################
CONFIG_FILE="../../environment.config"
LCDIR=`grep LOSDIR $CONFIG_FILE | awk '{print $2}'`
DBNAME=`grep LOSDB $CONFIG_FILE | grep -v LOSDB2 | awk '{print $2}'`
DBSERV=`grep LOSSERV $CONFIG_FILE | grep -v LOSSERV2 | awk '{print $2}'`
export DBNAME;
###############################################################################
# DEFINE DATA SET VARIABLES
###############################################################################
DATA_FILE="../../dataset.config"
#CDB_OUT_DATA=`grep CDB_OUT_DATA $DATA_FILE | awk '{print $2}'`
#CDB_DIR=`echo $CDB_OUT_DATA | cut -d"." -f1`
#CDB_DATASET=`echo $CDB_OUT_DATA | cut -d"." -f2-4`
SVC_OUT_DIR=`grep SVC_OUT_DIR $DATA_FILE | awk '{print $2}'`
SVC_HOST=`grep SVC_HOST $DATA_FILE | awk '{print $2}'`
#SPACE=`grep CDB_OUT_SPACE $DATA_FILE | awk '{print $2}'`
#LRECL=`grep CDB_OUT_LRECL $DATA_FILE | awk '{print $2}'`
#BLK=`grep CDB_OUT_BLK $DATA_FILE | awk '{print $2}'`
##########################################################################
# TEST FOR EXISTENCE OF OUTPUT FILE CREATED BY if040.eco. IF FILE EXISTS
# CONTINUE PROGRAM. IF NO FILE, EXIT SHELL.
##########################################################################
if [ ! -f /app/${LCDIR}/if/servicing/serv_work_out/svc.* ]
then
echo "There are no servicing transaction files staged in the"
echo "serv_work_out directory."
echo "Shell if040_cdb_send.sh ended."
exit 0
fi
cd /app/${LCDIR}/if/servicing/serv_work_out
##########################################################################
# ESTABLISH LOG FILE AND GET LIST OF FILES TO TRANSMIT
##########################################################################
TMP=ftp.out
rm -rf ${TMP}
find . -name "svc.*" > svcfiles
###########################################################################
# LOOP TO TRANSMIT THE TRANSACTION FILE TO THE CENTRAL DATABASE THROUGH FTP
###########################################################################
for filename in `cat svcfiles`
do
echo put ${filename} ${SVC_OUT_DIR} > batchfile
done
ret_code = sftp -b batchfile lossit02@${SVC_HOST}
quit
if ret_code != 0
then
echo "Transfer to Central Database FAILED."
echo "Check the Servicing Connection and Follow Restart Procedures."
exit 1
fi
rm svcfiles
rm batchfile
cat ${TMP}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2010 08:00 AM
08-23-2010 08:00 AM
Re: Need help with ftp to sftp command
Tell me what you're trying to do?
> echo put ${filename} ${SVC_OUT_DIR} > batchfile
">" -> ">>"? Did you look at what's in this
"batchfile"?
> TMP=ftp.out
Who uses this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2010 10:34 AM
08-23-2010 10:34 AM
Re: Need help with ftp to sftp command
> rm batchfile
As a general practice, using such simple
names for temporary files may lead to
problems, as when the user lacks write access
to the current working directory, or when
more than one instance of the script is
running at one time.
Including the process ID ("$$") in the name
should avoid problems with multiple
simultaneous instances of the script.
Putting temporary files into "/tmp" (or some
other, similar place) should avoid local
write-permission problems.
Including some script-identifying text in a
temporary file name can help the victim
puzzle out who's putting all this junk into
"/tmp".
For example:
TMPDIR=${TMPDIR:-/tmp}
base_name=` basename $0 `
temp_file_1_name="${TMPDIR}/${base_name}_1_$$.tmp"
[...]
Also useful:
man
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2010 06:48 AM
08-26-2010 06:48 AM
Re: Need help with ftp to sftp command
I have the sftp scripts & C programs converted to sftp and working. I am attaching an example script in the hopes that anyone working on a similar project can download & use it. To make it work modify the cd/get/put with your commands, and put in your user_id & hostname.
Make sure to install the keys on both hosts first, follow the Public Key Setup directions. Don't use a passphrase unless you have to.
http://sial.org/howto/openssh/publickey-auth/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2010 06:50 AM
08-26-2010 06:50 AM