How to ftp the files in perl.?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to ftp the files in perl.?
# 1  
Old 03-21-2013
How to ftp the files in perl.?

i want to upload two different files in to two different directories(path) on ftp server.but i am able to ftping only one at a time Smilie.. not both simultaneously.
here i have connectd the ftp and use the binary mode to transfer the files
Code:
  $ftp = Net::FTP->new($ftphost, Debug => 0)
      or die "Cannot connect to $ftphost $@";

  $ftp->login($ftpuser, $ftppassword)
      or die "Cannot login ", $ftp->message;

  $ftp->binary;
# Full Path on FTP
	
	  $ftp->cwd($fullpath);
	  print "Ftp Path : $fullpath\n\n"; 
	 	  $ftp->put("$filename");
	  
	 $ftp->cwd($fullftp)or die "Cannot change working directory ", $ftp->message; 
	  $ftp->put($filename2) or die $ftp->message;

		  }

would be highly thankful if anyone can help me out.

Regards,
# 2  
Old 03-21-2013
Are you getting any error while placing the second file?
# 3  
Old 03-21-2013
Thnk you so much Panyam to see my post.
m getting cannot open local file 'file.txt' : No such file or directory.. while putting the next file.
pls have a look on modified code.

Code:
 $ftp->cwd($fullpath);
	  print "Ftp Path : $fullpath\n\n"; 
	  print "File Name : $filename\n\n";
	  $ftp->put("$filename")or die $ftp->message;
	  print "Current directory is: ", getcwd(), "\n"; # this is printing the $fullpath.

chdir($ScriptHome)or die "could not cd to $!"; # to chnge the local directory where file exists that needs to ftp.

print "$ScriptHome \n\n"; # printing the local path where file exists.

 $ftp->cwd($fullftp); # to change the directory path where secnd file (filename2.txt) needs to upload.
			 print $ftp->pwd()or die $ftp->message;
#but this print statement printing the first directory path i.e $fullpath instead of $fullftp.
 $ftp->put($filename2) or die $ftp->message;

Regards,

Last edited by aarts; 03-21-2013 at 05:06 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to see the status of all the ftp put & get files logs and curent ftp transfer status ?

How to see the status of all the ftp put & get files logs and curent ftp transfer status if any active ftp running in the background ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. Shell Programming and Scripting

FTP from one directory to another using perl

Hi All I am stuck with a problem and i want your help, I have two directories dir1 and dir2 The files present in dir1 is a1,a2 a3 a4 What i want to is to FTP the files present in the dir1 to dir2 (with .txt extension at the end.) with the help of the Perl. The output expected is The... (12 Replies)
Discussion started by: parthmittal2007
12 Replies

3. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

4. Shell Programming and Scripting

ftp in perl

Hi, I have three files in this /home/mani/ location. I would like to ftp to another server. could you please give perl for that requirement. Thanks, Mani (10 Replies)
Discussion started by: Mani_apr08
10 Replies

5. Shell Programming and Scripting

Perl FTP navigation

Hi Experts, I have this requirement to list dirs and files of an FTP server on regular basis. I was able to do it by following script: $ftpobj = Net::FTP -> new ("$ftpsrv") || die "Cannot connect to FTP $ftpsrv"; $ftpobj -> login("user","passwd"); $ftpobj -> cwd ("/root_dir"); @rootdir... (1 Reply)
Discussion started by: mtomar
1 Replies

6. Shell Programming and Scripting

ftp files in perl

Hi, I am using NET::FTP in perl to tranfer files. i have an array of files and then I m getting one bye one using foreach. the problem is I m not gettng the complete list of files. the program terminates after 2 files. when I execute again it will transfer the remaining 2 files. (... (3 Replies)
Discussion started by: shellwell
3 Replies

7. Filesystems, Disks and Memory

Not able to FTP the files to a FTP server

Hi , We are facing a weird problem in our project. we need to send some xml & audio files to a remote FTP server from a Linux box, we are doing this in Perl script using Net::FTP->. Issue here is.. when FTPed the files using Perl scripts, only empty files ( 0 byte) are getting created on the... (2 Replies)
Discussion started by: kishorepotta
2 Replies

8. Shell Programming and Scripting

Ftp code in Perl

Hi All, i want to have a ftp function in my perl but i am unfamailiar with the perl syntax. Can any body help ? The ftp code below is in csh, can anybody help to convert this to perl with the same functionality ? foreach t (10.10.10.10 20.20.20.20) set USER = "xxx" set PASS = "zzz"... (21 Replies)
Discussion started by: Raynon
21 Replies

9. Shell Programming and Scripting

using perl to ftp

Hi all, I am trying to download a build from an ftp server. My problem is that my build contains sub folders and files within the sub folders. I can ftp a single file at a time, but it will be difficult to specify all the paths and download individula files. My build structure is: ... (2 Replies)
Discussion started by: gurukottur
2 Replies

10. UNIX for Dummies Questions & Answers

Perl, Pipes, and FTP

I am attempting to automate an ftp session in PERL by emulating the user and sending commands to ftp, but I am getting unexpected and unwanted results. Here is a portion code that illustrates the method I am attempting (this was just a shot in the dark): system("( echo open server sleep 1... (2 Replies)
Discussion started by: murdaugh
2 Replies
Login or Register to Ask a Question