Sponsored Content
Full Discussion: FTP Script Help!!
Top Forums Shell Programming and Scripting FTP Script Help!! Post 302923992 by Chubler_XL on Wednesday 5th of November 2014 03:02:44 PM
Old 11-05-2014
I have seen some scripts that put the file over with a temporary name then rename. This also protects from jobs on the destination server attempting to process file still in transit.

Once the remote rename is done the file can then be moved to a transfered folder, for eaxample:

Code:
put ORD049382.20141106 tmp_transfer
rename tmp_transfer ORD49382.20141106
!mv ORD049382.20141106 tmp /var/orders/transfered/


Here is an attempt at putting Don Cragun's suggestions and this change all together for you:

Code:
#!/bin/bash
source /opt/foobar/$1/config/usrconfig.sh
source  /opt/foobar/$ENV/config/$2

### foobar environment variables ###
export FTPHOST="sftpserv.foobar.com"                 # server to ftp to
export FTPUSR="usmssh"                               # ftp user id
export FTPPASS=""                                    # ftp user password
export PATTERN=                                      # pattern for file name to ftp
export USING_MARKER=no                               # using a marker file???
#export TDEMARKER="X"                                # pattern for marker file if no files to ftp
export FTPDIR="prod/TDE/in/"  # directory to ftp to on ftp server
export DAEMONLOG=/opt/foobar/$ENV/log/TDEdeamon.log
export DAEMONSLEEP=10
export CURRDATE=`date +%Y%m%d`
export READDIR=/opt/foobar/$ENV/data/TDE/output
export TEMP=/opt/foobar/$ENV/tmp
export TDE_BACKUP=$APP_ROOT/data/TDE/backup/

if [ ! -d "$READDIR" ]
then
    echo "Directory $READDIR not found!" >>$DAEMONLOG 2>&1
    exit 1
fi

cd $READDIR
sleep 2

> tde_batch
find $READDIR -type f -name '*.ready' | while read file
do
  real_file="${file%.ready}"
  echo "put \"$real_file\" \"$FTPDIR/trans.temp\"" >> tde_batch
  echo "rename \"$FTPDIR/trans.temp\" \"$FTPDIR/$real_file\"" >> tde_batch
  echo "!mv \"$real_file\" \"$TDE_BACKUP/\"" >> tde_batch
done

if [ ! -s ./tde_batch ]
then
     echo "No ready files found in $READDIR" >>$DAEMONLOG 2>&1
     exit 2
fi

echo "quit" >> tde_batch
sftp -b tde_batch "$FTPUSR@$FTPHOST" >>$DAEMONLOG 2>&1
mv tde_batch "$TDE_BACKUP/tde_batch.$CURRDATE"
exit 0

This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

FTP script in Unix shell script

Hello , I am trying to make a shell script (Unix) for a ftp connection to another server and to get a file. So I have no knowledge about ftp and my script must do automaticly the connection with the user and passwd. Can you help us about that... Christian... (2 Replies)
Discussion started by: steiner
2 Replies

2. UNIX for Dummies Questions & Answers

excuting a shell script within ftp script

Novice here... I need help with excuting a shell script on a flat file that I've transfered over from a Windows XP machine for manipulation through an auto FTP script... so that after it is transfers it excutes the shell script and then returns it back to XP machine... Any ideas... (2 Replies)
Discussion started by: Gerry405
2 Replies

3. Shell Programming and Scripting

Need help - script for ftp..

I have my ftp script as below.. This is logging the messages into ftp.log file , But I want the same output(what ever messages are going into ftp.log) to be printed on the console too for the user to show the status.. Tried with "tee" .. unable to get the solution.. Can some one help me... (3 Replies)
Discussion started by: Srini75
3 Replies

4. Shell Programming and Scripting

FTP script to FTP file to UNIX - Solaris

Hello, A couple of times per week, i receive emails notifications when files are available for processing. Currently i read these eamails with a java program and store the attachement on my C: drive and would now like to generate a PC script to send this file name up to UNIX-Solaris and... (3 Replies)
Discussion started by: bobk544
3 Replies

