Forum Moderators: coopster

Message Too Old, No Replies

FTP Upload Error

         

suicide

1:04 pm on May 20, 2009 (gmt 0)

10+ Year Member



I have troubles with this script below, Also I'm receiving an error which is posted below:

Error
---------
Warning: ftp_put(batch file.txt) [function.ftp-put]: failed to open stream: No such file or directory in C:\Inetpub\wwwroot\ghost\admin\serials\uploadfile.php on line 26

upload.php
-------------
<form action="uploadfile.php" method="post" enctype="multipart/form-data" name="form1" >
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>File name </td>
<td><input type="file" name="file"><input type="submit" name="Submit" value="Upload"></td>
</tr>
</table>
</form>

uploadfile.php
----------------
error_reporting(E_ALL);
ini_set('display_errors','On');

$ftp_user_name='prod-wsus\ghost';
$ftp_user_pass='password';
$ftp_server='ghost.utsi.local';
$source_file=$_FILES['file']['name'];
$destination_file=$source_file;

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id , $ftp_user_name , $ftp_user_pass);

if((!$conn_id)¦¦(!$login_result))
{
echo "FTP connection has failed!" ;
echo "Attempted to connect to $ftp_server for user $ftp_user_name" ;
exit;
}
else
{
echo "Connected to $ftp_server, for user $ftp_user_name" ;
}

$upload = ftp_put($conn_id,$destination_file,$source_file,FTP_ASCII); <--- This is line 26

if(!$upload)
{
echo " FTP upload has failed!" ;
}
else
{
echo "Uploaded $source_file to $ftp_server as $destination_file" ;
}

ftp_close($conn_id);

penders

2:53 pm on May 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It doesn't look like you have finished uploading your file (via HTTP) - hence it doesn't yet exist - before you are trying to 'upload'/put the file to another server via FTP. (Is that your intention?)

Your form uploads the file (via HTTP) to a temporary location $_FILES['file']['tmp_name'] (governed by your server). I think you then need to call move_uploaded_file() to move this file to a slightly more permanent location on your server before you can then use this file to ftp_put it to a different server.

raheelajk

1:34 pm on May 21, 2009 (gmt 0)

10+ Year Member



I can see that problem is with $source_file. Also if you are using Linux/Unix Server then please avoid spaces in file names. So try renaming "batch file.txt" to "batch_file.txt" or "batch-file.txt".

suicide

2:39 pm on May 21, 2009 (gmt 0)

10+ Year Member



Sorry the server is running on a windows box, and I'm going to try with a filename without spaces. Also I'm looking into penders solution.