1827279 Members
3474 Online
109717 Solutions
New Discussion

FTP scptiing question

 
SOLVED
Go to solution
Jorge Cocomess
Super Advisor

FTP scptiing question

Greetings,
I need help with renaming a file during my FTP script execution from my Linux server RHAS 3.0 to my Windows FTP server. Also, what would be the best way to pickup a long file name, such as PAAAAAPAAAAA20060307.txt and rename from PAAAAA20060307.txt to PAAAAA20060307.old after I am done with the FTP procedure?

Thanks,
J
16 REPLIES 16
Yogeeraj_1
Honored Contributor
Solution

Re: FTP scptiing question

hi J,

you can include it in script that will run after the ftp operation:

e.g.
filelist=`ls -1 *.txt`
for filen in $filelist; do
new=`echo ${filen} |sed s/txt/old/g`
mv ${filen} $new
echo renamed $filen to $new
done




hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Jorge Cocomess
Super Advisor

Re: FTP scptiing question

Thanks for your response. How do I retain the file's permission coming down from the Windows side? Seems though, the linux side stripped all the permissions. I had to manually modify the permission by chmod 666 test_file.txt

Any ideas??
Jeff_Traigle
Honored Contributor

Re: FTP scptiing question

File permissions would be controlled from the Linux side based on umask value. If you need the files to have 666 permissions when downloaded, you could put "umask 000" prior to the ftp in your script.
--
Jeff Traigle
Jorge Cocomess
Super Advisor

Re: FTP scptiing question

Per your suggestion, it doesn't work with umask 000 - Seems though it doesn't even care about the command "umask".

What am I missing here? Here's an example:

fooo01
foolprof
prompt
umask 000
lcd e:\ftpusers\temp\IN
cd /u09/data/bin/in
ascii
mput *test_file*.txt
bye
Jeff_Traigle
Honored Contributor

Re: FTP scptiing question

The umask command is outside the ftp command, not part of the commands you'll run within the ftp session. There is a umask command within ftp, but that only applies to files you are sending to the server. Something like this is what you want to do:

umask 000
ftp server << EOD
your ftp commands here
EOD
--
Jeff Traigle
Jorge Cocomess
Super Advisor

Re: FTP scptiing question

As you can tell, I am very new to Linux. Could you please spell out what does it mean to run outside of my FTP script but in the same FTP session?

Please help!

Thank you!
Jeff_Traigle
Honored Contributor

Re: FTP scptiing question

The lines I included in my previous post should be included in a script and made executable.

vi ftpscript.sh and insert the following lines:
#!/bin/sh
umask 000
your ftp command here

Make it executable:
chmod u+x ftpscript.sh

Run it.
--
Jeff Traigle
Jorge Cocomess
Super Advisor

Re: FTP scptiing question

Maybe I'm not explaining clearly what I'm trying to do.... Here go, I am trying to run my FTP script from a Windows server to a Linux server. The script is working okay with an exception of the permission issue on the Linux server. Again, the script is execute from the Windows server, not from the Linux server.

Now, what I can tell is that when I typed unmask, I can see it was set 022 by default. if I set the umask to 777 (umask 777 test_account) - this would work just fine. How do I make this umask 777 to set permanently for this account?

Thanks,
J
Yogeeraj_1
Honored Contributor

Re: FTP scptiing question

hi J,
will it be possible to do the FTP from the Linux server instead?

would be then "mget" instead of "mput"?

there may be some configuration required on the FTP server.

revert

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Jorge Cocomess
Super Advisor

Re: FTP scptiing question

yogeeraj - Yes, that's what I did recently or last night. I'm doing a pull from the Linux box and once the files are pulled down, I do a chmod to 666 and that's it. I can setup the cron to run every hour per there request.

Please let me know if I'm on the right track or not.

Thanks,
J
Jeff_Traigle
Honored Contributor

Re: FTP scptiing question

Ok. You lost me. I didn't notice you were using mput. I just read you were trying to go from the Linux server to you Windows server in the initial post.

If you want the umask for the user to be 000 (so file permissions are 666), you can add the "umask 000" to the user's .profile or .bashrc in the home directory. However, this will only affect login sessions. I think you can set the umask for the cron job in Linux's cron implementation so you wouldn't need to do the chmod in your script. Or using chmod after the ftp, as you've done, will work too.
--
Jeff Traigle
Jorge Cocomess
Super Advisor

