find file name...in SFTP

Hi All,

i am using sftp script.

Here is my problem..

i have one script which should find out the exception file that has been already placed on SFTP.

now i wan to check using script whether the file name is present there or not?

i tried using find ...not working.

only ls -l (then the filename)...its working..

but i want to use some different commands which is like grep or awk or sed..like that..is there any possiblity..

can some one help me plz..

:slight_smile:
Thanks in advance
Sha

When using find you'll have to give a name or something you can identify that file with too, like with ls. Not sure what your problem is. Maybe give an example of what you have tried.

You can often check the exit code of commands with $? if they found something or not.

Hi ,

Thanks for your quick replay..

let me explain little bit elaborate....

i have one production box(Linux box) from there i used login SFTP server.

using some credentials like below..

sftp O4dgSFTP@ipaddres
then will ask paswd..if give

then i will be inside SFTP server.

in a daily basis i upload only error file to this SFTP server so that other person can take this and can correct it.

now if i want to check yesterday ..did i upload the error file or not?

here i could not use find command or grep or awk?

whenever i am using those commands its giving Invalid command.

hope you understood my problem now..

Thanks
Sha

When logged in with sftp type "help" and you'll get the list of all commands. sftp has list of commands like ftp and you can't use shell commands in there like find etc.
For this you have either to log what you did on your side/box or have to ask the admin of the other box to add your public ssh key and check it via ssh.

Thanks for you valid suggestion.... :slight_smile:

let me try to do that through ssh..

i have one more question if you could answer!

using below command i get some filename in my unix ...

in some location ... /home/testfolder/

ls -lrt | grep -l $value *.csv > temp1.txt

i would get some out put like below
test.csv
test2.csv
test3.csv

now i want to know which one is the latest one which got generated and i need the timestamp only..is there any way that i can get...

using awk hope i may get.. like this..

ls -lrt test3.csv | awk '{print $6,$7}'

output i am getting like ...

jan 18

because using this time stamp i need to check some other files in different location as well...

Thanks
Sha

ls -rt | grep -l $value *.csv | tail-1 > t.txt
ls -l < t.txt | awk '{print $6,$7}' 

Thanks Jim...

i got it :slight_smile: