Hi Guys,

We are testing our site in Amazon AWS and site is built in PHP uses Apache and Mysql.

My problem is i have 2 instances(say source and destination). I want to move file from source instance to destination instance(or say create a file on dest instance from the script running in source instance), for this i am using PHP ftp_put() but i am getting Warning: ftp_put(): Security: Bad IP connecting. in /opt/lampp/htdocs/test.php.
Also i am able to upload files to instance using WinSCP/FileZilla!!!!
Kindly help me to resolve this issue.....

Below is my code

$file = 'source.txt';
$remote_file = '/var/www/readme.txt';

// set up basic connection
$conn_id = ftp_connect('XX.XX.XXX.XX');

// login with username and password
echo $login_result = ftp_login($conn_id, 'XXXXX', 'YYYYYYYY');

// turn passive mode on
ftp_pasv($conn_id, true);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";

// close the connection

Thx in adv :)

Recommended Answers

All 3 Replies

Test this code from the PHP manual on your server and see if it works. If it doesn't then it is an issue with your environment. Maybe a port being blocked, or the IP is "bad".


$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Connected as $ftp_user@$ftp_server\n";
} else {
    echo "Couldn't connect as $ftp_user\n";

// close the connection

ThX pixelsoul for your reply....

Its working fine... I got the out put as Connected as xxxxxx@yy.yyy.yyy.yy

I have not seen that error before. I tested your code locally and there is no problems with it working here. Maybe it is a security issue on the local server your are running the script from, not the server you're connecting to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.