transferring files via FTP from my remote
I have not been successful transferring files via FTP from my remote server to my local windows machine using the following code.
$ftpserver = "ftp Server";
$ftpdirectory = "image_specs.txt";
$download = "C:\\testFTP\\Another Directory";
$tempfile = tempnam("tmp", "ftp");
$destdir = "C:\\";
if (!($ftp = ftp_connect($ftpserver))) { print("Unable to connect to $ftpserver!<br>\n");
}
print("Connected to $ftpserverâ¦<br>\n");
if (!ftp_login($ftp, "user", "pass")) { print("Unable to login.<br>\n");
}
print("Logged in.<br>\n");
ftp_pasv($ftp, FALSE);
//if(!ftp_chdir($ftp, $ftpdirectory)) { print("Unable to change directory to $ftpdirectory!<br>\n"); exit();
//}
$fp = fopen($tempfile, 'w');
if(!ftp_fget($ftp, $fp, $download, FTP_ASCII)) { print("Unable to download file $download!<br>\n"); exit();
}
if(!rename($tempfile, $destdir . "C:\\" . $download)) { print("Unable to move file to destination directory!<br>\n"); exit();
}
print("File $download successfully downloaded.<br>\n");
}
or
function ftpFiles ()
{
$conn = ftp_connect("ftp Server") or die("Could not connect");
ftp_login($conn,"user", "pass");
echo ftp_get($conn,"C:\testFTP","image_specs.txt",FTP_A SCII);
ftp_close($conn);
}
or
function downLoad2 ()
{
// define some variables
$local_file = 'C:\testFTP\\';
$server_file = 'image_specs.txt';
// set up basic connection
$conn_id = ftp_connect("ftp Server");
// login with username and password
$login_result = ftp_login($conn_id, "user", "pass");
// try to download $server_file and save to $local_file
if (ftp_fget($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
}
The file is being transferred to the remote server. I need to save the file locally. Please help.
|