Operating System - Linux
1829136 Members
2386 Online
109986 Solutions
New Discussion

how to ftp files which are not ftped before

 
QASCO
Advisor

how to ftp files which are not ftped before

Hello experts,

I have windows folder with employees photos, every day i run ftp script form linux to transfer all the files but i want to transfer the files which are recently added to the folder.
how can i do that.

Any help is higly appreciated.
Regards
8 REPLIES 8
Steven E. Protter
Exalted Contributor

Re: how to ftp files which are not ftped before

Shalom QASCO,

Build a file list with the find command

find +ctime 1 > filelist

ctime is 1 hour.
mtime may also work.

A better solution would be to install rsync or ssh for windows and use the rsync command between the two hosts.

http://www.networksimplicity.com
Provides free ssh server for windows.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
QASCO
Advisor

Re: how to ftp files which are not ftped before

Steven,

to make my self clear those files are added only once. in each ftp session i need to ftp the newly added photos for the new emplyees.

Regards,
Alexander Chuzhoy
Honored Contributor

Re: how to ftp files which are not ftped before

Hi QASCO,
if you have to use ftp for downloading files from windows to linux-you can use the following script.Simply copy it to a file on your linux,then make it executable and run.
Replace all variables starting with 'your' to relevant values.
This simple script only checks the files in certain directory on linux box then downloads from ftp all those files that aren't listed in this directory.Thus if you already have them-they won't be downloaded.
It doesn't check for newer files with the same name....
#!/usr/bin/perl
use Net::FTP;
chdir "your_dir";
@local_files=glob "*";
chomp for @local_files;
$server="your_server";
$user="your_user";
$pass="your_password";
$ftp = Net::FTP->new($server, Debug => 0)
or die "Cannot connect to $server: $@";
$ftp->login($user,$pass) or die "Cannot login ", $ftp->message;
@files_on_ftp=$ftp->ls();
chomp for @files_on_ftp;
for $remote(@files_on_ftp)
{
$found=0;
for $locally(@local_files)
{
last if $found == 1;
if ($remote eq $locally)
{
$found=1;
}
}
if ($found == 1)
{
next;
}
else
{
$ftp->get($remote) ;
print "Downloading new file $remote\n";
}
}
$ftp->quit;
QASCO
Advisor

Re: how to ftp files which are not ftped before

Thanks Alexander,

can you give the same script in shell scripting.

Regards,
Stuart Browne
Honored Contributor

Re: how to ftp files which are not ftped before

There isn't a nice neat way to do it with shell script.

Ugly way is to set up a '~/.netrc' with a shell-script and 'find' command, but.. messy given that the folder is hosted on a Windows box.

What you need is either a 'mirror' script, or to populate a file somewhere on the windows box with the update file's names.

Is this folder set up as a Windows share? If so, something could be mangled together using 'smbclient', but the Perl solution is good.
One long-haired git at your service...
Alexander Chuzhoy
Honored Contributor

Re: how to ftp files which are not ftped before

This transfer could also be achieved using the "expect" utility...
QASCO
Advisor

Re: how to ftp files which are not ftped before

Hi All,

Thanks for your inputs, I'm not comfortable with perl scripting.

It seems that i found my way to do it in shell script.

Regards
Pau Garcia i Quiles
Frequent Advisor

Re: how to ftp files which are not ftped before


You may want to give a try to a tool called "unison"
http://www.cis.upenn.edu/~bcpierce/unison/

"Unison is a file-synchronization tool for Unix and Windows. It allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other."

You don't need to install any server or software, just copy the .exe and invoke it when needed.