Reputation: 1545
I am trying to open ftp file using below lines,
$con = ftp_connect(myhost);
if (!$con) {
throw new Exception('Unable to connect');
}
$loggedIn = ftp_login($con, 'user', 'pass');
if ($loggedIn) {
if(ftp_get($con, test.csv, "ftp://myhost/test.csv", FTP_ASCII))
echo 'in';
else
echo 'out';
}
Then I am getting error
ftp_get(): File not found
but if I ran ftp path in browser it fetches file correctly.
can anyone guide me in correct path ?? Thanks in advance
Upvotes: 0
Views: 699
Reputation: 13128
Your best bet is to go with ftp_get()
:
$con = ftp_connect(myhost);
// try to download $server_file and save to $local_file
if (ftp_get($con, 'file_to_save_to.csv', 'test.csv', FTP_BINARY)) {
echo "Successfully written";
} else {
echo "There was a problem\n";
}
As @Gordon stated in the comments:
FTP is an insecure protocol. The credentials are passed in clear text to the server and can be sniffed. Consider using SFTP or another more secure solution.
Upvotes: 1