filecopy from remote machine to local machine
filecopy from remote machine to local machine
am 07.02.2006 14:50:00 von Anu
Hi,
I am tryin to copy a tar file from remote machine to local machine
using Net:Telnet.
I am using the following logic :
my(@Out) = $objTelnet->cmd("cat $FromFile");
$strArg2 = basename $FromFile if $strArg2 eq '.';
open (FH, ">$strfnArg2") or die "Can't open $strfnArg2 for
writing: $!";
print FH @Out;
#closing local file
close FH or die "Can't close $strfnArg2 : $!";
print ("File fetched from remote host successfully");
Note: here strArg2 is the filename that is passed as an argument.
This logic is working fine for ascii files but doesnt for tar
files."cat file.tar" i dont know if that is fine.
Can anyone please help me out here.
And also please do clarify this doubt of mine----" Can we open a
filehandle for a file on the remote machine using Net::Telnet " if so
how?
thanx
Anu.
Re: filecopy from remote machine to local machine
am 07.02.2006 15:28:51 von Paul Lalli
anu wrote:
> I am tryin to copy a tar file from remote machine to local machine
> using Net:Telnet.
Why? Telnet is not a file transfer proticol. Why not use a module
that *does* interface with a file transfer proticol? Such as Net::FTP
or Net::SCP?
> I am using the following logic :
>
> my(@Out) = $objTelnet->cmd("cat $FromFile");
> $strArg2 = basename $FromFile if $strArg2 eq '.';
> open (FH, ">$strfnArg2") or die "Can't open $strfnArg2 for
> writing: $!";
> print FH @Out;
>
> #closing local file
>
> close FH or die "Can't close $strfnArg2 : $!";
>
> print ("File fetched from remote host successfully");
>
>
> Note: here strArg2 is the filename that is passed as an argument.
>
>
> This logic is working fine for ascii files but doesnt for tar
> files.
"doesn't work" is the worst of all possible error descriptions. What
happens? Syntax error? Run-time error? Empty file? No file?
Corrupt file?
How can we help you when you won't tell us what goes wrong?
> "cat file.tar" i dont know if that is fine.
I don't know what that means.
> And also please do clarify this doubt of mine----" Can we open a
> filehandle for a file on the remote machine using Net::Telnet " if so
> how?
Nothing I saw in my (very brief) examination of the docs suggests that
you can. However, check out Net::SSH, which does seem to have that
ability.
Paul Lalli
Re: filecopy from remote machine to local machine
am 07.02.2006 15:36:24 von Paul Lalli
Paul Lalli wrote:
> anu wrote:
> > And also please do clarify this doubt of mine----" Can we open a
> > filehandle for a file on the remote machine using Net::Telnet " if so
> > how?
>
> Nothing I saw in my (very brief) examination of the docs suggests that
> you can. However, check out Net::SSH, which does seem to have that
> ability.
Nope, I'm wrong. Read the docs incorrectly. Net::SSH does not have
this ability either.
I once again suggest an actual file transfer module - Net::FTP,
Net::SFTP, Net::SCP, etc...
Paul Lalli
Re: filecopy from remote machine to local machine
am 08.02.2006 04:50:29 von Anu
Well, the constraints put forward to me dont let me use any of the file
transfer modules of perl. All that I can use are the Net::Telnet and
the Net::SSH module and hence I was trying out tht logic for file
transfer.
"doesn't work" is the worst of all possible error descriptions. What
happens? Syntax error? Run-time error? Empty file? No file?
Corrupt file?
Sorry for that , let me now rephrase that ......when I try that logic
out with Net::Telnet
-- in case of larger files an empty file gets copied
-- in case of smaller files the a corrupt file gets copied
I figured this may be was because tar files are binary files and hence
I tried setting the binmode to 1 which wouldnt translate the newline
characters but then the problem still persists.
Re: filecopy from remote machine to local machine
am 08.02.2006 16:28:35 von unknown
anu wrote:
> Well, the constraints put forward to me dont let me use any of the file
> transfer modules of perl. All that I can use are the Net::Telnet and
> the Net::SSH module and hence I was trying out tht logic for file
> transfer.
>
> "doesn't work" is the worst of all possible error descriptions. What
> happens? Syntax error? Run-time error? Empty file? No file?
> Corrupt file?
>
> Sorry for that , let me now rephrase that ......when I try that logic
> out with Net::Telnet
> -- in case of larger files an empty file gets copied
> -- in case of smaller files the a corrupt file gets copied
>
> I figured this may be was because tar files are binary files and hence
> I tried setting the binmode to 1 which wouldnt translate the newline
> characters but then the problem still persists.
>
Hmm. That's what I was going to suggest. The next step is probably to
uuencode the tar file, cat _that_ onto the link, and uudecode it after.
Nothing magic about uu(en|de)code, anything that ASCII-fies the file is
worth a try.
Don't you hate it when you are both required and forbidden to do a job?
Tom Wyant
Re: filecopy from remote machine to local machine
am 08.02.2006 16:49:14 von Paul Lalli
anu wrote:
> Well, the constraints put forward to me dont let me use any of the file
> transfer modules of perl. All that I can use are the Net::Telnet and
> the Net::SSH module and hence I was trying out tht logic for file
> transfer.
Is this some kind of bizzaro-world homework assignment? Who/What puts
contraints that you can't use File Transfer modules for File Transfers?
Net::Telnet and Net::SSH simply have nothing to do with transferring
files. You may as well be told you can only use Math::BigInt and
Getopt::Long to transfer the files.
> > "doesn't work" is the worst of all possible error descriptions. What
> > happens? Syntax error? Run-time error? Empty file? No file?
> > Corrupt file?
>
> Sorry for that , let me now rephrase that ......when I try that logic
> out with Net::Telnet
> -- in case of larger files an empty file gets copied
> -- in case of smaller files the a corrupt file gets copied
Define larger. Define smaller. Define corrupt.
> I figured this may be was because tar files are binary files and hence
> I tried setting the binmode to 1 which wouldnt translate the newline
> characters but then the problem still persists.
At this point, my recommendation is to write a Perl script that simply
shells out to the actual scp or ftp programs on your machine.
Paul Lalli