FTP file upload in php
407
I have a windows server from which i wish to transfer some images to my FTP server. below is my code
$file = "docs/1.png";
$ftp_server = "";
$ftp_user_name = "";
$ftp_user_pass = '';
$destination_file = "1.png";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
// upload the file
// ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 180);
ftp_chdir($conn_id, "example/");
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
// ftp_put($conn_id, $destination_file, $file, FTP_BINARY);
ftp_pasv($conn_id, true);
$upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);
// check upload statu
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
I am getting **
ftp_put(): Opening BINARY mode data connection
** this error and file not uploading.