LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ftp - check if file on remote exists (skip overriding) (https://www.linuxquestions.org/questions/linux-newbie-8/ftp-check-if-file-on-remote-exists-skip-overriding-822801/)

spiriad 07-29-2010 03:40 AM

ftp - check if file on remote exists (skip overriding)
 
Hello,

I have a script that uploads a file from local to remote place using ftp. The problem is that, if on remote host there is a file called the same as the one I want to upload, the ftp program overrides that file. But I don't want to override nothing (even if the remote file is older, smaller or whatever).
The problem is that I can't test if a file exist on remote (doing [ filename ]) because ftp only allows me limited commands (like ls, mkdir, cd, etc.)

So, how can I check if the file i want to upload already exists, so I can skip overriding ?
Notes :
- Using sunique feature isn't a solution. I don't want to copy nothing if it's there already.
- Maybe using other ftp programs might help, but what programs ?


Thx,
Adrian

Didier Spaier 07-29-2010 04:05 AM

Try lftp.

imagine_me2 07-29-2010 04:08 AM

You could give "lftp" program a try.
Why dont you try "getting" the file first, if its successful remove it locally, else upload.

spiriad 07-29-2010 04:46 AM

I've tried lftp too. But it too doesn't have the option of testing the existence of a file prior to uploading(or I haven't figured out).

"Why dont you try "getting" the file first, if its successful remove it locally, else upload." -> I've toughed that , but like a last resort, I am looking for a more elegant solution. What if the file has 4GB ? No, this will be the last solution.

ghostdog74 07-29-2010 05:06 AM

Code:

$ result=$(ftp -n localhost<<EOF | awk '/myfile/{print "1"}'
user anonymous sadfs
ls -1
bye
EOF
if)
if [[ $result = ]] ;then
  ....
fi


spiriad 07-29-2010 05:42 AM

Hey ghostdog74, it seems this is good. But I have a question : how to specify the whole path of the file on the remote ? E.g.: I want to check to see if /httpdocs/sounds/cool.wav is there. How will the code change ?

Thx


All times are GMT -5. The time now is 01:05 AM.