SFTP - Overwrite [Put -P <file>] option


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users SFTP - Overwrite [Put -P <file>] option
# 1  
Old 03-26-2010
Question SFTP - Overwrite [Put -P <file>] option

Hi All Experts,

I hope you are all ok! Smilie

My question is simple but I was not able to find an answer in the internet, and that's why I am here!

My question is: when I sftp to a server and use "put -P" option to put a file, it keeps the file's full permission and access time. Check below what sftp's man page says about it: "If the -P flag is specified, then the file's full permission and access time are copied too."

What I need is to overwrite the "-P" option in the server side, I mean, I need to change the access time to the current time, is like the client not used the "-P" option.

Is there a way to do it? Smilie

Below there is an example(of course you know it):
Code:
$ sftp USER@SERVER
Connecting to SERVER...
Password:
sftp> put -P FILE.log.2009-10-21
Uploading FILE.log.2009-10-21 to /PATH_TO_FILE/FILE.log.2009-10-21
FILE.log.2009-10-21                                                                                                                      100%  855     0.8KB/s   00:00
sftp> ls -l
-rwxrwxrwx    1 USER   GRP           855 Oct 21 12:46 FILE.log.2009-10-21
sftp> rename FILE.log.2009-10-21 FILE.log.2009-10-21.keep
sftp> ls -l
-rwxrwxrwx    1 USER   GRP           855 Oct 21 12:46 FILE.log.2009-10-21.keep
sftp> put FILE.log.2009-10-21
Uploading FILE.log.2009-10-21 to /PATH_TO_FILE/FILE.log.2009-10-21
FILE.log.2009-10-21                                                                                                                      100%  855     0.8KB/s   00:00
sftp> ls -l
-rwxr-xr-x    1 USER   GRP           855 Mar 26 17:23 FILE.log.2009-10-21
-rwxrwxrwx    1 USER   GRP           855 Oct 21 12:46 FILE.log.2009-10-21.keep
sftp>

As you saw, it kept the access time when I used the -P option, and changed the access time when I did not use it.

Again, what I need is whenever the client uses the -P option, the server ignores it and changes the access time.

That's it!

Thanks for your attention and help!

Regards!
# 2  
Old 03-29-2010
Nobody know it?
# 3  
Old 03-29-2010
Afaik there is no option for the sshd (sshd_config) on the receiving side to ignore -P from a client's put.
Try to make sure the clients don't use that -P option.

An awkward procedure might be to set up a little script in crontab that stats a file a client has transfered with -P, parse the change time and touch the file with it:
Code:
$> stat ~/infile
  File: »/root/infile«
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 805h/2053d      Inode: 424849      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2010-03-29 14:22:42.000000000 +0200
Modify: 2010-03-25 16:16:05.000000000 +0100
Change: 2010-03-29 14:30:24.000000000 +0200



---------- Post updated at 02:43 PM ---------- Previous update was at 02:34 PM ----------

Parsing the date for the touch command could look like this:
Code:
stat ./infile| awk -F"[ .:]" '/^Change:/ {gsub(/-/,"",$3); print $3$4$5$6}'
20100325161605
# so we go for
touch -t=`stat ./infile| awk -F"[ .:]" '/^Change:/ {gsub(/-/,"",$3); print $3$4$5$6}'` infile


Last edited by zaxxon; 03-29-2010 at 09:44 AM.. Reason: update, more help
# 4  
Old 03-29-2010
Hi zaxxon,

Thanks for the reply and sorry about bumping Up my post! I am not going to do that again.

Regards.
# 5  
Old 03-29-2010
No problem - did one of the two suggestions help?
# 6  
Old 03-29-2010
Yes! Both of them! Now I have to choose one. =0)

Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Put -r is not working in SFTP

Hi Folks, I am trying to copy a directory along with sub-directories to SFTP server. I have connected to SFTP and tried to run the below command: sftp> get -r abc/* It is throwing the error Invalid flag -r Can you please let me know the ways to copy a directory from Local to SFTP ... (1 Reply)
Discussion started by: kirans.229
1 Replies

2. Red Hat

SFTP with limit(l) option

Hi, I have sftp installed in some of my corporate servers (test and production). However, I notice that it does not have the limit(l) option for bandwidth limit option. Why is this? Is it because sftp was not installed with other necessary packages? How do I make sftp available with the... (4 Replies)
Discussion started by: anaigini45
4 Replies

3. Shell Programming and Scripting

SFTP batch not renaming file with "put"

I have a .ksh script that creates an sftp batch file and runs it through sftp. It works except for one thing. If I try to "put" to a different name, it doesn't use the specified remote name...it still "puts" the original local name. I've tried both of these, and neither work...it will always... (4 Replies)
Discussion started by: dbiggied
4 Replies

4. Shell Programming and Scripting

./CARE_SM_SFTP.sh[27]: put: not found error while doing sftp

Hi, I am getting the below error while doing sftp in a script file but the same is getting executed when i run from command prompt ./CARE_SM2_SFTP.sh: put: not found Code :- sftp ${USER_ID}@${FTPHOST4}:/opt/path put <Filename with path> chmod 777 <FileName with Path>... (2 Replies)
Discussion started by: satishmallidi
2 Replies

5. Shell Programming and Scripting

How to overwrite a file by transferring the file using sftp?

hi, i am using sftp to transfer files between two servers, if i connect to a remote server using sftp n moves a file say "S123.txt" to the remote server, it moves successfully, but when i try to execute the same sftp script to move the same files to the same remote server, the old file is... (3 Replies)
Discussion started by: Little
3 Replies

6. Shell Programming and Scripting

SFTP PUT

Hi, ServerA (SFTP server) ServerB (SFTP client) ServerB:> sftp user@ServerA ServerB:> put sample.txt ServerB:> get sample2.txt My question is that which machine will encrypt the sample.txt and sample2.txt files. Thanks (8 Replies)
Discussion started by: Arpit Narula
8 Replies

7. Shell Programming and Scripting

SFTP bash put/get/rm check

Hello, i'm doing something like that #!/bin/sh sftp 172.18.255.140 <<End-Of-Session >> /usr/batch/logsftp.txt user batch ascii lcd /usr/batch get olaola.txt bye End-Of-Session   if then echo MAL >> /usr/batch/logsftp.txt echo $? >> /usr/batch/logsftp.txt exit $? else echo... (16 Replies)
Discussion started by: dexposit
16 Replies

8. Shell Programming and Scripting

sftp -b option

Hi, what does -b option do in sftp batch mode..?:confused: (1 Reply)
Discussion started by: rahulsxn660
1 Replies

9. UNIX for Advanced & Expert Users

how to prevent overwrite particular config file when using rpm --replacefile option

Helo I have already installed manbase - 4.0.0.0.15 Now I m installing newver version of the same rpm using rpm -iv -replacefiles manbase -4.0.0.0.16 But using this option my important config files is overwrite. now I want that using first check whethere config file is there or not.... (0 Replies)
Discussion started by: amitpansuria
0 Replies

10. Shell Programming and Scripting

SFTP - 'put' doing an 'mput'

Hi guys, I'm having a problem with F-Secure Unix. When I try a simple command; sftp> put local.test remote.test I expect that the local file local.test would be copied to the remote file remote.test However sftp is attempting to copy local.test & remote.test from the local machine, as if... (2 Replies)
Discussion started by: b0bbins
2 Replies
Login or Register to Ask a Question