1834133 Members
1959 Online
110064 Solutions
New Discussion

Re: ftp command

 
augusto cossa
Frequent Advisor

ftp command

Hi,

I need to ftp a file from one UNIX box to other UNIX box without humman intervation. I do not need the second box to ask for a user name and password.

Help.

Augusto
5 REPLIES 5
John Palmer
Honored Contributor

Re: ftp command

Do you want the second box not to ask for a password (not recommended) or do you want to automatically supply one via a scripted ftp?

If the latter then the trick is to run ftp with the -n flag to disable auto-login. You can then supply the user command (with the password) as part of your command stream.

I suggest that you use the forums search facility for more information, this is a popular subject.

Regards,
John
Eileen Millen
Trusted Contributor

Re: ftp command

Hi Augusto,

The rcp command might be a good option.
If the username and password are the same on
both systems, rcp should do the job without having to enter a password.

Eileen
Christopher McCray_1
Honored Contributor

Re: ftp command

Hello,

Do a man on .netrc

This may be what you are looking for.

Chris
It wasn't me!!!!
John Dvorchak
Honored Contributor

Re: ftp command

Create a .netrc file in the users home directory on the machine that you want to initiate the ftp from. Here is an example of a .netrc file:

machine machine_name_you_want_to_ftp_to
login your_login_name
password password_on_target

then be sure that the file is only readable by you. If .netrc is readable by anyone else it is ignored:

chmod 400 .netrc

Then create a shell script to do the transfer unattended:

#!/usr/sbin/sh
ftp -v machine_name > ftp.log << -EOF
asc
put file_name_to_transfer
quit
EOF

chmod it so it executes.
The -v option tells ftp to work verbose so it will actually put something in ftp.log for you to check status or have it mailed to you.
If it has wheels or a skirt, you can't afford it.
A. Clay Stephenson
Acclaimed Contributor

Re: ftp command

A far better method than trying to shell script your way through this is to use the Perl Net::FTP module. My big question to you is "How do you know that your transfer worked?" How do you know the file was completely sent? You don't. You can check stderr of ftp but that is a pain. All you really need to do is look at the status value in Net::FTP and for a transfer, 2 is good.

Do something like this:
ftp.pl myfile1 myfile2
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "FTP ok"
else
echo "FTP failed"
fi

If the exit status of ftp.pl = 0 then myfile1 and myfile2 were sucessfully transferred. The login can be embedded withing the login command of the script or you can simply supply the login and .netrc will be read for the passwd.

You can download the Net::FTP module from www.perl.com/CPAN.

I never script these transfers in the shell anymore; Perl does it so much cleaner.
If it ain't broke, I can fix that.