5. Shell Programming and Scripting

ftp script not able to connect to ftp server.

I have the following ftp script to get files from a remote location. However, on running the script I find that I am not even able to connect to ftp server. I am able to connect to ftp server using other GUI ftp tools like WS_FTP using the same IP. IP used here is a dummy IP. What can go... (3 Replies)
Discussion started by: gram77
3 Replies

6. Shell Programming and Scripting

passing parameter to ftp script from output of another ftp

Hi, I have a ftp script which first gets all the file names and echo's the latest file. I'm using another ftp command sets to get the file name given by first ftp. The problem is the parameter is not accepted by second ftp. The error message i'm getting is > Rename Temp File calloc:ICMP... (5 Replies)
Discussion started by: ammu
5 Replies

7. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

8. Linux

Need SCP script equivalent to FTP script .

Hi, Currently i'm using the folllowing FTP acript and its working. echo "open $server" > ftp_file echo "user $user $password" >> ftp_file echo "cd $remote_dir" >> ftp_file echo "lcd $local_dir" >> ftp_file echo "put $file">> ftp_file echo "bye" >> ftp_file ftp -nv < ftp_file I've... (1 Reply)
Discussion started by: vickramshetty
1 Replies

9. Shell Programming and Scripting

Need help in ftp script

hello , I am working on a FTP script which navigates to specific directory and pulls the file Issue which i am facing :: ---------------------------- i) When there is a file it pulls the file , but when there is not file in the directory it fails in the same statement and it is not... (3 Replies)
Discussion started by: ranga27
3 Replies

10. Shell Programming and Scripting

configuration for ftp script in main script

Hi, I am new to shell scripting,and i was planning to write a script that will FTP files to destination folder. I was planning that All configuration should be done through a properties files. and finally the output should be Files are transferred I have developed a properties file named... (4 Replies)
Discussion started by: rahul125
4 Replies
FTPFS(4)						     Kernel Interfaces Manual							  FTPFS(4)

NAME
ftpfs - file transfer protocol (FTP) file system SYNOPSIS
ftpfs [ -/dq ] [ -m mountpoint ] [ -a password ] system DESCRIPTION
Ftpfs dials the TCP file transfer protocol (FTP) port, 21, on system and mounts itself (see bind(2)) on mountpoint (default /n/ftp) to pro- vide access to files on the remote machine. If required by the remote machine, ftpfs will prompt for a user name and password. The user names ftp and anonymous conventionally offer guest/read-only access to machines. Anonymous FTP may be called without user interaction by using the -a option and specifying the password. By default the file seen at the mount point is the user's remote home directory. The option -/ forces the mount point to correspond to the remote root. To avoid seeing startup messages from the server use option -q. To see all messages from the server use option -d. To terminate the connection, unmount (see bind(1)) the mount point. EXAMPLE
You want anonymous FTP access to the system export.lcs.mit.edu. The first import(4) command is only necessary if your machine does not have access to the desired system, but another, called gateway in this example, does. import gateway /net ftpfs -a yourname@yourmachine export.lcs.mit.edu SOURCE
/sys/src/cmd/ftpfs SEE ALSO
bind(2) BUGS
Symbolic links on remote Unix systems will always have mode 0777 and a length of 8. After connecting to a TOPS-20 system, the mount point will contain only one directory, usually /n/ftp/PS:<ANONYMOUS>. However, walking to any valid directory on that machine will succeed and cause that directory entry to appear under the mount point. Ftpfs caches files and directories. A directory will fall from the cache after 5 quiescent minutes or if the local user changes the direc- tory by writing or removing a file. Otherwise, remote changes to the directory that occur after the directory has been cached might not be immediately visible. There is no way to issue the appropriate commands to handle special synthetic FTP file types such as directories that automatically return a tar of their contents. FTPFS(4)
All times are GMT -4. The time now is 08:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy