LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 07-29-2010, 04:40 AM   #1
spiriad
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Rep: Reputation: 0
Question 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
 
Old 07-29-2010, 05:05 AM   #2
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad W520
Posts: 4,673

Rep: Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236
Try lftp.
 
Old 07-29-2010, 05:08 AM   #3
imagine_me2
Member
 
Registered: Nov 2009
Location: Kolkata, India
Distribution: Fedora 11
Posts: 136

Rep: Reputation: 22
You could give "lftp" program a try.
Why dont you try "getting" the file first, if its successful remove it locally, else upload.
 
Old 07-29-2010, 05:46 AM   #4
spiriad
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 07-29-2010, 06:06 AM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Code:
$ result=$(ftp -n localhost<<EOF | awk '/myfile/{print "1"}'
user anonymous sadfs
ls -1
bye
EOF
if)
if [[ $result = ]] ;then
  ....
fi
 
Old 07-29-2010, 06:42 AM   #6
spiriad
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if file exists in C MTK358 Programming 17 06-20-2010 03:40 AM
Check File Exists shady4u Linux - General 2 02-21-2010 04:05 AM
[SOLVED] check whether a file exists or not ?? vikas027 Programming 5 06-05-2008 05:45 AM
FTP scripts check remote servers file manish_meet_in Linux - General 1 02-28-2007 03:07 PM
c++ check if file exists Genjix Programming 3 03-15-2004 01:08 AM


All times are GMT -5. The time now is 07:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration