Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Using Perl FTP to write a string variable as a file

by toohoo (Beadle)
on Dec 22, 2014 at 11:16 UTC ( [id://1111011]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using Perl FTP to write a string variable as a file
in thread Using Perl FTP to write a string variable as a file

Hello again ...

I have tested it with a testscript. It does not work. The error message is:

Cannot open Local file FH: No such file or directory at test-ftpscalar.pl line 54 put failed (Passive=1) Type set to I ; localfilename(FH): [d:/Dokumente2/Server2/cgi-bin/out//test-ftpscala +r.xml], remotefilename: [test-ftpscalar.xml] at test-ftpscalar.pl lin +e 54.

The script is as follows:

#!/usr/bin/perl print "Content-type: text/html"; print "<html>\n<head>\n<title>Test FTP Sclar</title>\n</head>\n<body>\ +n<p>___ hier gehts los ___:</p>\n<p>\n"; use Net::FTP; my $content = <<__CONTENT__; <inno> <antrag> <tester>THOFMANN(TH)</tester> </antrag> <hinweis> <ziel>Test-Server</ziel> </hinweis> </inno> __CONTENT__ my $server = 'www.lly5.de'; my ($login, $passwd) = ('theoneandonly', 'g1v3m3s0m35h17'); my $localdir = "d:/Dokumente2/Server2/cgi-bin/out/"; my $datei = "test-ftpscalar.pl"; $datei = "test-ftpscalar.xml"; my $remotefile = ''; my $remotefilename; my $passive; my $remotedir = 'public_html/inno/'; my $localfilename; $localfilename = "$localdir\/$datei"; if ($remotefile ne '') { $remotefilename = $remotefile; } else { $remotefilename = $datei; } if ($server =~ m/(www.lly5.de)/i) { # fies, name wurde i +n IP geaendert $passive = 1; $ftp = Net::FTP->new($server, Passive => 1) or die "Cannot connect to $server (Passive=$passiv +e): $@"; } else { $ftp = Net::FTP->new($server) or die "Cannot connect to $server: $@"; } open( FH, "<", \$content) or die "Kann File Handle nic +ht zum lesen aus content oeffnen"; $ftp->login($login, $passwd) or die "Cannot login (Passive=$passive) ", $ftp->m +essage; $ftp->cwd($remotedir) or die "Cannot change working directory (Passive=$ +passive) ", $ftp->message; $ftp->binary or die "Cannot change to binary mode (Passive=$pas +sive) ", $ftp->message; $ftp->put(FH, $remotefilename) or die "put failed (Passive=$passive) ", $ftp->mes +sage, "; localfilename(FH): [$localfilename], remotefilename: [$remot +efilename]"; $ftp->quit; close( FH ); print "*** Fertig FTP ***\n";

Thanks in advance, Thomas

Replies are listed 'Best First'.
Re^4: Using Perl FTP to write a string variable as a file
by poj (Abbot) on Dec 22, 2014 at 13:25 UTC

    Try using a lexical filehandle

    open( my $FH, "<", \$content ) or die "Kann File Handle nicht zum lesen aus content oeffnen"; . . $ftp->put( $FH, $remotefilename ) or die "put failed (Passive=$passive) ", $ftp->message, "; local +filename(FH): [$localfilename], remotefilename: [$remotefilename]"; $ftp->quit; close( $FH );
    poj

      Dear poj,

      many thanks, this works in my test script now. will try to move this to my live script.

      Thanks again and best regards, Thomas

      PS: I guess a :

      binmode( $FH );

      ... after open will be processed correctly

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1111011]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-23 17:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found