PHP - ftp_put failed to open stream?

2019-03-01 13:12发布

问题:

I have a website on a remote host. I am trying to get the php page to upload a file to another remote server through ftp.

The server I am trying to upload to has these directories(all have permission 777):

/
/public_html
/public_html/files

lets say for example these were the ftp details:

host: example.com
user: user
pass: pass
port: 21

can anyone please help me understand why this code isn't working:

$file = 'C:\Users\[my username]\Desktop\somefile.txt';
$remote_file = '/public_html/files/file.txt';

// set up basic connection
$conn_id = ftp_connect("example.com",21);

// login with username and password
$login_result = ftp_login($conn_id, "user", "pass");
echo $login_result;
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
    echo "successfully uploaded $file\n";
} else {
    echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);

when I run it I get the following message:

Warning: ftp_put(C:\Users\User\Desktop\somefile.txt) [function.ftp-put]: failed to open stream: No such file or directory in /home/user/public_html/page.php on line 11

Any help is really appreciated ive researched like crazy and have been trying for ages.

回答1:

$remote_file = 'files/file.txt'; You should try this



标签: php ftp