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;
 
This could be a firewall issue

try ftping from the command line on the server, to make sure you can put or get files

let me know how you get on

--Paul

cigless ...
 
Try also using the lcd command to move to the correct local directory and then put the file using its bare name without path specifiers.
 
Hi PaulTEG,
Isn't a true statement that if the problem is the firewall, I wouldn't be able to perform a mkdir or file delete. I'm not sure I can try what you suggest since the server belongs to my ISP. Can I do what you suggest remotely? Please advise. Thx in advance.

Hi MOrac,
I'm not familiar with the lcd command. Does the following code do the same thing.

use CWD
chdir();
chdir("/home/nevlinkc/public_html");

If it doesn't, what is needed in my Perl script to perform the lcd command? Please advise. Thx in advance.

Regards to all,
Randall Princeton
 

$ftp->cwd("/home/nevlinkc");
or
$ftp->cwd("/home/nevlinkc/public_html");
$ftp->put("abc.txt","abc.txt") or die "Cannot put file ", $ftp->message;

Should already be in the root for your account right ?
 
In the line where you put the file on the ftp server the first part should be the file on the client and the second part is the name of the file that will be stored on the server

$ftp->put("/home/nevlinkc/abc.txt","abc.txt")

now is the path of your file this: '/home/nevlinkc/abc.txt'
or it is this : 'c:\\home\\nevlinkc\\abc.txt' or somehting like this, (meaning it is in your c: drive)

cause if it is the second you should write it like this

$ftp->put("c:\\home\\nevlinkc\\abc.txt","abc.txt")

Is it this, cause i didnt quite understand where you install the server and what kind of OS your client has.
 
Hi perluserpengo,
I have the 'put' line coded as:
$ftp->put("/home/nevlinkc/abc.txt","abc.txt")
The file server is running on my PC. The client file is on my Internet hosting service's server. The perl script also runs on my Internet hosting service's server. The error message produced reads: Cannot put file Cannot open data connection.
Regards,
Randall Princeton
 
Looks more like a permissions issue

ftp 10.100.100.2 #or whatever your server IP is
it should then prompt you for a user name and password, enter those and then try putting a file

If this doesn't work, then it's definitely a permissions issue, have you any other usernames on the server?

--Paul

cigless ...
 
Good morning PaulTEG,
I would like to try the suggestions you make. How do I issue the ftp command from my ISP's server or do you want me to code this a Perl script? Secondly you mention permissions...this is the chmod 755 type stuff, right? For a file to be FTPed what must the permissions be set to?
Please advise. Thank you.
Regards,
Randall Princeton
 
open a command window on your desktop, and where hostname is your server name or IP
Code:
c:\>ftp hostname 
prompt for user
prompt for password
ftp> asc                   #set ascii mode
ftp> put smallfile.txt     #put a small file onto the server

Let us know how you get on
--Paul

cigless ...
 
Hi PaulTEG,
Perhaps I haven't been clear enough in my posts. In your last correspondence you indicate running FTP from my PC i.e., c:\>FTP hostname etc. My operating environment is as follows. The file server is running on my PC. The Perl script runs on the hosting service's server. The script is invoked via a webpage. The Perl script is what is issuing the FTP request, not my PC. I have done some additional research on the "Cannot open data connection" error and it seems that in most cases it has something to do with the port if you are running behind a router. I do not have a router so I don't know why I would be getting this error. I use WS_FTP Pro and have virtually no problem FTPing between my PC and the host's server. I truly do not understand that if the logon credentials prove there is a good connection between the Perl script and the file server that the file transfer fails. Do you by chance know of a working Perl script that is doing an FTP? Perhaps there is something subtle that I need. Please advise. Thank you.
Regards,
Randall Princeton
 
Randall,

log on the server in SSH, and try to initiate the connection back to your PC (if you have a unique IP, or hostname) and see how that works.

What I'm trying to determine is if there is any problems with raw FTP before blaming the perl script.

What FTP server are you running on your desktop, also what OS

--Paul


cigless ...
 
Hi PaulTEG,
Thank you for getting back to me. I am relatively new at this UNIX stuff...how do I log on to the server SSH, what is SSH? My hosting service provides me with what I would call a dashboard of sorts that enables an individual to do certain things with regard to the website. If I understand you correctly you want me to get to some type of command prompt at the server but I do not know how this is done. With regard to the FTP server, it is Chameleon by Netmanage and my operating system is Windows 2000 Pro.
Regards,
Randall Princeton
 
Look for Putty on google, it's an SSH client, like telnet, but it encrypts the tunnel

launch putty, and give it your server address/name, and username and password, this might/might not get you in. If it doesn't go to another machine, preferably outside your network, from a internet cafe and try to connect to your desktop

ftp rprinceton (machine name or IP)
user
...
and try to put a small file onto the ftp server
--Paul
 
Hi PaulTEG,
I have downloaded and run PUTTY only to find out that my hosting service does not offer SSH support unless you are on a dedicated server. In my case my website is on a shared server not a dedicated server.
Regards,
Randall Princeton
 
how did you get on with trying to ftp to your machine from outside the network?
--Paul



cigless ...
 
Hi PaulTEG,
The area in which I live does not have any Internet cafes.
I am thinking that perhaps I can go to a library. Assuming I can use the library's computer I'm not clear on on the process. I am assuming I would have to use PUTTY on the library's computer. I don't know if the library will let a person run "personal" software i.e., PUTTY. Assuming I can do this, I will be putting in the IP address of my home PC, correct? Please advise.
Regards,
Randall Princeton
 
You don't need putty on the library PC

All we're trying to do here is connect to your PC from outside your network over FTP

The command line "Start->Run->Cmd.exe" on NT++, Start->Run->Command on Win98

Let us know how you get on

--Paul


cigless ...
 
Hi PaulTEG,
This is the latest status of my FTP problem. I have gone to the library. Due to malicious behavior they do not even present the Windows task bar on any of their computers. This means I was unable to try your suggestion. I have tried another server. It essentially yields the same result. In their help files they state that in an FTP scenario two ports are required. Port 21 is the control port and port 20 is usually the data transfer port. They also allude to having the ports open to the firewall. I have disabled my Zone Alarm to take it out of the equation, but the results remain the same. I am able to use WS_FTP Pro by Ipswitch with no problem. Again I don't understand why one product works but another doesn't. All of my reading with regard to the problem points to a firewall/router issue but 1. I do not have a router and 2. I have taken the firewall out of the equation. What else is left? I use Road Runner as my ISP...is there something that needs to be "tweaked" at the ISP level? Please advise. Thx in advance.
Regards,
Randall Princeton
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top