Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp file transfer 1

Status
Not open for further replies.

sappleg

Programmer
Apr 15, 2008
31
CA
Hi Guys,
I am trying to transfer file via. ftp using command line in my Perl script. However, for some reason after sending first file successfully, the connection gets lost. The log file (ftplog) shows the error as 'Not Connected'.

$command=("ftp -n -i -s:to_ftp.ftp > $ftplog");
system($command);

my ftp script file (to_ftp.ftp) looks like this:

open ftp.to_ftp.com
user
abc
password
ascii
lcd d:\main\jobs\abc\data
cd IN
mput *.txt
dir *.txt
quit

The above only transfers one file and then shows 'Not Connected' as shown in the log file below:

ftp> Connected to ftp.to_ftp.com.

open ftp.to_ftp.com
220 ProFTPD 1.2.10 Server ready.
ftp> Username
password
331 Password required for abc

230 User abc logged in.
ftp> ascii
200 Type set to A
ftp> Local directory now d:\main\jobs\abc\data.

ftp> lcd d:\main\jobs\abc\data
cd IN
250 CWD command successful
ftp> mput *.txt
200 PORT command successful
150 Opening ASCII mode data connection for abc_20090612-1145.txt
226 Transfer complete.
ftp: 6350474 bytes sent in 78.50Seconds 80.90Kbytes/sec.

200 PORT command successful
ftp> Not connected.

ftp> dir *.txt
quit

Please help.
 
use Net::FTP;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thanks Travs69. Unfortunately, I can't use NET::FTP. Is there anything wrong I could be doing in my above code, or is it the FTP site that has issues? Some days it succeeds to send all the files, but then the next day the same fails.
 
Hi

See perlipc | Using [tt]open()[/tt] for IPC and try it like this to have better control :
Code:
[navy]$command[/navy][teal]=[/teal][green][i]"ftp -n -i -s:to_ftp.ftp > $ftplog"[/i][/green][teal];[/teal]

[b]open[/b] FTP[teal],[/teal][green][i]"| $command"[/i][/green][teal];[/teal]
[b]print[/b] FTP [green][i]"open ftp.to_ftp.com\n"[/i][/green][teal];[/teal]
[gray]# ...[/gray]
[b]close[/b] FTP[teal];[/teal]
Of course, add some error handling.


Feherke.
 
Thanks Feherke. This does seem to work. However, I am not able to get the ftp commands output(success/failure) to the log file, except only the commands that I am issuing from the ftp file.
 
Hi

sappleg said:
I am not able to get the ftp commands output(success/failure) to the log file
perlfunc | open said:
You are not allowed to [COLOR=purple #EEEEDD]open[/color] to a command that pipes both in and out, but see IPC::Open2, IPC::Open3, and ""Bidirectional Communication with Another Process"" in perlipc for alternatives.
( perlfunc | open )

Feherke.
 
Hi Feherke,
It worked and redirected output properly. I changed the pipe symbol from 'open FTP, "| $command' to 'open ftp, "$command |'.

It now works the way I wanted it to be.

Thanks a gazillion for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top