I have written a script to upload files from my computer to a external server. However I get the following error message:
Warning: ftp_put(): Filename invalid
I have tried changing the filename and etc but have had no luck.
Here is my code:
$ftp_server = "ipaddress";
$username = "username";
$password = "password";
$destination_file = 'C:\ftp_root\borna\ttt.txt';
$source_file = 'C:\inetpub\ftp_test.txt';
// setup basic connection
$conn_id = ftp_connect($ftp_server);
// check connection
if(!$conn_id){
print "FTP connection has failed.<br>";
}else{
print "FTP connection successfull.<br>";
}
// login with username and password
$login_result = ftp_login($conn_id, $username, $password);
// check login
if(!login_result){
print "FTP login credentials not recognised.<br>";
}else{
print "FTP login credentials recognised.<br>";
}
// upload our file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// read upload status
if(!$upload){
print "FTP upload has failed.<br>";
}else{
print "FTP upload was successfull on file $source_file to $destination_file via $ftp_server.<br>";
}
// close the ftp stream
ftp_close($conn_id);
I'd say the error is correct:
$destination_file = "C:\ftp_root\borna\ttt.txt";
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
You're feeding it with a local path as target path (see the C: bit).
If unsure about what server paths will look like, just open the site with a regular FTP client.
If you don't have an FTP client you can download a free one called FileZilla. Install it, launch it, and type your FTP credentials (the piece of data you have in $ftp_server, $username and $password variables) in the top bar. Once you've established a connection you'll see remote paths in the Remote Site box.
Related
I am doing an application for android and i need to upload to the server the profile picture of user i try to do it by ftp , but wen i send the path from android app of this picture it give me an error , and i dont understand much about path from android to web , what i do wrong?
Also forgot to coment i do a random strind with uniqid(); for the name of the file uploaded.
This is my error:
ftp_put(/storage/emulated/0/Download/red-bull-2384130__480.png): failed to open stream: No such file or directory in /home/nicetaxi/public_html/mobilapp/uploadfile.php on line 18
This is my code
<?php
$ftp_server="ftp.......";
$ftp_user_name="......";
$ftp_user_pass=".......";
$Random_str = uniqid();
$file = $_POST["path"];
echo $file;
$remote_file = $Random_str . ".jpg";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
?>
ftp_put(/storage/emulated/0/Download/red-bull-2384130__480.png): failed to open stream: No such file or directory in /home/nicetaxi/public_html/mobilapp/uploadfile.php on line 18
Your server is on the internet and you posted a file path for a file residing on your Android device.
Sorry, but that server connot access files on your Android device.
It does not even try as php thinks its a path on the server itself.
Well then it will not find it.
Instead you should post the file itself to to php server.
I search a lot on internet but i don't find a solution.
I need upload a file to an FTP server through PHP.
I tested various script PHP like this below but I always receive the same problem (I tries with absolute, normal and other path):
connected
Warning: ftp_put(): Can't open that file: No such file or directory in /web/htdocs/www.stanem.it/home/csv/importinnovacsv.php on line 20
There was a problem while uploading /web/htdocs/www.stanem.it/home/csv/test.csv
What I have to do?
<?php
$ftp_server="ftp.xxxx.it";
$ftp_user_name="user";
$ftp_user_pass="psw";
// connect and login to FTP server
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_user_name, $ftp_user_pass);
if($login) {
echo 'connected<br>';
// Where I need to put file
$local_file = '/web/htdocs/www.stanem.it/home/csv/test.csv';
// Where I copy the file
$server_dir = 'ftp://15886:XDBbcFYQUs#ftp.innovaspa.it';
// upload a file
if (ftp_put($ftp_conn, $server_dir, $local_file, FTP_ASCII)) {
echo "successfully uploaded $local_file\n";
exit;
} else {
echo "There was a problem while uploading $local_file\n";
exit;
}
}
The $remote_file argument of ftp_put is a path to the file on the FTP server.
You are passing a URL (and it even misses any path or file name).
It should be like:
$remote_file = "/remote/path/test.csv";
Once you resolve the path problem, you will also likely face data connection problems, as your are using the default active mode. See PHP ftp_put fails.
I have upload script for file uploading from php which is configured to upload file on hosting server from godaddy. Same script I am using on different server domain it is not able to upload on that server which is also godaddy server. I have full access to the folder and server ftp but still didnt find out why this script is not working on that server. Anyone can find out why it is throwing 500 error.
<?php
$ftp_server = "ftp.xxxxx.com";
$ftp_username ="xxxx#xxxx.com";
$ftp_password = "xxxxxxxxxxx";
$destination_folder = "/upload/";
$file_name = $_FILES["userfile"]["name"];
$destination_file = $destination_folder.time().'_'.$file_name;
$file = $_FILES["userfile"]["tmp_name"];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
// upload a file
if (ftp_put($conn_id, $destination_file, $file, FTP_BINARY)) {
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
?>
Do you have shell access? If so, reconfig apache. It may sound not related to your problem, but this will solve it. I had this problem some time ago and rebuilding apache fixed it.
I am trying to connect to a server via php and write a PDF file to a folder that I dynamically create. This is the code I am using:
<?php
$ftp_server = "[server ip]";
$ftp_user_name = "[username]";
$ftp_user_pass = "[password]";
// set up basic ssl connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
if ($login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)){
mkdir('/home/luke/public_html/pdfs/kmhllc/', 0777, true);
}else{
echo "Connection Failed";
}
// close the ssl connection
ftp_close($conn_id);
?>`
The code connects to the server just fine but it can't write to the folder even though it has 0777 permissions on the server.
use ftp_mkdir not mkdir to create a directory on the ftp server.
I need to upload a file automatically from a local computer to a remote server. I have found the following code on here:
<?php
require_once('ftp.php');
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
?>
ftp.php is my file with the ftp authentication information. The connection works but I am getting the following error:
There was a problem while uploading C:/xampp/htdocs/testbcos/accounting/checkslastmonth.csv
EDIT: I amnot sure if this makes a difference or not, but here are my $remote_file and my $file:
$file = "C:/xampp/htdocs/testbcos/accounting/checkslastmonth.csv";//tobe uploaded
$remote_file = "/home/bookcell/public_html/testbcos/accounting/checkslastmonth3.csv";
What am I doing wrong here? Also, is it possible to do this if the file is on a mapped drive on my local server?
Thanks.
First thing: Try to set passive mode. You need it if you're sitting behind a firewall. (What probably is the case)
ftp_pasv($conn_id, true); // after ftp_login
Second, you have to change to dir first:
ftp_chdir($conn_id, '/home/bookcell/public_html/testbcos/accounting/');
ftp_put($conn_id, 'checkslastmonth3.csv', $file, FTP_ASCII);
If you want to know what's really going on, try to get error message with error_get_last() or
$php_errormsg