ah_yee_00 has asked for the wisdom of the Perl Monks concerning the following question:

I am a beginner for Perl, I want to upload a file to another server, can the file path specified by the ip address? If the file path is "c:\folder\abc.jpg", it's ok, can I use "http://ip/folder/abc.jpg"?? Thanks for your attention!

Replies are listed 'Best First'.
Re: Perl upload file
by tachyon (Chancellor) on Aug 17, 2001 at 09:30 UTC

    Yes, this is Perl you can do almost anything! Assuming you have ftp access to your website you can use something like the Net::FTP module to FTP it up. See the docs for full details but here is a working example. Note you put in the IP address not the http:// part (we are using ftp afterall). The cwd() function changes the working dir and the put uploads the file to the cwd. There are all the other functions you might expect to make dirs etc.

    use Net::FTP; my $webaddr = "www.foo.com"; my $username = "username"; my $password = "password"; my $target_dir = "www"; my $file = "c:/test.txt"; $ftp = Net::FTP->new( $webaddr ) or die $@; $ftp->login( $username, $password ) or die $ftp->message(); $ftp->cwd( $target_dir ) or die $ftp->message(); $ftp->put( $file ) or die $ftp->message(); $ftp->quit;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Perl upload file
by Jonathan (Curate) on Aug 17, 2001 at 18:13 UTC
    If you have access to the server you could upload a file with CGI. A code demo is available here (could'nt be asked to cut and paste it :)
Re: Perl upload file
by RayRay459 (Pilgrim) on Aug 17, 2001 at 19:13 UTC
    is the machine in your domain?(assuming a Win32 env). You could probably use File::Copy also. I had a favorable experience with that. Cheers. Ray