Jump to content

FTP server


jadeg

Recommended Posts

I'm getting an error message anytime I try accessing a file on a remote FTP server. Here is the code I've got  

$ftp_server="server";
$ftp_user_name="user";
$ftp_user_pass="passs";
$conn_id = ftp_connect($ftp_server) or die ("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
	if($login_result){
            ftp_pasv($conn_id, true);
            $handle=fopen('crio/criolive.csv);

}


I get this error message

 

 

 

Warning: fopen(/cro1/cRIO01_live.csv) [function.fopen]: failed to open stream: No such file or directory in /home/a5045426/public_html/sample.php on line 39

 

 

any pointer to why this is?

Link to comment
Share on other sites

the path shown in the error message doesn't match what you are showing in your code. the posted fopen() line of code is also invalid, containing a syntax error and is also missing a 2nd parameter. if you want programming help, you must show accurate, unadulterated information.

Link to comment
Share on other sites

Sorry about that. This is the code

$ftp_server="server";
$ftp_user_name="user";
$ftp_user_pass="pass";
	$conn_id = ftp_connect($ftp_server) or die ("Couldn't connect to $ftp_server");
	$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

	if($login_result) {

		echo '<h1> Last Second Reading for Bridgetford T1 </h1>';
	    if(($handle = fopen('/crio1/cRIO01_csv', "r")) !== false) {
	    	
	    
          $data = fgetcsv($handle, 0, ","); 
          var_dump($data);
            }
         }        

with this I get the above error

Link to comment
Share on other sites

FTP is a protocol that is created/designed for the transferring of files from a remote location to a local machine, or vice versa. As a file transfer protocol, FTP is only capable of transferring files from one point to another, and some basic file operations, like copying, moving, or deleting files and directories on the remote machine. In your example you're trying to run a command whose is not a part of the ftp protocol. That's why you failed. To be able to run a wide variety of applications or commands on the remote machine using your local one you need to use a different approach like a SSH or vulnerable Telnet network protocol.   

Link to comment
Share on other sites

the fopen() statement doesn't even have anything to do with ftp, assuming you are trying to open the .csv file on the server where this code is running.

 

based on your last posted code, the error you are getting means what it says, either the file or directory you are using in the fopen() statement doesn't exist. you are aware that the leading / you have on the file system path refers to the root of the current hard disk?

Link to comment
Share on other sites

What's the host's name? Does it contain any special chars? If the "crio1" directory is in relative path to public_html, try to set absolute path to this file, something like,

fopen('ftp://user:pass@server/home/username/public_html/crio1/cRIO01_live.csv', "r")

We need to know the absolute path to this directory on the file structure in the remote machine!

 

http://ca2.php.net/manual/en/function.getcwd.php

 

Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.