Automatic ftp job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automatic ftp job
# 1  
Old 04-16-2002
Question Automatic ftp job

I'm slowly (very slowly) learning csh and the UNIX underpinnings of Mac OS X so please bear with me.

I want to be able to ftp a file to my personal webspace at work. I can do this by manually going in and doing

ftp host.domain.com
user:
password:
cd /folder
put myfile
etc..

I'd like to be able to do this automatically. I read the man file on ftp and it told me about .netrc. I tried using that but ftp doesn't want to read my .netrc. Maybe Mac OS X won't let me use a .netrc?
I found Perderabo's suggestion for doing what I think I want to do but it's using ksh.
Code:
#! /usr/bin/ksh

HOST=remote.host.name
USER=whoever
PASSWD=whatever

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd directory
print -p binary
print -p put tar.gz

wait
exit 0

Is there an equivilent to ksh's print function in csh? Is this kind of thing even possible in csh?
# 2  
Old 04-17-2002
Question

If MAC OS X have the possibility to use .netrc files, and in your organization is not considered a security expose.

Man page an a example of an .netrc in Solaris

.netrc: file for ftp remote login data

DESCRIPTION The .netrc file contains data for logging in to a remote host over the network
for file transfers by ftp(1). This file resides in the user's home directory on the
machine initiating the file transfer. Its permissions should be set to disallow read
access by group and others (see chmod(1)).
The following tokens are recognized; they may be separated by SPACE, TAB, or
NEWLINE characters:

machine <destination_server_name> Identify a remote machine name.
The auto-login processsearches the .netrc file for a machine token
that matches the remote machine specified on the ftp command line or as
an open command argument. Once a match is made, the
subsequent .netrc tokens are processed, stopping when the
EOF is reached or another machine token is encountered.

login <name>: Identify a user on the remote machine. If this token is
present, the auto-login process will initiate a login using
the specified name.

password <remote_user_passwd> :Supply a password. If this token is present,
the auto-login process will supply the specified string if the remote server
requires a password as part of the login process. Note: if
this token is present in the .netrc file, ftp will abort the
auto-login process if the .netrc is readable by anyone
besides the user.

account <remote_user_account_name>: Supply an additional account password.
If this token is present, the auto-login process will supply the specified
string if the remote server requires an additional account
password, or the auto-login process will initiate an ACCT
command if it does not.

macdef <name> : Define a macro. This token functions the same as ftp
macdef. A macro is defined with the specified name; its
contents begin with the next .netrc line and continue
until a null line (consecutive NEWLINE characters) is
encountered. If a macro named init is defined, it is
automatically executed as the last step in the auto-login
process.

EXAMPLES EXAMPLE 1 A Sample .netrc File
A .netrc file containing the following line:
machine ray login demo password mypassword
allows an autologin to the machine ray using the login name demo with password mypassword.

Good luck, Hugo.Smilie
# 3  
Old 04-17-2002
Welcome to the forum, DumDum! It's good to see a newcomer who actually used the search function.

The csh equivalent of print would be "echo". But the there is no equivalent of "print -p" which sends the line to a co-process. But then, csh doesn't have a co-process concept either. Nor can csh manipulate file descriptors. In short, you are not going to be able to use my technique with csh.

I am not familiar with the MAC OS X. Are there any other shells available? Even the old Bourne shell could be used with a "here document".
Code:
#! /usr/bin/sh
HOST=remote.host.name
USER=whoever
PASSWD=whatever

ftp -nv <<-!x
open $HOST
user $USER $PASSWORD
cd directory
binary
put tar.gz
bye
!x
exit 0

PS

Another thread implies that csh can handle "here documents" like this. You might give it a try...I'm not real expert with csh, so I'm not sure.

Last edited by Perderabo; 04-17-2002 at 10:43 AM..
# 4  
Old 04-17-2002
Well I finally got the .netrc file to work. I guess the first time I did it I formatted the .netrc file wrong or something.

I think other shells are available in OS X but I don't know if they're already there or if I have to go find them and try to install them. I may be checking out other shells just for the sake of learning how to script.

