Search code examples
phpfileftpuploadwinscp

Upload files with PHP on FTP server (WinSCP works)


I want to upload a file on a FTP Server (I use WinSCP). But I don't know how use ftp_put.

$file = 'somefile.txt';
$remote_file = 'readme.txt';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_put($conn_id, $remote_file, $file, FTP_ASCII);
ftp_close($conn_id);

I receive the file with a form ($_FILES). In $file, maybe $_FILES['myFile']['name'] but I don't know what to put in $ftp_server and $remote_file. The server http://10.XX.X.XX/myProject/ and my file, in WinSCP are in : /var/www/myProject/

Maybe the hostname is XXXX@xxxxx

enter image description here

It works ! Thanks. The problem was the path, the good is : /myProject/


Solution

  • $ftp_server should be the host name you use, when connecting with WinSCP, like "example.com".

    $remote_file should be "/var/www/myProject/" . $_FILES['myFile']['name'].

    $file should be $_FILES["myFile"]["tmp_name"].