usage of if command in ftp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting usage of if command in ftp
# 1  
Old 12-14-2011
usage of if command in ftp

Hi ,

I am writing script to copy some files and folders . I am trying to use if command to check if folder exists and then copy in that folder but if command is not working:
Code:
if [ -z sequences ]
then
     lcd $home_directory/sequences
     cd sequences
     mput *
 else
  echo "Not a Directory"
 fi

I have done ftp in script... but when i am trying to run script and if command is not checking for directory...

Moderator's Comments:
Mod Comment Please use

code tags!

Follow the above link to see how...

Last edited by vbe; 12-14-2011 at 11:26 AM.. Reason: code tags keep the formatting you done also...
# 2  
Old 12-14-2011
If it was a shell, -z isn't what you'd use to test for a directory -- that's -d.

But ftp is not a shell. ftp can't do this. ftp is very simple and stupid and limited in what it can do.

You could use the expect language to monitor ftp's responses to commands and answer appropriately.
# 3  
Old 12-14-2011
ftp does not offer flow control. You might want to write the if-part etc. as shell script and including the ftp-part as "here"-script. If possible in your environment maybe use scp instead anyway.
# 4  
Old 12-14-2011
thanks for your reply. Is there any work around for this?
I mean during ftp can i check for directory somehow?
# 5  
Old 12-14-2011
Already described 2 possible workarounds (shell + ftp, or shell + ssh/scp). You can check but for that you would have to parse the output of your ftp commands each with shell commands to decide what you're gonna do.

Last edited by zaxxon; 12-14-2011 at 11:39 AM.. Reason: spelling
# 6  
Old 12-14-2011
Quote:
Originally Posted by ankush_mehra
thanks for your reply. Is there any work around for this?
I mean during ftp can i check for directory somehow?
Quote:
Originally Posted by Corona688
FTP is not a shell. ftp can't do this. ftp is very simple and stupid and limited in what it can do.
You'll have to either process ftp's output, or do it outside FTP.

Do you have SSH access? You could do this:

Code:
tar -C $home_directory/sequences -cf - . |
        ssh username@host [ -d sequences ] '&&' tar -C sequences -xvf -

On the local side, it creates a tape archive with tar and attempts to stream it to the remote side. On the remote side, it checks if 'sequences' exists and, only if it does, runs tar to extract the stream it's reading over ssh. On both ends, -C is used to tell tar to change directory before creating/extracting the archive.

The -v should tell the remote side to print filenames as they're extracted. Remove the v if you don't want that.

Last edited by Corona688; 12-14-2011 at 11:39 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Usage of '.' in MV command

Hi, Could you please let me know, why we should not use '.' in move command, if we use it, is it something wrong.. Please share the details on it. /home/rahualux/emp.csv /home/rahualux/details/employee_files/. Or other example for mutlipile files /home/rahualux/*.csv... (3 Replies)
Discussion started by: rahualux
3 Replies

2. Shell Programming and Scripting

cp -v command usage?

I am trying to output a log file from cp usage. I think this can be achieved. In my code I have this. cp -i -v ~/files/* ~/backups/oldfiles/;; > ~/logs/logfile.logThe error I get is "syntax error near unexpected token '>' What am I missing? (7 Replies)
Discussion started by: gameinn
7 Replies

3. UNIX for Dummies Questions & Answers

FTP command-line utility usage

Hi, Using command-line utility "ftp or sftp", I want to transfer files across Windows and UNIX. Can you please tell me from where I need to connect to ftp and how do I specify the hostname, credentials and how do I get and put files between DOS and UNIX? Please provide me as much... (10 Replies)
Discussion started by: Dev_Dev
10 Replies

4. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

5. UNIX for Dummies Questions & Answers

Mail/ftp/web servers, on VIRTUAL!! dedicated server. Also resource usage. Centos 5.

Hi. First of all, would 4 or 5 websites, 1 ftp server (when downloading by someone or a few persons or one, concretize) and one mail server (not many emails, just to sound official and have a nice, spam-free email for myself). Websites with not that many, but some, later more visitors, quite... (0 Replies)
Discussion started by: newn
0 Replies

6. Shell Programming and Scripting

Various usage of FTP in Unix

My project is to write a script to get/put data to another server, be able to log input and output files, have some sort of security for the password, and any errors connecting send a email to a group of people. I've seen examples of perl, java being called by Unix scripts, etc. I've even seen... (1 Reply)
Discussion started by: gavineq
1 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

9. AIX

Prevent ftp usage

Is there a way to prevent users to use ftp on my server? And only allow root to use ftp. Thanx (1 Reply)
Discussion started by: NineInch
1 Replies

10. Programming

usage of ftp in C program

thank you of your help my application system is : windows 2000 pc --- HP unix minicom ---- windows NT I am programming with C language on HP unix minicom , I want to get files with ftp command from windows 2000 pc to HP unix minicom in my program, and also put files with ftp command... (1 Reply)
Discussion started by: bdyjm
1 Replies
Login or Register to Ask a Question