Reputation: 5071
Sorry if I missed a question similar to this one here but I couldn't find answer to this. So I am uploading files from a remote server to my server using the FTP with PHP. Here is my code.
<?php
if(isset($_POST['remote'])) {
$source = $_POST['remote'];
$filename = time() . ".apk";
$server = "my_server_address";
$user_name = "username";
$password = "password";
try {
if(ftp_connect($server)) {
$connection = ftp_connect($server);
} else {
throw new Exception("Could not connect to FTP server");
}
} catch (Exception $e) {
echo $e->getMessage();
}
ftp_login($connection, $user_name, $password);
ftp_put($connection, $filename, $source, FTP_ASCII);
}
?>
<form method="post">
<input type="text" name="remote">
<input type="submit" value="Upload">
</form>
Everything goes fine. I connect to my server successfully and remote file is uploaded successfully too. But when I check the file on my server after the upload completes, it breaks (corrupts).
Please note that I am uploading the APK files of Android apps (with .apk extension) with this method.
Any solution to this? Please help.
Upvotes: 1
Views: 57
Reputation: 3029
.apk files are executable code, so you would want to use FTP_BINARY
instead of FTP_ASCII
.
Upvotes: 4