<?php
// FTP access parameters
$source_ftp_server = 'ftp://uk9.siteground.eu';
$source_ftp_user_name = 'xyz';
$source_ftp_user_pass = 'abc';
// file to move:
$local_file = '/Users/Swayam/Desktop/Test.csv';
$remote_file = '/home/c10mill2/public_html/edtopiadb/Test.csv';
$fp = fopen($local_file, 'r');
$conn_id = ftp_connect($source_ftp_server);
$login_result = ftp_login($conn_id, $source_ftp_user_name, $source_ftp_user_pass);
$ret = ftp_nb_fput($conn_id, $remote_file, $fp, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
// Establish a new connection to FTP server
if(!isset($conn_id2)) {
$conn_id2 = ftp_connect($source_ftp_server);
$login_result2 = ftp_login($conn_id2, $source_ftp_user_name, $source_ftp_user_pass);
}
// Retreive size of uploaded file.
if(isset($conn_id2)) {
clearstatcache(); // <- this must be included!!
$remote_file_size = ftp_size($conn_id2, $remote_file);
}
// Calculate upload progress
$local_file_size = filesize($local_file);
if (isset($remote_file_size) && $remote_file_size > 0 ){
$i = ($remote_file_size/$local_file_size)*100;
printf("%d%% uploaded<br>", $i);
flush();
}
$ret = ftp_nb_continue($conn_id);
}
if ($ret != FTP_FINISHED) {
echo "<span style='color:red;'><b>There was an error uploading the file...</b></span><br>";
exit(1);
}
else {
echo "<br>Files successfully uploaded!<br><br>";
}
fclose($fp);
请帮助我使用代码来使其正常工作。 当我执行此代码时,我收到错误 -
Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/Swayam/Desktop/sample.php on line 14
Warning: ftp_login() expects parameter 1 to be resource, boolean given in /Users/Swayam/Desktop/sample.php on line 15
Warning: ftp_nb_fput() expects parameter 1 to be resource, boolean given in /Users/Swayam/Desktop/sample.php on line 16
<span style='color:red;'><b>There was an error uploading the file...</b></span><br>