kalle73
asked on
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.
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.
mkdir "$basepath/$id",0755 or die "can't mkdir $basepath/$id $!";
Use Net::FTP
I'll try and send more detailed info in a second...
I'll try and send more detailed info in a second...
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.someco mpany.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/pa th";
# 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_pas sword);
# make the basedir/id directory
$ftp->mkdir("$server_basep ath/$serve r_id",1);
# make the new directory the current directory
$ftp->cwd("$server_basepat h/$server_ id");
# transfer files in binary mode
$ftp->binary();
# read *.gif/*.jpg filenames
opendir(DIR,$local_directo ry) || 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_director y/$_",$_);
}
# close ftp connection
$ftp->close();
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.someco
# 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/pa
# 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,$
# make the basedir/id directory
$ftp->mkdir("$server_basep
# make the new directory the current directory
$ftp->cwd("$server_basepat
# transfer files in binary mode
$ftp->binary();
# read *.gif/*.jpg filenames
opendir(DIR,$local_directo
@files=grep { /\.(gif|jpg)$/i && -f "$local_directory/$_" } readdir(DIR);
closedir(DIR);
# put files on server
foreach (@files) {
$ftp->put("$local_director
}
# close ftp connection
$ftp->close();
ASKER
thoellri
Thanks, I'll check whether it works. If it is, you'll get your points.
Thanks, I'll check whether it works. If it is, you'll get your points.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, it worked.