change the mode of the file after FTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change the mode of the file after FTP
# 1  
Old 04-01-2010
change the mode of the file after FTP

Hi
I am FTPing a file to a remote server from my local server. But after I FTP it the permissions are not in executable option, I need to change the permissions of the FTPed file how can i do that. Below is my script

Code:
LOCALDIR=/batch/ediprocess
LOCAL_BACKUP_DIR/batch/ediprocessBackUp
FTPCMDFILE=//batch/cmdftp.cmd
APP_SCRIPT_DIR=/batch
FTPLOGFILE=/batch/ftpTest.log
REMOTESERVER=test.appl.com
REMOTE_DIR=/batch/ftpTest
REMOTE_USER=hello
REMOTE_PWD=abcd
chmod 777 $LOCALDIR/*.csv
echo "user $REMOTE_USER $REMOTE_PWD"   > $FTPCMDFILE
echo "cd $REMOTE_DIR"             >> $FTPCMDFILE
echo  "lcd $LOCALDIR"              >> $FTPCMDFILE
echo "chmod 777 $LOCALDIR/*.csv"   >> $FTPCMDFILE
echo "bin"                          >> $FTPCMDFILE
echo "mput *.csv"               >> $FTPCMDFILE
echo "lcd $APP_SCRIPT_DIR"            >> $FTPCMDFILE
echo "chmod 777 $REMOTE_DIR/*.csv"  >> $FTPCMDFILE
echo "bye"                            >> $FTPCMDFILE
ftp -niv  $REMOTESERVER < $FTPCMDFILE > $FTPLOGFILE
logon_succ=`grep -ci "Goodbye" $FTPLOGFILE`
if [ $logon_succ -eq 0 ]
then
  echo "Ftp to Vendor-000009 Failed " 
else
   
  echo "Ftp to Vendor-000009 successfull"
  #echo "File Name :"$Out_FileName >> $FTP_MAIL
  mv $LOCALDIR/*.csv $LOCAL_BACKUP_DIR
fi

I tried changing the permission of the remote file but i am not able to do it.

regards
Prashanth

Last edited by zaxxon; 04-01-2010 at 07:11 AM.. Reason: use square brackets instead of pointy ones when using tags ie [] not <>
# 2  
Old 04-01-2010
Wildcards are not allowed in the ftp implementation of chmod. The ftp environment is not shell but does have some similar commands.

Maybe consider restructuring the script to ftp the files one-by one (using put not mput) you should then be able to chmod the individual file.
This is a general statement because we don't know what Shell you have, what Operating Systems are involved or or what ftp software you are using. Not all ftp versions implement chmod.
If you can type it at the command line you can script it.


Btw. chmod 777 is not the normal permissions for a data file. The loosest permissions would be 666 .
If you have control over the comms configuration unix "rcp" might be more suitable.
# 3  
Old 04-01-2010
change the mode of the file after FTP

Hi
i have tried using this command in the FTP
site chmod -R 777 /batch/ftpTest but it throws the following error
550 SITE CHMOD command failed. Does this mean the user I am trying to use does not have the required permissions?

I have also tried putting each file one after another (using put rather than mput).

I have got this command when searching in forums in this site.

regards
Prashanth
# 4  
Old 04-01-2010
Hello Chandra,
From my experience, you will not be able to change permissions of remote file using ftp/sftp. You can do below mentioned approach.

1. Configure SSH public key authentication b/w these 2 servers(There are several posts for this)

2. Once you see SSH public key authentication working, you can use ssh to change the permission.
Quote:
ssh ${REMOTE_USER}@{REMOTESERVER} chmod 777 $REMOTE_DIR/*.csv
-Nithin.
# 5  
Old 04-01-2010
It would still help to know what software you have.

This command looks unlikely to me:

Quote:
site chmod -R 777 /batch/ftpTest
Please try the very basic form of the command. Many ftp commands do not accept full pathnames or command switches. The chmod will only ever work if the account on the remote server has permissions to issue a chmod on the directory and if local ftpd policy allows the function. The permissions on the directory are important too. The "rhelp" (remote help) and similarly "rhelp site" at your ftp prompt should tell you whether the chmod command is implemented.

Code:
cd /batch
dir ftpTest
put ftpTest
dir ftpTest
chmod 777 ftpTest
dir ftpTest

If local rules allow there are much better methods than ftp to transfer files between unix servers.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Change Param File Variable Test Mode Value

First two days of shell scripting... I've looked at awk/sed and man sed only to get off into the weeds of complexity that may not be needed here... hints for awk or sed or other method to magically change the bolded item below? Nutshell: HFTST=Y #test mode = true to false & back again so... (0 Replies)
Discussion started by: JeffPGMT
0 Replies

2. UNIX for Advanced & Expert Users

Change mode drwxrwsr-x+ directory

Hi, How to change mode "drwxrwsr-x+" in directory. I'm able to set drwxrwsr-x but "+" is difficult to set. ~ $ las -las | grep done1 4 drwxrwsr-x+ 3 root sfuser 4096 Nov 26 16:39 done1 ~ $ getfacl done1 # file: done1 # owner: root # group: sfuser # flags: -s- user::rwx... (4 Replies)
Discussion started by: justbow
4 Replies

3. Shell Programming and Scripting

one line command to change mode only if necessary

hi, sorry for posting this for a quick answer. Is there a one line command to change permissions on files in a directory to a given mode (say 554) and only for those files that do not already have that mode? Running chmod updates the last access/modified timestamp on the files, and i want to... (11 Replies)
Discussion started by: ysrini
11 Replies

4. AIX

ftp connect in passive mode , ftp settings

how to connect to ftp server in passive mode? ftp server.abc and how can i see ftp settings, doesn't exist some ftpd.conf there is some other file where i check the options and configurations of ftp server? Thanks (3 Replies)
Discussion started by: prpkrk
3 Replies

5. Shell Programming and Scripting

ftp file and change prefix

Hi, i want to ftp to another server and change the prefix of the file and change direcotry also. but i am unable to get it. any ideas will be helpful? ftp -n ${HOST} <<END quote USER $USER quote PASS $PASS cd /dir/dir put file mv file fnl.fileEND END (2 Replies)
Discussion started by: dazdseg
2 Replies

6. Solaris

FTP is in maintenance mode always

Hello All, On solaris 10 server i could see the FTP service is in maintenance mode always :mad: Could some assist? svcs -xv svc:/network/nfs/nlockmgr:default (NFS lock manager) State: maintenance since Tue 28 Jul 2009 11:47:55 AM BST Reason: Restarting too quickly. See: Sun... (5 Replies)
Discussion started by: bullz26
5 Replies

7. Shell Programming and Scripting

How to check a file whether it is in binay mode or not while doing ftp??

Hi, One bank statement file should be loaded into some tables by using a concurrent program. But if the file is transfered in binary mode i am getting some special characters in the file which is unexpected. so, for that while moving that file data into tables i want to write a script that... (2 Replies)
Discussion started by: sateesh.d
2 Replies

8. IP Networking

Transfering file through FTP through Binary Mode

Hi, I'm uploading files using internet explorer. 1.Open internet explorer 6.0 2.Open site like ftp://172.45.15.1 3.Copy files The files which I'm copying are basically zip files. What is the default transfer mode, I mean ASCII/BINARY ???. The problem I'm facing, while extracting these... (4 Replies)
Discussion started by: ronald_brayan
4 Replies

9. Shell Programming and Scripting

script to ftp file (ip change)

Hi All, If I want to ftp files from machine to local pc. But the ip must change everytime :( (due to VPN), can I write a script to easiler (no need to update ip in script)? user_name=aaa password=bbb cat ip.txt # # FTP the files # ftp -d -in 199.200.204.109 <<EOF user $user_name... (2 Replies)
Discussion started by: happyv
2 Replies

10. UNIX for Dummies Questions & Answers

How do I change IP addresses in command mode...

How do I change IP addresses in command mode? i need to assign custom (non DHCP) addresses from the command line. Actually I also need to know how to change the subnet mask, the gateway and the primary, secondary, ... dns servers. (6 Replies)
Discussion started by: Super.Anyak
6 Replies
Login or Register to Ask a Question