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
close
quit

could you please help me on this?

Note : xxx.dat will be created every one hour, also I can't do FTP from wxyz.

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.

FTP is not a shell. It can't do logical expressions.

You could try something like this (untested):

#!/usr/bin/perl

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->size($_file)
   };

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

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