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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP - delete, mkdir work, get/put do not work 1

Status
Not open for further replies.

RPrinceton

Programmer
Jan 8, 2003
86
0
0
US
Hi everyone,
I am trying to FTP a file from a directory on my website to my HDD using Net::FTP in a Perl script. I have a file server running on my PC. I can successfully do a file delete and mkdir using the script, so this proves the integrity of connectivity and drive access. The problem comes in when I try to FTP i.e., put or get an actual file. I believe it has something to do with the path. I have further deduced that it is the file path to the file on the website and that somehow the script is unable to locate the file or something of that nature. I receive an error message "Cannot open data connection". I really thing this means "Cannot find file". I have included a portion of the code below. Please advise. Thx in advance.
Regards,
RPrinceton

use Net::FTP;


Making a new directory works using this code:
$ftp = Net::FTP->new("EIS", Debug => 0) or die "Cannot connect to EIS: $@";
$ftp->login("WBSFP",'??????') or die "Cannot login ", $ftp->message;
$ftp->cwd("C:\\") or die "Cannot change working directory ", $ftp->message;
$ftp->mkdir("newdir") or die "Cannot make new directory ", $ftp->message;
$ftp->quit;

Deleting a file on my C drive works using this code:
$ftp = Net::FTP->new("EIS", Debug => 0) or die "Cannot connect to EIS: $@";
$ftp->login("WBSFP",'??????') or die "Cannot login ", $ftp->message;
$ftp->cwd("C:\\") or die "Cannot change working directory ", $ftp->message;
$ftp->delete("abc.txt") or die "Cannot delete file ", $ftp->message;
$ftp->quit;

Transferring a file from my PC to the website does NOT work using this code:
$ftp = Net::FTP->new("EIS", Debug => 0) or die "Cannot connect to EIS: $@";
$ftp->login("WBSFP",'??????') or die "Cannot login ", $ftp->message;
$ftp->cwd("C:\\") or die "Cannot change working directory ", $ftp->message;
$ftp->put("/home/nevlinkc/abc.txt","abc.txt") or die "Cannot put file ", $ftp->message;
$ftp->quit;
 
Hi All,
I want to bring closure to this post. To summarize, in a Perl script, I was attempting to FTP some files from my ISP's server to my PC. After many attempts of modifying the script and using two different file servers I was unable to get the FTP to work. The error message indicated it was a router problem, which I do not have. I do want to thank everyone for all of the replies and help I received on this post. I did manage to come up with a workaround if anyone is interested. Perhaps you can use this solution if you encounter this type of problem. I have a product named WS_FTP by Ipswitch installed on my home PC. I use it to transfer files back and forth between my PC and my ISP's server, i.e., my web site. WS_FTP supports the use of command line input. I also have a product that runs on my PC that is capable of sensing when a file is changed i.e., a "folder/file listener". The "listener" program is called MyTrigger by Torgesta. The "listener" software is capable of launching executables and BAT files. I modified my database backup Perl script to write a cookie. I created a BAT file that invokes WS_FTP via command line input. I then made the "listener" program watch the "cookie folder" for the specific cookie file my script was writing. Voila! The Perl script writes the cookie, the "listener" detects the change and in turn launches the BAT files that executes the FTP. A rather complex solution for what should have been a simple task, but it does work.
Kindest Regards,
Randall Princeton
 
why not just have the perl script open WS_FTP and do whatever it is you want when the script writes the cookie?

system("c:\\path\\WS_FTP95.exe your commands here");

or have the perl script invoke your bat file.
 
Hi KevinADC,
As you can tell I am new to Perl. I didn't realize this capability exists. Do understand that I do not have Perl installed on my PC...the scripts run on my ISP's server. I will however try what you suggested. Thank you.
Regards,
Randall Princeton
 
Hi Randall,

If WS_FTP is on your PC, then you can not open it from a perl script on the ISP server. I assumed you had perl on your PC for some reason.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top