FTP - shell script question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP - shell script question
# 1  
Old 09-01-2008
FTP - shell script question

Hi All,

I had a question on something which i have trying to add to my current shell script which does FTP of files from my local machine to a remote server.

I have 5 files which i zip and FTP them on daily basis to a remote server. My script is as below:
############################
#!/bin/sh
temp="put $1"
ftp xxxx.this is IP address of remote machine.com << EOFFile
myusername
binary
$temp
quit
EOFFile
exit 0
############################

I am successfull in doing this activity.

But sometimes there is some problem with the remote FTP machine the FTP fails.

My problem is that i am only able to determine this failure after manually logging in checking for the files on remote machine.

My remote files look like this on FTP machine, all the files have the same name each day and The system date of this matches with the local machine:

08-31-08 10:00PM 55182 help1.zip
08-31-08 10:00PM 64861 help2.zip
08-31-08 10:00PM 57915 help3.zip
08-31-08 10:01PM 224245 help4.zip
08-31-08 10:01PM 2388 help5.zip


Is there a way i can add in my script or have an external script that checks for these files on FTP machine( probablly compare with local machine date stamp and FTP date stamp to determine the latest files are there).

Please suggest

Thanks,
Sandy
# 2  
Old 09-01-2008
One option shoud be ..

After copying files to remote server, just before quit the connection, give a ls and capture it in a shell variable.Then, verify the files list from the variable...

ie,

Code:
var=$(ftp xxxx.this is IP address of remote machine.com << EOFFile 
......
...
lcd
ls
quit
EOFfile
)

echo $var

# 3  
Old 09-02-2008
The ftp command is designed for interactive use.

For scripts, use the ncftp group of commands, or, if possible, use scp.
# 4  
Old 09-03-2008
Hi dennis,

#!/bin/sh
var=$(ftp www.state.il.us << EOFFile
symphems
binary
ls
quit
EOFfile
)

This gives me the required results but the results of echo $var is as below:
11:52PM 61954 help1.zip 09-02-08 10:01PM 8153 help2.zip 09-02-08 10:01PM 1890 help3.zip

The results are in a single line.

Can you please help how i can have them one fter another.

Thanks,
Sandy
# 5  
Old 09-03-2008
Quote:
Originally Posted by bsandeep_80
Hi dennis,

#!/bin/sh
var=$(ftp www.state.il.us << EOFFile
symphems
binary
ls
quit
EOFfile
)

This gives me the required results but the results of echo $var is as below:
11:52PM 61954 help1.zip 09-02-08 10:01PM 8153 help2.zip 09-02-08 10:01PM 1890 help3.zip

The results are in a single line.

Can you please help how i can have them one fter another.

Thanks,
Sandy

Assuming that you have only zip files in the location:

Code:
echo $var | sed 's/zip/zip\n/g'

or

Code:
echo $var | xargs -n4

# 6  
Old 09-03-2008
Quote:
Originally Posted by bsandeep_80
This gives me the required results but the results of echo $var is as below:
11:52PM 61954 help1.zip 09-02-08 10:01PM 8153 help2.zip 09-02-08 10:01PM 1890 help3.zip

The results are in a single line.

Can you please help how i can have them one fter another.

Quote your variables:

Code:
echo "$var"

# 7  
Old 09-09-2008
Thanks dennis

regards,
Sandy
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

repeating ftp script question

so i got this request to do this: - Script should check for the file ever 15 minutes on the FTP server…if the file is not found, then the whole script exits. File will only be created one a week at random. i have gotten this far, but am kind of stuck, also sleep command doesnt work... (3 Replies)
Discussion started by: zapatur23
3 Replies

2. Shell Programming and Scripting

FTP within a SHELL script

I am running the following on linux (on a mac): filename="/Users/thisfilename.txt" hostname="ftp.mysite.com" username="myusername" password="mypassword" echo '=======FTP========' ftp -un $hostname <<EOF quote USER $username quote PASS $password binary put $filename quit EOF I... (4 Replies)
Discussion started by: globalnerds
4 Replies

3. UNIX for Dummies Questions & Answers

FTP shell script

Hi I am new in UNIX field. I don't know if I am posting in right forum or not. And I have also found out that there are so many posts about ftp shell scripting. I have tried those but actually having some problem. Well, my script should do the following..... It finds files( the filename ended... (3 Replies)
Discussion started by: abhishek_510
3 Replies

4. Shell Programming and Scripting

Use ftp is a shell script

Hi, What i would like to do is to use a shell script connect to a remote computer and download files from a specific directory. I wrote the following script. #!/bin/sh HOST='IP' USER='yourid' PASSWD='yourpw' FILE='*.txt' REMOTEPATH=/incoming/MSC/ ftp $HOST <<END_SCRIPT user $USER... (3 Replies)
Discussion started by: chriss_58
3 Replies

5. Shell Programming and Scripting

FTP using shell script

Hi All, I want to make a ftp call using a separate file where the ftp commands will reside. Please find below the details: I have 2 files Sample1.sh and Properties Properties --------- <username> <password> .... other ftp commands Sample1.sh ---------- ftp -v <servername> <... (1 Reply)
Discussion started by: pickpeters
1 Replies

6. UNIX for Advanced & Expert Users

FTP in shell script

HI ALL i am writing a shell script in which i have to use FTP command like. FTP <ip address> cd xyz mget* bye but i am not able to perform any command from shell script. once the control goes to FTP, i again have to type all the things. i just want my shell script to take care of the... (8 Replies)
Discussion started by: infyanurag
8 Replies

7. Shell Programming and Scripting

ftp with shell script

Can I ftp to put file with shell script(as bath file) ? Plz give the simple code to do that. My script look like that #!/bin/sh echo "Start ftp" ftp temphost <<EOF put file quit EOF # end This code ignore username & password but I need to input. How to input username &... (8 Replies)
Discussion started by: aungomarin
8 Replies

8. UNIX for Dummies Questions & Answers

Shell script for ftp

Hi ,, I am wrting a shell script to ftp a file from remote server but its giving some problem to me.can you help me in debugging this. #!/usr/bin/ksh HOST="some ip" user="user_name" passwd="password" ftp -n $HOST >>END_SCRIPT USER $user $passwd binary prompt get... (3 Replies)
Discussion started by: namishtiwari
3 Replies

9. Shell Programming and Scripting

using ftp in a shell script.

I am trying to ftp some files from a certain directory, but i got an invalid command. does anybody know why i got this error? ftp -v -i -n <<SCRIPT open servername user username password cd /server/logs for file in MCWAS* do put ${file} /home/test/${file} done bye SCRIPT (2 Replies)
Discussion started by: caesarkim
2 Replies

10. Shell Programming and Scripting

Not the usual ftp script question

I have an order file that gets updated periodically on a ftp server. The file format is "number one-day of the quarter-file number". For example, the format would look like this for today and would increment as such. 1-26-1 1-26-2 1-26-3 etc After I grab each oder file, I will rename... (9 Replies)
Discussion started by: cstovall
9 Replies
Login or Register to Ask a Question