Moving files to server

Hi there!

I don't know perl at all and would highly appreciate your help. Here's what I need:

I've got some *.jpg/*.gif file in my local directory (c:\...) and I need to move it as it is to the following server directory:

<base path>/<id>/,

while <base path>  exists, but <id> may not exist.

Can *.pl script solve this? I must run it from Java.

Thanks a lot.
kalle73Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
mkdir "$basepath/$id",0755 or die "can't mkdir $basepath/$id $!";
0
guadalupeCommented:
Use Net::FTP

I'll try and send more detailed info in a second...
0
thoellriCommented:
Something like this should work. I assume the server is a Unix box? Or a system which supports FTP?

 Hope this helps
   Tobias


use Net::FTP;

# adjust the following variables:

# where are the local *.jpg/*.gif files?
$local_directory="c:\\";
# what is the hostname of the server?
$server="someserver.somecompany.com";
# what is the username of the user who puts the files up there?
$server_user="username";
# what is this users password?
$server_password="password";
# what is the basepath?
$server_basepath="/some/path";
# what is this "special" id?
$server_id="someid";

# open ftp connection to server
$ftp = Net::FTP->new($server) || die "Can't connect to $server -$!";
# login to server
$ftp->login($server_user,$server_password);
# make the basedir/id directory
$ftp->mkdir("$server_basepath/$server_id",1);
# make the new directory the current directory
$ftp->cwd("$server_basepath/$server_id");
# transfer files in binary mode
$ftp->binary();
# read *.gif/*.jpg filenames
opendir(DIR,$local_directory) || die "can't read dir $local_directory $!";
@files=grep { /\.(gif|jpg)$/i && -f "$local_directory/$_" } readdir(DIR);
closedir(DIR);
# put files on server
foreach (@files) {
  $ftp->put("$local_directory/$_",$_);
}
# close ftp connection
$ftp->close();
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

kalle73Author Commented:
thoellri

Thanks, I'll check whether it works. If it is, you'll get your points.
0
kalle73Author Commented:
thoellri

Actually I need a script which runs on a server. That means that I call its URL (from Java) with params: my local file and destination directory on a server and it moves it.
0
thoellriCommented:
This sounds a lot different than your original question - do you actually know what you want?

Anyway, here are the changes: If you would save this script as "transfer.pl" you would call it with: "transfer.pl /path/to/local/file.xyz /destination/directory/on/server"
If either of the args are missing then the script will die.

Hope *this* helps
  Tobias


use Net::FTP;

$local_file=$ARGV[1] || die "need local file as first argument";
$destination=$ARGV[2] || die "need destination directory";

# adjust the following variables:
# what is the hostname of the server?
$server="someserver.somecompany.com";
# what is the username of the user who puts the files up there?
$server_user="username";
# what is this users password?
$server_password="password";

# open ftp connection to server
$ftp = Net::FTP->new($server) || die "Can't connect to $server -$!";
# login to server
$ftp->login($server_user,$server_password);
# make the destination directory
                    $ftp->mkdir("$destination",1);
# make the new directory the current directory
$ftp->cwd("$destination");
# transfer files in binary mode
$ftp->binary();
# store local file to server
$ftp->put("$local_file");
# close ftp connection
$ftp->close();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kalle73Author Commented:
Thanks, it worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.