I got a weird problem using ftp_put.
My code works perfectly when connecting to my old linux server (ftp_connect), but fails when trying to upload files to the new windows server (client choice) - we're running Filezilla Server on the windows server.
- Can connect to the windows server works (ftp_connect).
- Creating folders works (ftp_mkdir).
- Uploading files does not work - no idea why (ftp_put).
- I can upload files using FileZilla.
- User has full permissions on the Filezilla Server.
- Connecting to "C:/FTP" when connecting to the windows server.
I'm completely lost, got no idea what is causing these errors. Maybe one of you might be able to point me in the right direction.
Does my code need to change path, when changing from a linux to windows server? The folder structure is 100% identical (file has to be saved within a folder named "SE").
This is my code:
# Conf ID
$conf_id = '7AEHQ6GS'; // for testing
# Files
$file1 = "xml/$conf_id/cylinder-tube.xml";
# FTP info
$ftp_host = '';
$ftp_port = '';
$ftp_user = '';
$ftp_pass = '';
# Connect to FTP server
$conn_id = ftp_connect($ftp_host, $ftp_port, 10);
# Connect to FTP Server
if($conn_id) {
if(@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
if(file_exists($file1)) {
# Change directory
ftp_chdir($conn_id, 'SE');
# Create folder
ftp_mkdir($conn_id, $conf_id);
# Change directory
ftp_chdir($conn_id, $conf_id);
# Upload files
if(
ftp_put($conn_id, basename($file1), $file1, FTP_BINARY)
) {
# Delete local files
@unlink($file1);
# Delete local folder
rmdir("xml/$conf_id");
}else{
$st['status'] = 'FTP003';
die(json_encode($st));
}
}else{
$st['status'] = 'FEJL011';
die(json_encode($st));
}
} else {
$st['status'] = 'FTP002';
die(json_encode($st));
}
}else{
$st['status'] = 'FTP001';
die(json_encode($st));
}
This is where my code is failing:
ftp_put($conn_id, basename($file1), $file1, FTP_BINARY)
Thanks,
Kenneth