in reply to Re^2: SFTP and the Pointy-Haired manager
in thread SFTP and the Pointy-Haired manager
#--------------------------------------------------------------------- +---------------------------------------- # Routine: DoSFTPCommands # Description: This routine will take an array of FTP commands and ex +ecute them using SFTP. # # Input: # aCmdList - Array of FTP commands like: # "chdir /data/reports" # "rm weekly_rpt_*.csv" # "put /new/reports/weekly_rpt_2004_07_01.csv" #--------------------------------------------------------------------- +---------------------------------------- sub DoSFTPCommands { my (@aCmdList) = @_; # Put the FTP commands into a file so we can pass the file name to + the SFTP program open (CMD_FILE, ">ftp.cmd"); foreach (@aCmdList) { print CMD_FILE "$_\n"; } close CMD_FILE; # Create a Expect script to run SFTP my $lCmd = '#!/usr/bin/expect spawn sftp -b ftp.cmd MyAccount@ftp.myCompany.com expect -exact " password: " send "myPassword"; interact '; open (EXP_FILE, ">auto.exp"); print EXP_FILE "$lCmd"; close EXP_FILE; # Make the script runable system ("chmod +x auto.exp"); # Run the script system ("./auto.exp"); # Clean up by deleting the two files we created unlink ("ftp.cmd"); unlink ("auto.exp"); } # DoSFTPCommands
|
|---|