Jump to content

help with ftp_get I can connect to the server but not sure hot to get to the folder named "Outbox"


kat35601
Go to solution Solved by requinix,

Recommended Posts

I am using ftp_get to connect to a server and want to download a file named CCDATA.TXT from a folder named  Outbox.

 

I can do this with filezilla and I can connect to the server with the below code.

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

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

// close the connection
ftp_close($conn_id);  

But I get these error when I try  this code.

Warning: ftp_get(/Outbox/CCDATA.TXT): failed to open stream: No such file or directory in /var/www/html/dashboard/data/file_download.php on line 16

Warning: ftp_get(): Error opening /Outbox/CCDATA.TXT in /var/www/html/dashboard/data/file_download.php on line 16
Error downloading CCDATA.TXT.

 
$local_file = "file.txt";
$server_file = 'CCDATA.TXT';
$ftp_username="removed";
$ftp_userpass="removed";
$ftp_path = '/Outbox/';
$ftp_server = "removed";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);



// download server file
if (ftp_get($ftp_conn, $ftp_path.$server_file, $local_file,  FTP_ASCII))
  {
  echo "Successfully written to $local_file.";
  }
else
  {
  echo "Error downloading $server_file.";
  }

// close connection
ftp_close($ftp_conn);
Link to comment
Share on other sites

Same error 

 

Warning: ftp_get(Outbox/CCDATA.TXT): failed to open stream: No such file or directory in /var/www/html/dashboard/data/cit_file_download.php on line 16

Warning: ftp_get(): Error opening Outbox/CCDATA.TXT in /var/www/html/dashboard/data/cit_file_download.php on line 16
Error downloading CCDATA.TXT.Connected as giachoufiu@tf.sftp.citonline.com

Link to comment
Share on other sites

This is what I have so far.

<?php
 
$local_file = "order.txt";
$server_file = 'CCDATA.TXT';
$ftp_username="removed";
$ftp_userpass="removed";
$ftp_path = '/Outbox/';
$ftp_server = "tf.sftp.online.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);



// download server file
echo $ftp_server.$ftp_path.$server_file;
if (ftp_get($ftp_conn, $ftp_path.$server_file, $local_file,  FTP_ASCII))
  {
  echo "Successfully written to $local_file.";
  }
else
  {
  echo "Error downloading $server_file.";
  }

// close connection
ftp_close($ftp_conn);
 
 // test connection 
 /*
 $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// try to login
if (@ftp_login($conn_id, $ftp_username, $ftp_userpass)) {
	print_r(ftp_nlist($ftp_conn, "."));
    echo "Connected as $ftp_username@$ftp_server\n";
} else {
    echo "Couldn't connect as $ftp_username\n";
}

// close the connection
ftp_close($conn_id);  */
 
 
 
   ?>

Link to comment
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.