How to transfer file from one PC to another using PERL?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to transfer file from one PC to another using PERL?
# 1  
Old 03-28-2012
How to transfer file from one PC to another using PERL?

Hi All

I have two PC connected with each other via LAN cable.
In one of the PC the Perl is installed. What I want to do is transfer the data from one PC to another via Perl.
Is it possible to do this.

---------- Post updated at 11:31 PM ---------- Previous update was at 07:01 AM ----------

I have used Net::FTP but i didn't find the way.
# 2  
Old 03-28-2012
What's your attempt with Net::FTP?
# 3  
Old 03-28-2012
Here it is
Code:
use Net::FTP;
use strict;

open (fh, "> abc.txt");

print fh "this is test data\n";
close fh;


my $ftphost='XXXXXX';
my $ftpuser='XXXXXX';
my $ftppass='XXXXXX';
my $outdir= 'C:/';

my $outfile='C:/Users/XXXXXX/Documents/abc.txt';


# FTP the file
            my $ftp = Net::FTP->new($ftphost,Debug => 1) || die "Unable to establish ftp connection to $ftphost";
           $ftp->login($ftpuser, $ftppass) || die "Unable to log into $ftphost as $ftpuser/$ftppass";
            $ftp->ascii || die  "Unable to change the Type to Ascii\n";
           $ftp->put("$outdir", "$outfile") || die "Unable to ftp $outfile to $ftphost.\n";
         $ftp->quit();
        print "The data output file $outfile was ftpd to $ftphost \n";

# 4  
Old 03-28-2012
Quote:
Originally Posted by parthmittal2007
Here it is
Code:
use Net::FTP;
use strict;
 
open (fh, "> abc.txt");
 
print fh "this is test data\n";
close fh;
 
 
my $ftphost='XXXXXX';
my $ftpuser='XXXXXX';
my $ftppass='XXXXXX';
my $outdir= 'C:/';
 
my $outfile='C:/Users/XXXXXX/Documents/abc.txt';
 
 
# FTP the file
            my $ftp = Net::FTP->new($ftphost,Debug => 1) || die "Unable to establish ftp connection to $ftphost";
           $ftp->login($ftpuser, $ftppass) || die "Unable to log into $ftphost as $ftpuser/$ftppass";
           $ftp->ascii || die  "Unable to change the Type to Ascii\n";
       $ftp->cwd("$outdir") or die "Cannot change working directory ", $ftp->message;
       $ftp->put("$outfile") || die "Unable to ftp $outfile to $ftphost.\n";
           $ftp->quit();
        print "The data output file $outfile was ftpd to $ftphost \n";

You have to set the remote working directory and you can't set that with put method. you have to use cwd method.

Code:
$ftp->cwd("$outdir") or die "Cannot change working directory ", $ftp->message;
$ftp->put("$outfile") || die "Unable to ftp $outfile to $ftphost.\n";

Cheers,
RangaSmilie
# 5  
Old 03-28-2012
Thats correct but what i will write in
my $ftphost my $ftpuser my $ftppass
# 6  
Old 03-28-2012
perl

Quote:
Originally Posted by parthmittal2007
Thats correct but what i will write in
my $ftphost my $ftpuser my $ftppass
You can use the remote ipaddress or hostname in $ftphost.
You can get the ipaddress by execute ipconfig in command prompt of remote machine and execute hostname in command prompt of remote machine
As you know the user name and password of the remote machine for $ftpuser and $ftppass.

Cheers,
RangaSmilie
# 7  
Old 03-28-2012
I have done that same But i am getting Error
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Avoiding file overwrite during file transfer using scp

Hi, I have written a small script to transfer a file from one unix server to other using scp command which is working fine. As I know with scp, if any file with the same name is already present on destination server, it would get overwritten without any notification to user. Could anyone help me... (14 Replies)
Discussion started by: dsa
14 Replies

2. UNIX for Advanced & Expert Users

perl script to transfer newly generated files by scp

Hi all, I have root directory on server 1 say A and having sub directory B now my application generates output files and put in sub directory B. now i need to transfer these files from server1 to server2 by scp which is having same directory structure A and sub directory B I have tried... (2 Replies)
Discussion started by: tushar_spatil
2 Replies

3. Programming

File transfer in C

HI Can anyone provide me with codes for file transfer server to client or vice versa? Also please explain how to compile those programs in ubuntu terminal as i am totally new to socket programming. Thanks (0 Replies)
Discussion started by: mayhemtrigger
0 Replies

4. Shell Programming and Scripting

C, sh, perl, system(): Can't transfer a return code appropriately: help, pls

I am using a perl-script from C-code, executing it by the 'system(..)' comand. The problem is to return the perl-return code to the C correctly. Default the 'system()' shell is Bourne: sh My try: (perl_src.c_pl - the perl script; t_sys - C-program with system() call (I will show it... (7 Replies)
Discussion started by: alex_5161
7 Replies

5. Shell Programming and Scripting

Perl automated file transfer

Hi, Firstly, I have no experience (at all) with shell scripting. So please, go easy on me :) I did a search for what I was looking for although there were a few things available here and on the net I couldn't find anything tailored to what I am looking for. Simply put, I have two servers.... (2 Replies)
Discussion started by: lastrider
2 Replies

6. Shell Programming and Scripting

File transfer

Hi All, it might not be an sound question, i have two server like A and B.. i want to transfer file from B to A ..here i have some questions.. 1) do we need to create private and public key to connect..and transferring files...from B to A..? 2) i tried with scp options like... (2 Replies)
Discussion started by: Shahul
2 Replies

7. UNIX for Dummies Questions & Answers

Transfer the file

Dear all, Can anybody let me know how to automate a file transfer process to a remote m/c thru SFTP , automate means it will not prmpt for password. how i am going to achive this....and what all methods are available or tools are available ???? (2 Replies)
Discussion started by: manas_ranjan
2 Replies

8. Shell Programming and Scripting

file transfer

hi all how do i copy a file from one server to another thanks bkan77 (4 Replies)
Discussion started by: bkan77
4 Replies

9. Shell Programming and Scripting

Data transfer from DB2 to Sybase using Perl?

Hi, Good Morning everybody. I need to write a perl script which will get some data from DB2 table and then put it into Sybase table. I have the experience in Oracle and Unix but new to these perl, DB2 and Sybase technologies. Appreciate if any one can suggest with a sample code. Thanks... (1 Reply)
Discussion started by: rajus19
1 Replies

10. Shell Programming and Scripting

Perl scirpt for automatic file transfer

Hi , can any one help me with a perl script for automating file transfer ? At each step i need to check for the success or failure . I am trying to connect to the target system for a specified number of times.if it doesnt connect even after 3 retries then the script should exit. and i have to... (8 Replies)
Discussion started by: sveera
8 Replies
Login or Register to Ask a Question