1833294 Members
3425 Online
110051 Solutions
New Discussion

Re: help in ftp

 
Amir Efrat
New Member

help in ftp

Hi, I'm trying to ftp to a remote station in an automatic way - using a script.
How can I enter a user and password in a script that is run by crontab ?
thanks.

Amir
4 REPLIES 4
Alan Casey
Trusted Contributor

Re: help in ftp

you can enter:

ftp hostname <user USERID PASSWORD
put file1 file2
bye
EOF



Sebastian Galeski_1
Trusted Contributor

Re: help in ftp

Hi
try it:

#!/usr/bin/sh
# Script to FTP file
# ftp host user password source_file destination_dir

set -x

HOST=$1
USER=$2
PASS=$3
FILE=$4
DEST_DIR=$5

( echo "user $USER $PASS"
echo "binary"
echo "cd $DEST_DIR"
echo "put $FILE"
echo "quit" ) | ftp -i -n $HOST


use:
./script server1 jack pass file dir1


hope it help
BFA6
Respected Contributor

Re: help in ftp

Hi,

We have the following in a script for ftp

{ ftp -n -v $FTPSERVER << ENDOFGET
user $FTPUSER $FTPPASSWD
prompt
binary
get $GETFILE $LOCALFILE.transfer
close
ENDOFGET
} > $TMPFILE 2>&1

$FTPSERVER is the remote server
$FTPUSER is the username
$FTPPASSWD is the password for that user

Hope this helps

Regards,

Hilary
Chris Wilshaw
Honored Contributor

Re: help in ftp

You could also set up a .netrc for the user

Create this in their home directory.

It can contain a number of entries in the format

machine login password

set this file to have read only permissions for the user

chmod 400 .netrc

then, ftp to the machine identified by

This should then automatically log you in to the server without requesting an ID/password.

Don't forget that having passwords in scripts and .netrc files can be a security risk.