LeeG
LeeG

Reputation: 105

FTP to a subfolder

Is it possible to upload a file into a subfolder on an FTP server?

I send a file daily to an FTP server, scheduled on a cron job that runs a php file. It all works fine, but now I've been asked to change the destination to a subfolder.

Changing *$server_name = 'ftp.website.com'* to *$server_name = 'ftp.website.com/data'* doesn't seem to work?

I can see the folder exists in filezilla and it has all read/write access in permissions.

I'd be grateful if someone can advise if its a permission issue or whether it's possible at all?

Thanks in advance.

CODE...

//FTP bit...

$server_name        = 'ftp.website.com';
$server_username    = 'xxxx';
$server_password    = 'xxxx';
$conn_id = ftp_connect($server_name);
$login_result = ftp_login($conn_id, $server_username, $server_password);
ftp_pasv($conn_id, true);
ftp_put($conn_id, $zip_filename, $output_dir . $zip_filename, FTP_BINARY);

Upvotes: 2

Views: 5216

Answers (3)

signpainter
signpainter

Reputation: 750

I assume you are using the ftp functions of PHP. I see two options:

1) Use ftp_put and specify the absolute path on the ftp server. http://php.net/manual/de/function.ftp-put.php

2) Before uploading your file change the working directory on the ftp server using ftp_chdir http://php.net/manual/de/function.ftp-chdir.php

Upvotes: 2

scibuff
scibuff

Reputation: 13755

If you use ftp_put you simply specify the absolute destination path on the server

http://php.net/manual/en/function.ftp-put.php

Upvotes: 0

SenorAmor
SenorAmor

Reputation: 3345

Seems like you need to use ftp_chdir().

Connect as normal, and then change directories using ftp_chdir().

Upvotes: 5

Related Questions