Re: FTP scptiing question

Great! I will try out your suggestion and let you know.

Thanks,
J
Yogeeraj_1
Honored Contributor

Re: FTP scptiing question

hi again,

in fact, if you have inetd you could just configure your ftp services on your linux server such that all file uploaded gets a predetermined mode.

e.g.

ftp stream tcp nowait root /usr/lbin/ftpd ftpd -l -u 002 -a

please check.

(in my suse linux at hand,we don't have it. On hp-ux, we do have it. On redhat, we need to install the inetd package)


kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Jorge Cocomess
Super Advisor

Re: FTP scptiing question

Guess what? I do have inetd installed. Do I created an user ftp-test account, do I just remove root and replace it ftp-test?

Thanks,
J
Yogeeraj_1
Honored Contributor

Re: FTP scptiing question

hi,


thats good news :)

I have not tried it on linux.

On hp-ux, we have setup ftponly accounts.

will try to get you some notes on how it was done on hpux.

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: FTP scptiing question

hi,

can you please try this?

=============================
1. Create a bogus shell like /usr/bin/ftponly - just put a message in there in case he tries to login on server: Create a group, like "ftpgroup" and put him in it.

Example bogus shell:

#!/bin/sh
/usr/bin/cat << XX
***********************************************************************************************
* ACCESS DENIED: You may use FTP, but you may not login with this account! *
***********************************************************************************************
XX
/usr/bin/sleep 5


2. Edit (or create) /etc/shells that looks like this (make sure that it includes your bogus shell) :

/usr/bin/sh
/sbin/sh
/usr/bin/ksh
/usr/bin/csh
/usr/bin/ftponly


3. For true "restricted" ftp accounts, Edit user in /etc/passwd with vipw:

(These accounts will not have a regular shell, so they cannot telnet.)

Change the home directory entry to put the "root" level that you want this user to be able see on one side of a period (.)
The other side of the period is where he intially lands (relative to the new "root") in when he ftps to the server.

Example:

ftpuser:jo/469sTHoYRQ:105:101:ftp account,,,:/opt/apache/ftpdir/./:/usr/bin/ftponly

Do NOT forget the trailing "/" just before the separating "." between the directories above.

4. For "restricted" ftp accounts, you also need to create or edit /ftpd/ftpaccess
(See ftpaccess manpage for mind-boggling details.)

Example /etc/ftpd/ftpaccess:

class all real,guest *
guestgroup www ftpgroup
upload * * yes * * 0775 dirs

My understanding of the above:

# defines a "class" of all, real, and anything starting with guest*

# defines 2 "guestgroup" "groupnames," called "www" and "ftpgroup" --- if an ftp user is a REAL /etc/passwd account AND the user belongs to one of these groups, then their ftp session is treated just like anonymous ftp. If a user is in one of these groups they cannot cd to anything outside of their home directory, cannot change user, or password, etc.

# allow "upload" access to any directory, ownership group will be those of the ftp user, directories may be created

When you setup a user like this, the user acts just like an anonymous ftp account. So, ftpd does a chroot to the selected directory. However, no files, libraries, etc that are outside this restricted piece of the file system are available anymore to this user. So commands like ls won't work anymore. To just get ls working, you need to create a local usr/bin under the new "root" directory. Change the permissions on these dirs to 555 - owned by root. Then copy /sbin/ls into the new usr/bin and chown to root and chmod 111 on the ls executable.

5. Put ANY (restricted or not) logins that you do NOT want to ftp in /etc/ftpd/ftpusers.

Hint: use the following command to create the file (NO ONE on this list will be able to ftp):

cat /etc/passwd | awk -F: '{print $1}' > /etc/ftpd/ftpusers

Then remove those users that you DO want to ftp from ftpusers.

6, Setup the ftpd entry in inetd.conf like this:

ftp stream tcp nowait root /usr/lbin/ftpd ftpd -a

(note: ftpaccess file must exist!)

(The ftpd -a tells the daemon to access the /etc/ftpd/ftpaccess configuration file.)

7. Restart inetd like this inetd -c (works on hp-ux).


kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)