Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

copy a file to a remote system

by hperl (Initiate)
on Jan 16, 2013 at 07:48 UTC ( [id://1013524]=perlquestion: print w/replies, xml ) Need Help??

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

I have an ip of the remote system. I want to copy a file from a local system to a directory of the remote system. I am very much new to perl. Please provide a script that can help. Thanks in advance.

Replies are listed 'Best First'.
Re: copy a file to a remote system
by Corion (Patriarch) on Jan 16, 2013 at 07:50 UTC

    You will need to talk to the system administrator of the remote system what method of file transfer she prefers. Most likely it will be one of SFTP, WebDAV or rsync-over-ssh. There are modules for each method on CPAN.

Re: copy a file to a remote system
by perl514 (Pilgrim) on Jan 16, 2013 at 11:11 UTC

    Hi,

    Please check the node - A little demo for Net::SSH2 by Zentara. Its really very informative. I recently created a script, the basis of which was Zentara's excellent writeup.

    Please note, if you are an absolute beginner to Perl, I would kindly request you to please first go through some Basic Perl stuff, also pick up some good books like "Learning Perl 6th Edition" and "Beginning Perl" by Curtis Poe. Not saying that there aren't any other good books, but I found these two books to be really awsome. These will really get you going and keep things pretty interesting.

    If you have picked up the above example because you want to start learning Perl, then may I humbly suggest that you pick something a little easier and gradually move on to stuff like this.

    Perlpetually Indebted To PerlMonks

    Win 7 at Work. Living through it....Linux at home. Loving it.

Re: copy a file to a remote system
by vinoth.ree (Monsignor) on Jan 16, 2013 at 08:42 UTC
    Corion ++

    Net::FTP is a class implementing a simple FTP client in Perl.

Re: copy a file to a remote system
by mhearse (Chaplain) on Jan 16, 2013 at 19:15 UTC
    If you plan to copy file/files repeatedly use rsync. It has the capability to transfer only the changes over the network. Which is why it's so powerful for remote backups.

    If you plan to do backups read up on rsync snapshots. A great example of data de-duplication.

    If you plan to copy the file once, use scp or ftp/lftp.

    There are modules on CPAN for all of these methods.

Re: copy a file to a remote system
by hperl (Initiate) on Jan 18, 2013 at 05:55 UTC
    Thanks for the book suggestions. But right now its an urgent requirement to complete the script. Here is what I used:
    use Net::FTP; $ftp = Net::FTP->new("xxx.xx.xxx.xxx") or die "Cannot connect to some.host.name: $@"; print "1111"; $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message; print "2222"; $ftp->cwd("D:\folder") or die "Cannot change working directory ", $ftp->message; print "3333"; $ftp->put("test.txt") or die "put failed ", $ftp->message; print "4444";
    The msg. it gives is Cannot connect to some.host.name: Net::FTP: connect: Unknown error The procedure to establish FTP is correct to the best of my knowledge, if some discrepency is there, please let me know. Or if something else is being missed, please help.
Re: copy a file to a remote system
by perl514 (Pilgrim) on Jan 18, 2013 at 09:59 UTC

    Hi,

    This might sound like a stupid question, but I am hoping that before running the script you tried ftp'ing to the host and that worked right. Here's more info on a similar problem - Net::FTP cannot connect in Windows 2003. Which version of Perl are you using? On which flavour of Windows?

    For a more informative error, add $^E after the $! statement in die (this is given in the node mentioned above)

    Perlpetually Indebted To PerlMonks

    Win 7 at Work. Living through it....Linux at home. Loving it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-16 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found