1836304 Members
1986 Online
110099 Solutions
New Discussion

Transfer problem

 
haeman
Frequent Advisor

Transfer problem

To ensure the file can be transferred to remote server , I try to write a script to do transfer file from local server ( directory: dir1 ) to remote server ( directory: dir1 ) , then get the files back from remote server ( directory: dir1 ) to local server ( directory: dir2 ), then compare the files in local server ( directory: dir1 & dir2 ) , if found any files missing , then send me alert .

I have below script to do it , when run it , the file could be transfer to remote server , but can't get it back , it pops "Failed to open file." , it seems can't find the file in remote server , can advise what is the problem ? thx




ftp remote_server<prompt off
lcd dir1
passive
cd dir1
put *
lcd dir2
get *
EOF
20 REPLIES 20
Kenan Erdey
Honored Contributor

Re: Transfer problem

hi,

try mget and mput.

Kenan.
Computers have lots of memory but no imagination
haeman
Frequent Advisor

Re: Transfer problem

thx Kenan Erdey ,

you are right , it works now , I have a few more questions ,

1. it could get back the file to dir2 now , can advise how to compare the files in dir1 and dir2 , if found any file difference , then send me mail ?

2. do you think is it a good way to check the file transfer successful or not ? thx
Kenan Erdey
Honored Contributor

Re: Transfer problem

Hi,

have a look at diff command. you can write a script using it and mailx command. diff can also compare files so if there has been a problem because of transfer, you'll be aware of it.



Computers have lots of memory but no imagination
haeman
Frequent Advisor

Re: Transfer problem

thx kenan ,

diff is file content comparsion , as this is binary file , I think compare the file existence will do , if any files is not exist in dir2 , then send me alert , can advise how to do it ? thx
haeman
Frequent Advisor

Re: Transfer problem

thx reply ,

could advise what can i do ? thx
Steven Schweda
Honored Contributor

Re: Transfer problem

> diff is file content comparsion , as this
> is binary file , I think compare the file
> existence will do [...]

Why would you think this? Are non-text files
somehow more robust than text files?

> 2. do you think is it a good way to check
> the file transfer successful or not ?

If the FTP server says "2xy", I'd probably
relax and be happy. Or, I'd package the
files using a program like Info-ZIP Zip,
which includes some data integrity info, so
that UnZip will complain if the archive is
corrupt.

The best solution depends on details of the
requirements which you have not supplied.

> could advise what can i do ?

More than you've already been advised? Not
really, not for free. A forum search for
"mailx" should find some scripts which send
e-mail, if that part is still a mystery.
Steven Schweda
Honored Contributor

Re: Transfer problem

haeman
Frequent Advisor

Re: Transfer problem

thx replies,

I wrote it already , but still have problem ,

1. after get back the files , I want to remove all files on remote site , I tried to use del file_name is OK to remove the file , but if I want to remove all files in dir1 on remote site , what can i do ?

2. use diff will compare the file includes file and sub-directory , how can i only compare files ? thx
Steven Schweda
Honored Contributor

Re: Transfer problem

> [...] but still have problem [...]

Yes, and your main problem seems to be that
you haven't read "man ftp" or "man diff".

> [...] if I want to remove all files [...]

"man ftp". Remember "mget" and "mput"? Try
"mdelete"?

> [...] diff will compare the file includes
> file and sub-directory [...]

"man diff". As usual, it would help if you
showed the actual command you used, as
different commands can behave differently.

"diff -r" compares directories recursively.
"diff" without "-r" compares two directories
or two files, doesn't it?
haeman
Frequent Advisor

Re: Transfer problem

thx reply

I tried mdelete , it is OK to remove the file in remote site , but still show the below message after run it , can advise what is wrong ? thx

Delete operation failed.
haeman
Frequent Advisor

Re: Transfer problem

I have one more question ,

I edited this ftp script , it can put and get the files well ,if I want to add a comparsion script (eg. comparsion_script) to this ftp script , can advise what can i do ? Thx

ftp remote_server<prompt off
lcd dir1
passive
cd dir1
put *
lcd dir2
get *
mdelete *
comparsion_script
EOF
haeman
Frequent Advisor

Re: Transfer problem

thx reply ,

what I want is after mdelete the file , then run the comparsion script , if I just add the script name to the ftp script , it will pop "?Invalid command" , can advise what can i do ?ã ï½ ï½ ï½
Dennis Handly
Acclaimed Contributor

Re: Transfer problem

>but still show the below message after run it, can advise what is wrong?

You may not have permission to remove files on the remote system. Can you manually use "del" on a single file? Can you manually use "mdel" on another single file?
What does "ls -d ." show?
Dennis Handly
Acclaimed Contributor

Re: Transfer problem

>then run the comparison script

To run a script you must exit ftp.
haeman
Frequent Advisor

Re: Transfer problem

thx dennis,

To run a script you must exit ftp.

if exit ( bye ), how to run its next script ? thx
Dennis Handly
Acclaimed Contributor

Re: Transfer problem

>how to run its next script?

Your current script has:
ftp remote_server<...
mdelete *
EOF

You either invoke your "comparsion_script" here or put the compare commands inline.
Steven Schweda
Honored Contributor

Re: Transfer problem

> I tried mdelete , it is OK to remove the
> file in remote site , but still show the
> below message after run it , can advise
> what is wrong ? [...]

Not without some useful information.

> To run a script you must exit ftp.

Not really. It might help if you would read
"man ftp", but I'm beginning to doubt it.

[...]
COMMANDS
[...]
![command [args]]
Invoke a shell on the local host. [...]

Have you considered hiring someone who can do
your job for you?
Dennis Handly
Acclaimed Contributor

Re: Transfer problem

>> To run a script you must exit ftp.

>Not really

Oops, right. But ! would be next to useless at the end of ftp, when you can just exit back to the shell.
And just about the only commands I use are !pwd and !ls. Otherwise when interactive I use control-Z and use a real shell.
Chris Vail
Honored Contributor

Re: Transfer problem

This is NOT a good idea! You need to get all thoughts of ftp out of your mind, and use the secure shell equivalent, scp. This command scripts much more easily, it is secure and does not send passwords unencrypted as ftp does.

Rather than comparing the files before and after the transfer, use the sum command to get a checksum.

CSUM1=`sum $FILE|awk '{ print $1 }'`
scp $FILE $DESTHOST:/$DESTDIR
CSUM2=`ssh $DESTHOST sum $DESTDIR/$FILE|awk '{ print $1 }'`

if test "$CSUM1" -ne "$CSUM2"
then
echo "There is a problem with the file transfer."
fi

If you have not yet installed or configured ssh on your systems, I have previously posted instructions on how to to do this.

Chris
Dennis Handly
Acclaimed Contributor

Re: Transfer problem

>Chris: use the sum command to get a checksum.

sum(1) says: sum is obsolescent ...
So you should use cksum instead.