Jump to content

Recommended Posts

Hello fellow phpers,

 

I am trying to create a script that will connect to an FTP site and grab a file from that site. It will then format that file and place it on the root on my machine. I keep getting "SITE EXEC" not understand on line 22. Below is my script. Any help will be greatly appricated. Also the IP address, username and passcode is purposely 'X' out. Thanks everyone. Johnnie

 

<?php

 

 

//ZGJ 9-19-07

 

 

$ftp_server = "XX.XX.XX.XX";

$ftp_user = "XXXX";

$ftp_pass = "XXXX";

$server_file = 'psd_schoolmsgr.txt';

$scrubbed_file = "C:/SMDIM/Data/dump/Puyallup_STU_DEMOGRAPHICS.CSV";

$logfilename = "C:/SMDIM/Logs/Puyallup_STU_DEMOGRAPHICS_LOG.TXT";

include'C:/SMDIM/Translators/include.php';

$ftptimeout = 90; //90 seconds is the default

 

$conn = ftp_connect($ftp_server) or die("Could not connect");

 

ftp_login($conn, $ftp_user, $ftp_pass);

 

ftp_set_option($conn, FTP_TIMEOUT_SEC, $ftptimeout);

 

if (ftp_exec($conn, $command)) {

  echo "$command executed successfully\n";

} else {

  echo "could not execute $command\n";

}

 

$local_file = "C:/SMDIM/Data/" . $server_file;

 

if (!ftp_get($conn, $local_file, $server_file, FTP_BINARY)) {

    wlogDie("Failed to get the file from the FTP server!");

}

 

ftp_close($conn);

 

if (!$in = fopen($local_file, "r")) {

wlogdie("Failed to open $scrubbed_file for reading!");

}

 

if (!$out = fopen($scrubbed_file, "w")) {

wlogdie("Failed to open $scrubbed_file for writing!");

}

 

$count = 0;

 

while($line = fgetcsv($in, 1000, "\t")) {

 

$row = str_replace("\t", ",", $line);

$row[] = "Student";

 

 

writeLine($out, $row);

$count++;

}

 

if ($count !== '0') {

echo "Successfully imported $count records.";

} else {

wlogDie("Failed to import data!");

}

 

fclose($in);

echo "Closed the input file." . "\r\n";

fclose($out);

echo "Closed the ouput file." . "\r\n";

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/70665-connecting-to-an-ftp-site-using-php/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.