Reputation: 51
I have the following folder structure on my remote site:
/home/John
/flowers
When I login using ftp_login, the active directory is set to /home/John. If I write:
ftp_put($conn_id, "tulip.jpg", "tulip.jpg")
the file ends up in the /home/John folder as expected.
However I want to upload it into the "flowers" directory. I tried two methods that didn't work:
ftp_put($conn_id, "../../flowers/tulip.jpg", "tulip.jpg")
but the file is still uploaded in /home/Johnftp_chdir
as follows:ftp_chdir($conn_id, '/flowers')
But it ends up in an error:
ftp_chdir(): /flowers: No such file or directory
If I have folders inside /home/John I can use ftp_chdir to change the active directory and point to them, but I cannot do anything outside the folder. Despite not being in the root directory, ftp_pwd($conn_id) returns '/' (I was expecting /home/John)
Logging in with Winscp I can access and write in the "flowers" folder, so there are no rights issues.
How can I do the same thing in PHP with ftp_put?
Upvotes: 0
Views: 105
Reputation: 51
It turned out that user "John" could connect to that server in two ways: via FTP or via SFTP (using the SAME username and password in both cases). When connected via SFTP the root directory was '/' and so, the 'flowers' folder was accessible.
When connected via FTP, it was chrooted to /home/John and therefore it was impossible to move up.
Sadly for me, in winscp I was connecting using the SFTP connection, and therefore the adventure started :)
Upvotes: 1