You could write the ftp code out to a file and then use the system command to execute that file. Here is a script that I use:
Code:
#!/usr/bin/perl
# #########################################################################
# # This script was written to search directories read ##
# # from the file pwdirs and search them for monthly reports to be sent ##
# # to . You must provide the beginning day, ending day and ##
# # month on the command line. The beginning day, ending day and month ##
# # must be two digits ex: 01,02....31. This script will pull files for ##
# # days and month specified. The command to run this is: ##
# # perl pwcopy.pl BEGINNING_DAY ENDING_DAY MONTH . ex: ##
# # perl pwcopy.pl 01 03 09 ##
# # The above command would copy reports from the 1st through 3rd days ##
# # for the month of September. ##
# #########################################################################
# # These are passed from the command line
$begin=$ARGV[0]; #Get the begin day of month
$end=$ARGV[1]; #Get the end day of the month
$month=$ARGV[2]; #Get the month of the reports to copy
# Get the current date
($csec,$cmin,$chour,$cmday,$cmon,$cyear,$cwday,$cyday,$cisdst) = localtime(time);
$cyear=$cyear+1900; # get the correct year
$cmon=$cmon+1; # Get the correct month
if($cmon<10) {$cmon="0$cmon";}
if($cmday<10) {$cmday="0$cmday";}
if($chour<10) {$chour="0$chour";}
if($cmin<10) {$cmin="0$cmin";}
if($csec<10) {$csec="0$csec";}
# # Open file to write ftp script to
open(ftpsc, '>/usr/local/bin/pwpmftp') or die "Can't open ftp script file";
print ftpsc "# This script is created by the script pwcopy.pl\n";
print ftpsc "ftp -in 00.00.00.00 <<EOF\n";
print ftpsc "user userid password\n";
print ftpsc "type ascii\n";
# # Open the file containing the directories to be searched
open(DIRFIL, 'pwdirs') or die "Can't open directory file pwdirs\n";
while (<DIRFIL>) {
$dir = $_ ;
chomp($dir);
# # Open the directory to be read for files
opendir(CURR, $dir) or die "Can't open directory: $dir $!\n";
while (defined($file = readdir(CURR))) {
if ($file =~ m/ARM|AMI|AMR[^AMRA|^AMRB|^AMRD]/) {
$mtime = (stat("$dir/$file"))[9]; # Get the last accessed date
# # Create a readable date to compare to the current date from above
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime);
$mon=$mon+1;
$year=$year+1900;
if($mon<10) {$mon="0$mon";}
if($mday<10) {$mday="0$mday";}
if(($mday ge $begin && $mday le $end) && $mon eq $month && $year eq $cyear) {
$count=$count+1;
$fdate_time="$cmon$cmday$cyear$chour$cmin$csec$count";
$new_file=substr($file,4,4);
$odir=substr($dir,10,3);
print ftpsc "put $dir/$file /$odir/$odir$new_file$fdate_time.txt\n";
}
}
}
}
print ftpsc "quit\n";
print ftpsc "EOF\n";
close ftpsc;
system("./pwpmftp");
I am sure someone more experienced than I could write a more efficient perl script, but it works for me. Good Luck.
Hi,
I am trying to write and automate a ftp job that connects to a IBM mainframe and pulls the same files everyday.
To do this I assumen I create a .netrc file in my solaris home directory, then I write a shell script. How do I envoke ftp from a ksh script and pass it the info in .netrc?
I... (11 Replies)
One of our most frequent questions is how to automate ftp transfers. There are several approaches. Since I'm writing this post, we will start with my favorite technique. :)
In Automated FTP task I present a simple example of my ksh co-process technique. And note that later in this thread I... (0 Replies)
Hi all,
I got this piece of code in this forum and I can't seem to get it work. The thread already closed so I just post a new thread.
#!/usr/bin/ksh
ftp -v -n "YOUR.IP.ADD.RESS" << cmd
user "user" "passwd"
cd /distant/directory
lcd /local/directoryget ssh_install
get ( or put) your... (4 Replies)
Hello script experts,
I am newbie to shell script. But I have to write a shell script (ASAP) where I need to ftp a file on daily basis to a remote server, and send an email with final status. I I should have a properties file with hostname, Userid, and pwd. And a shall script file should read... (1 Reply)
Hi,
Currently, i am using sftp manully to transfer files between two secure servers. Can anyone provide me a sample shell script which can automate the sftp process? (11 Replies)
How to automate FTP files daily with the following constraints
1) Try (every 15 mins or 30 mins) FTP till it reconnects
2) Files that arrive in between 5:30 pm and 2:00 am
3) The sat and sun, mon files are to be FTP on monday.
4) Only the txt files are to be FTP'ed.
The following are the... (2 Replies)
Hi Guys,
i have this lil challenge;
i am to implement an automated script that searches/scans a directory for files then picks and sends this files to a very remote server via an ftp link.
the challenge here is that the ftp link fails due to netwrk issues maybe;
i therefore need to develop... (5 Replies)
Plzz Some One Help in this matter
I have scripts to load the data into tables and to copy files from ftp to our system.
we use to run the scripts every day....
we hav the files in the FTP server and we hav to bring the files to our system and we hav to load the data into the tables.
We... (0 Replies)
Hello All,
I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir.
rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed.
Can some body help me to... (2 Replies)
Heyas
Seen some of the ftp posts here and knowing i'll be writing a script using ftp soon, so i thought i'd write a script to automate, or at least simplify some basic tasks with it.
I'm currently stuck at handling active/passiv modes.
Neither lftp nor sftp seem to support them by arguments,... (3 Replies)
Discussion started by: sea
3 Replies
LEARN ABOUT OPENSOLARIS
shells
shells(4) File Formats shells(4)NAME
shells - shell database
SYNOPSIS
/etc/shells
DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser-
shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root.
A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines
which search the file. Blank lines are also ignored.
The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/ksh93, /bin/pfcsh, /bin/pfksh, /bin/pfsh,
/bin/sh, /bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/ksh93, /usr/bin/pfcsh,
/usr/bin/pfksh, /usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh, and /usr/sfw/bin/zsh. /etc/shells overrides the default list.
Invalid shells in /etc/shells could cause unexpected behavior, such as being unable to log in by way of ftp(1).
FILES
/etc/shells list of shells on system
SEE ALSO vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4)SunOS 5.11 20 Nov 2007 shells(4)