Using conditions in FTP

Thread Tools Search this Thread
Operating Systems AIX Using conditions in FTP
# 1  
Old 06-08-2011
Data Using conditions in FTP

I'm running a ftp script which will ftp a file xxx.dat from abcd to wxyz

In that I want to check if the file already exists or not,
1. if yes, append the current file to old file
2. else, put the file

Code I tried:

user ijkl password
cd /home/yyy
site [[ -s xxx.dat ]] && append xxx.dat xxx.dat
site [[ ! -s xxx.dat ]] && put xxx.dat xxx.dat

could you please help me on this?

Note : xxx.dat will be created every one hour, also I can't do FTP from wxyz.
# 2  
Old 06-08-2011
You would probably be better off putting the file into /home/xxx with a different file name every time, and running a (cron) script on wxyz that decides whether to move the file to yyy, or append it to an existing file in yyy.
The script should check to see if any process is using either file before doing the move/append, that is make sure that the file transfer is complete, and that the file in yyy is not being processed.
# 3  
Old 06-08-2011
FTP is not a shell. It can't do logical expressions.
# 4  
Old 06-08-2011
You could try something like this (untested):


use warnings;
use strict;
use Net::FTP;

my ($host, $user, $pass) = qw(<host> <user> <pass>);

my $_file = 'xxx.dat';

my $ftp = Net::FTP->new($host, Debug => 0, Timeout => 240)
  or die "Cannot connect to $host: $@\n";

$ftp->login($user, $pass)
  or die "Cannot login ", $ftp->message;

eval {

$@ ? $ftp->put($_file) : $ftp->append($_file, $_file);

  or die 'Failed to disconnect ', $ftp->message;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conditions in if

I'm using the below one.. #!/bin/ksh File=$3 if ; then echo "Script" elif ] ;then echo "Passed k or f option" else "Please check the Input passed" fi Command line argument is "k" or -f and file is exist then... (3 Replies)
Discussion started by: Roozo
3 Replies

2. Shell Programming and Scripting

Errors in if conditions with to many OR conditions

Hi ALL I have a script where in i need to check for several values in if conditons but when i execute the script it throws error such as "TOO MANY ARGUMENTS" if then msg="BM VAR Issue :: bmaRequestVAR=$bmaRequestVAR , nltBMVAR=$nltBMVAR , bmaResponseVAR=$bmaResponseVAR ,... (10 Replies)
Discussion started by: nikhil jain
10 Replies

3. Shell Programming and Scripting

If conditions need

Dear Expert, Below code is for to take the backup of database by daily time stamp. I need vital help to make my script automatic sending me email if it sucess or fail. echo on @REM Seamonkey's quick date batch (MMDDYYYY format) @REM Setups %date variable @REM First parses month, day, and... (6 Replies)
Discussion started by: Alone
6 Replies

4. Shell Programming and Scripting

Conditions in 'for' Loop

Hey guys, I've been learning shell for a few weeks now & come across an issue in one of my for loops : However I wish to add a condition (maybe if loop is best ??) when, if the variable value $line is > 24 go back to the start of my 'for' loop thus skipping my application based commands and... (3 Replies)
Discussion started by: phil0316
3 Replies

5. Shell Programming and Scripting

FTP GET with exception handeling and multiple conditions

Thanks everyone for the wonderful and helping environment.. And the problem I asked.. forget it... 4 days wait for a decent reply was such a moral booster.. (3 Replies)
Discussion started by: ReignOfChaos
3 Replies

6. Shell Programming and Scripting

IF OR with two conditions

I have this IF working fine, testing if a char is a digit: if ; then _VALUE=$_VALUE$_CHAR else _ISDIGIT="false" fi Then I add a second condition to test if the char is either a digit or a * if ]; then _VALUE=$_VALUE$_CHAR ... (11 Replies)
Discussion started by: Flavius
11 Replies

7. Shell Programming and Scripting

While with three conditions

Currently this is what I am trying while || && ]; do I want to continue if the first condition or both the second and third are true but I am getting a too many arguments error. Can someone help me out? (5 Replies)
Discussion started by: whdr02
5 Replies

8. Shell Programming and Scripting


./script 89 The script will extract the last digit of the input parameter. example, that is 4. This will be compared to the last digit of the current day of the month ( like day 14; that is 4). A message will displayed on the screen indicating if the digits are the same or not. (1 Reply)
Discussion started by: singh is king
1 Replies

9. UNIX for Dummies Questions & Answers

2 or more if conditions

Hello, I have a file as follows: col no:1 2 3 4 5 6 7 8 9 10 11 a 4 226 226 ch:95024048-95027592, 1y224 of 3545 223 224 ident b 53 235 235 ch:148398-148401255, 1y184 of 3187 180 186 ident awk... (3 Replies)
Discussion started by: dr_sabz
3 Replies

10. Shell Programming and Scripting

reduce the or conditions

Hi , how can i reduce the or conditions: if ]; then whatever fi (8 Replies)
Discussion started by: hitmansilentass
8 Replies
Login or Register to Ask a Question