1827791 Members
2544 Online
109969 Solutions
New Discussion

Re: Need ftp script

 
Vishal_1980
Regular Advisor

Need script

Hello experts--

 

I require one script for file copying from local server to FTP.

 

Thanks ,

 

Vishal

29 REPLIES 29
Vishal_1980
Regular Advisor

Re: Need ftp script

Hello : i will explain the scenario,

 

Pls check attacment & suggest me.

Hope some will provide me the solution ,as i am new to scripting.

 

 

Thanks in advance

 

Dennis Handly
Acclaimed Contributor

Re: Need ftp script

Any reason you provided an Excel file?  Is this how you need to get your script input of is this just how you wanted to present your requirements?  (Here a text file is better.)

 

If this is a one time thing, you can just code these values in a script.  Or copy the script and change them.

Or you can pass them as parms to the script.

 

#!/usr/bin/ksh

 

# ftp files from SRC_PATH/SRC to TGT on SERVER.  Using USER & PASS

 

SRC_PATH=/usr/sap/RAV/SYS/global/ftp/RMPA

src="RAV_INFO_20*"

TGT=/

SERVER=10.10.10.31

USER=dewqv

PASS="password"

 

ftp -inv $SERVER <<EOF
user $USER $PASS

bin

lcd $SRC_PATH

cd $TGT
mput $src
bye

EOF

Vishal_1980
Regular Advisor

Re: Need ftp script

Thanks a lot sir.....& sorry for puting the excel ...next time i will remember this definately..

However what if i want multiple file to be transfered from HP-UX to windows box.

As this is for the same purpose.We need to transfer few files more than six files from HP-UX to windows bos.

Please suggest me furthere & once again thanks for the guidence.

 

Regards,

Vishal

Vishal_1980
Regular Advisor

Re: Need ftp script

Dear sir..

 

I creates the script & run on the test server ....i below is the output ..

 

 

# ./ftpcptest
Connected to 10.10.10.31.
220-FileZilla Server version 0.9.41 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/
Remote system type is UNIX.
331 Password required for dewqv
230 Logged on
200 Type set to I
Local directory now /sapmnt/RAV/global/ftp/RMPA
250 CWD successful. "/" is current directory.
(local-files) local: bye remote: bye
bye: No such file or directory
221 Goodbye
#

 

Please suggest .....

 

Thanks

Vishal

Vishal_1980
Regular Advisor

Re: Need ftp script

Dear sir ,

 

i need to move the below mention file

 

 

# pwd
/usr/sap/RAV/SYS/global/ftp/RMPA
# ll
total 12
-rw-rw----   1 rdvadm     sapsys         146 May 27 15:04 RAV_INFO_20140527_001.PSV
-rw-rw----   1 rdvadm     sapsys        2692 May 27 15:02 RAV_MM_20140527_001.PSV
-rw-rw----   1 rdvadm     sapsys          92 May 27 15:03 RAV_VM_20140527_001.PSV

 

thanks ,

Vishal

Dennis Handly
Acclaimed Contributor

Re: Need ftp script

>I need to move the below mentioned file: RAV_INFO_20140527_001.PSV

 

I assume you only wanted this one?

 

It appears that the forum changed my "src=" to lower case.  It tried to edit it several times and each time it did it again.

So I changed both to "src".

Vishal_1980
Regular Advisor

Re: Need ftp script

Yes sir..i got that & made the changes now it is successfull.......attached is the output

 

therefore i need to move 6 files at a time (all are different name) what changes i need to do in the script pls suggest...

 

 

Thanks ,

 

Vishal

 

Dennis Handly
Acclaimed Contributor

Re: Need ftp script

>made the changes now it is successful. attached is the output

 

(If you are happy with the answers, please click on the kudos star for each helpful answer.)

 

If you don't want so much output, you can remove that "v" in -inv.

Also, this script doesn't really catch errors too well.

 

>therefore i need to move 6 files at a time (all are different name)

 

Do you have a file matching pattern that will do all 6?

Otherwise you can just include all of them in:

