0

I have a class that handles FTP stuff located here:

/var/www/html/crm/rhinos/classes/ftp.php

This class is included in a script that generates a spreadsheet here:

/var/www/html/crm/send_cust_lock.php

The generated spreadsheet is located here:

/var/www/html/crm/tmp/cust_lock_1430424215.xlsx

My class contains the following method:

public function put($filepath){
    $fp = fopen($filepath, 'r');
    $z = ftp_fput($this->connection, $filepath, $fp, FTP_BINARY);
    fclose($fp);
    return $z;
}

From my send_cust_lock.php script, when I call $ftp->put($fn); ($fn being the above filepath to the spreadsheet), I get the following error:

Warning: ftp_fput(): Can't open that file: No such file or directory in /var/www/html/crm/rhinos/classes/ftp.php on line 62

fopen() does not throw an error, so why does ftp_put() throw one?

I have tried converting the path to a relative path using the function in the chosen answer here, but no luck. How can I convert the filepath to something that ftp_put() can recognise?

Community
  • 1
  • 1
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
  • Are you trying to FTP into the same server as the script/file already run? – Jonathan Kuhn Apr 30 '15 at 20:15
  • @JonathanKuhn, no, I'm trying to send it from my development machine to a remote server over the internet. – I wrestled a bear once. Apr 30 '15 at 20:16
  • ok, next question, your code says `ftp_fput()` but your description mentions `ftp_put()`. Which do you need help on? `Realpath()` will return the fully resolved absolute path (as a string) to a file or false if the file could not be found. As long as that is not false, you should be able to use it with `ftp_put`. – Jonathan Kuhn Apr 30 '15 at 20:23
  • @JonathanKuhn, I was so determined that the problem was with the filepath I didn't bother rereading the manual.. turns out I don't even need the filepath where I was putting it. The question has been correctly answered, thanks for you help though! – I wrestled a bear once. Apr 30 '15 at 20:26

1 Answers1

3

The manual says the values are:

ftp_fput ( resource $ftp_stream , string $remote_file , resource $handle , int $mode [, int $startpos = 0 ] )

And you are passing:

$z = ftp_fput($this->connection, $filepath, $fp, FTP_BINARY);

Where your $fp is a handle to the local file as expected, but why are you passing the same path as the $remote_file? It's not going to find it on the remote FTP since you passed the local file name.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133