:Update: It turns out that Mac OS X has a little bit of most everything. According to one user on Macaddicts message boards, Mac OS X has csh, tcsh, Bourne and bash. I tried out that script written for Bourne and it worked like a charm.

Thanks for the help. (again) Smilie

Last edited by DumDum; 04-17-2002 at 06:30 PM..
# 5  
Old 04-07-2005
duh

1234567890

Last edited by Steve_H; 04-07-2005 at 10:36 AM.. Reason: duh, should have realised this thread was 3 years old
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

automatic FTP failed

I have automated ftp for different scripts. every script uses different login and passwords for different server. it reads the username and password from netrc. there is 1 particular script that is failing. this script is failing in FTP step. i have checked the logs it says login failed. but... (5 Replies)
Discussion started by: dazdseg
5 Replies

2. Shell Programming and Scripting

Automatic FTP-Download | not files older then x days

Hey Guys, i need to download files from a ftp-server that not older than $VAR (x) days eg for seven days ./script 7 or two weeks ./script 14 all files from the last 14 days will download but how i can explain "ftp" this? sorry for my strange english :/ (2 Replies)
Discussion started by: tetex
2 Replies

3. Shell Programming and Scripting

Automatic FTP

Hi I am looking for automatic FTP script from UNIX to UNIX servers. I have two problems that anyone may help: 1- The directory where the files have to be FTPed is varied, where it is identified by the date of today (YYYYMMDD) 2- the files come every 15 minutes and named by the time with form... (2 Replies)
Discussion started by: akhadoor
2 Replies

4. AIX

.netrc and Automatic ftp problem

Guy's We have two AIX servers Server1 and Server2 and we have created user1 in Server1 and Server2 ... and .netrc file was confiured under /home/user1 with the below line machine server2 login user1 password abc1234567 -rw------- 1 user1 staff 159 Sep 28 2004 .netrc ... (7 Replies)
Discussion started by: ITHelper
7 Replies

5. SCO

Automatic FTP script

We are using SCO OS 5.05 server and we are doing a manual ftp to another SCO OS 5.05 server to backup our database. We are using the Bourne shell. We would like to automate the ftp backup of our database instead of doing it manually. It would be nice to run a script. Also would there be anyway... (4 Replies)
Discussion started by: texastig
4 Replies

6. UNIX for Advanced & Expert Users

Cron FTP job

We have a script that we run manually, we want to set it up so that it will run automatically via cron, the problem is during the ftp process nothing is put, the script logs in changes directory fine, but nothing is put to the directory. I have tried it as root, a power user, etc. I have made the... (4 Replies)
Discussion started by: marvin51796
4 Replies

7. Shell Programming and Scripting

Automatic FTP Script from windows to unix machine

Hi i need to FTP files from windows to unix(sun) machine using script. what are the scripts commands i need to use to transfer files Thanks (2 Replies)
Discussion started by: bmkreddy
2 Replies

8. Shell Programming and Scripting

Is it possible..when ftp session disconnect and it can automatic run again?

Hi, Is is possible when ftp script disconnect by remote server and it can restart to tranfer (such as restart in 10 mins, etc)? Please help!!!! (1 Reply)
Discussion started by: happyv
1 Replies

9. SCO

SCO 5.06 :automatic shutdown on the job?

Hi Guys I have got a problem and I would really be grateful if some1 could sort out the problem. The problem is that there are a few computers based on SCO 5.0.6 automatic shutdown on the job.and I am anxious to konw the reasons. Looking forward to seeing some messiah helping me out.... (1 Reply)
Discussion started by: rendechen
1 Replies

10. UNIX for Advanced & Expert Users

Automatic FTP

Hi, We have a requirement to transfer(FTP) files created in a particular directory (In Solaris) to NT machine. Also this process neeeds to be automated. I belive a command MAIL in UNIX could be used to find new files created in a directory, but this just sends the file list to the logged user.... (5 Replies)
Discussion started by: shyamrk
5 Replies
Login or Register to Ask a Question