src="file1 file2"

Vishal_1980
Regular Advisor

Re: Need ftp script

Hello sir, yes i made the changes.However i want to cut paste the files.The requirement is when the files get generated on source it will be cut from their & paste to the destination.
Please suggest...

Thanks & have a great day ahead.
Regards,
Vishal
Dennis Handly
Acclaimed Contributor

Re: Need ftp script

>i want to cut paste the files.

 

(Files don't get cut & pasted, they get copied and then removed.  :-)

 

After the mput you can simply do:

!rm -f $src

 

But since there is no checking for any errors, this may be dangerous.

Vishal_1980
Regular Advisor

Re: Need ftp script

Thanks a lot sir....yes i am discussing the same with my team & we come to the same conclusion.So how could we do the error checking.Please suggest further.
Vishal_1980
Regular Advisor

Re: Need ftp script

Will you please guide me: i want to scheduled the program for every 15 min in a day ,for the week & year as well


Thanks in advance .....
Vishal_1980
Regular Advisor

Re: Need ftp script

I am scheduling by the bellow values:

*/15,*,*,* * * * * /usr/sap/RDV/SYS/global/ftp/RMPA/ftpcptest.sh
Dennis Handly
Acclaimed Contributor

Re: Need ftp script

Dennis Handly
Acclaimed Contributor

Re: Need ftp script

>for every 15 min in a day, for the week & year

>*/15,*,*,* * * * * /usr/sap/RDV/SYS/global/ftp/RMPA/ftpcptest.sh

 

This is the linux way of doing things.  For HP-UX, you need:

0,15,30,45 * * * * /usr/sap/RDV/SYS/global/ftp/RMPA/ftpcptest.sh

Vishal_1980
Regular Advisor

Re: Need ftp script

Hello Dennis sir,

I am getting the mail as below.Also there is nothing found in the cron log.
Date: Tue, 10 Jun 2014 09:30:00 +0530 (IST)
From: root@eccdevvg.infodartsap.com
Message-Id: <201406100400.s5A400n3005435@eccdevvg.infodartsap.com>
Subject: cron

sh: /usr/sap/RDV/SYS/global/ftp/RMPA/ftpcptest.sh: not found.


*************************************************
Cron: The previous message is the standard output
and standard error of one of your crontab commands:

/usr/sap/RDV/SYS/global/ftp/RMPA/ftpcptest.sh

Please suggest me on this.

Thanks & regards,
Vishal
Dennis Handly
Acclaimed Contributor

Re: Need ftp script

>sh: /usr/sap/RDV/SYS/global/ftp/RMPA/ftpcptest.sh: not found.

 

Well, is that the path to your script?

Vishal_1980
Regular Advisor

Re: Need ftp script

Yes sir ,the path is same.However i have to manually execute the script.

Thanks ,
VIshal
Dennis Handly
Acclaimed Contributor

Re: Need ftp script

>I have to manually execute the script.

 

Did you make the script executable?  chmod a+x /usr/sap/RDV/SYS/global/ftp/RMPA/ftpcptest.sh

Vishal_1980
Regular Advisor

Re: Need ftp script

Yes Dennis sir ,

I made the script executable.
Vishal_1980
Regular Advisor

Re: Need ftp script

This is the output :
# ll
total 2
-rwxrwxrwx 1 root sys 391 Jun 10 10:35 ftpcptest
Dennis Handly
Acclaimed Contributor

Re: Need ftp script

-rwxrwxrwx 1 root sys 391 Jun 10 10:35 ftpcptest

 

You should NOT make the file writable by everyone nor by group:

chmod go-w ftpcptest

 

If this is local and you're root, this should work, unless you have some unprintable chars in the crontab.

Use vis(1) to check:

crontab -l | vis

Vishal_1980
Regular Advisor

Re: Need ftp script

Hello SIr,

 

The script works good, however when the file is transfer through script the format is different.

And when it is ftp through SAP ftp application the format is different.My customer wants the same format as SAP ftp application.

 

Attaching both the files ,request you to please suggest on this.