problem with php ftp_put command

I'm having a really difficult time trying to resolve this problem...here's the situation:

We have a personals website on one server and want to members to be able to upload and store videos of themselves.  We want the videos to be stored on a different server.

I'm using the ftp functions in php to try and accomplish this.  I seem to have no problems connecting to the server or logging in, but when it comes to actually transferring the files, the script is failing.

Here's the code:

$file = $userfile[$i];//temp file name
$remote_file = $vidname;
$tmpName = basename($userfile[$i]);
move_uploaded_file($file, $vid_working_dir."/".$tmpName) or die("Cannot move uploaded file to working directory");

// set up basic connection
$conn_id = ftp_connect($vid_ip_address,21) or die("Cannot initiate connection to host");

// login with username and password
$login_result = ftp_login($conn_id, $vid_username, $vid_password) or die("could not login");

// upload a file
$savepath = $vid_root_dir.$vid_file_path.$vidname;
$upload = ftp_put($conn_id, $savepath, $vid_working_dir."/".$tmpName, FTP_BINARY);
if (!$upload) {

    echo "Cannot upload";
      

} else {

    echo "Upload complete";
      
}


// close the connection
ftp_close($conn_id);
unlink($vid_working_dir."/".$tmpName) or die("Cannot delete uploaded file from working directory -- manual deletion recommended");


My error logs are giving me the following:

ftp_put(): /var/www/vhosts/vid.xxxxxx.net/httpdocs/videos/1_p61824.mpg: No such file or directory in /var/www/vhosts/xxxxxx.net/httpdocs/php/uploadvideos.php on line 454, referer: http://xxxxxx.net/index.php?&action=uploadvideos

The video is being uploaded to the main server in the temp location without any problem.

What it looks like to me is that it's trying to find the file before it's actually uploaded....this is the first time I've tried to use the ftp commands so I have no experience with this command.

Your help is much appreciated...I'm on a deadline to get this site up and running!

Regards,
amoenum123Asked:
Who is Participating?
 
arnoldConnect With a Mentor Commented:
It seems that whether the file is there or not, the upload will be attempted.  You should make sure that the file has been uploaded prior to attempting the ftp.

Are you sure the location for the remote file is writeable?
can you from the system FTP a file to the remote location with the same credentials?

Have you considered whether you need to use a passive connection?

http://us2.php.net/manual/en/function.ftp-put.php

It might be better to use scp/sftp to avoid transmitting username/password information in plain text: http://us2.php.net/manual/en/function.ssh2-sftp.php

however,  you should consider an asynchronous transfer of uploaded files.  Or use a network mapped (NFS) drive that is accessible from both systems.

0
 
arnoldCommented:
It is not clear how you are handling the transaction of getting the file uploaded to the web server and then the transfer out, or are you trying to skip the intermediary step of storing the file localy by redirecting the stream through an FTP session.

Your best bet would be to get the file first and then have a cron or a scheduled process that would transfer the file. (Presumably you use a database.)
0
 
amoenum123Author Commented:
sorry for not being clear on that part....

I'm not having any trouble with the file upload (using standard file upload in a form) and i've confirmed that it is storing it locally first.

The problem seems to lie when I attempt to transfer the file between servers.  I have no problems connecting to the other server and can log in with the username and password fine.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
arnoldCommented:
The issue is at what stage are you attempting the transfer out (ftp)?  If you are attempting to do so from the script that handles the upload, double check that the ftp session does not begin until the upload is complete.  Or use asynchronous transfer.  I.e. when a file is uploaded mark its detail in a database.  Then have a cron job or a process that checks the database for uploaded files and transfer them out.

 
0
 
amoenum123Author Commented:
ok now i've tried running the following as a standalone process (knowing that the source file exists):

// set up basic connection
$conn_id = ftp_connect("vid.xxxxx.com",21) or die("Cannot initiate connection to host");

// login with username and password
$login_result = ftp_login($conn_id, "username", "passwod") or die("could not login");
i
if(file_exists("/var/www/vhosts/xxxxx.com/httpdocs/workdir/1_p61822.mpg"))
echo "file exists";

// upload a file
$upload = ftp_put($conn_id, "/var/www/vhosts/vid.xxxxx.com/httpdocs/videos/thisvideo.mpg", "/var/www/vhosts/xxxxx.com/httpdocs/workdir/1_p61822.mpg", FTP_BINARY);

if (!$upload) {

    echo "Cannot upload";
      

} else {

    echo "Upload complete";
      
}


i get the output "file exists" after the test for the source file and yet I still get "Cannot upload" as the result.  My error logs are still telling me that the file doesn't exist.  I'm pulling my hair out going crazy.

I'm able to connect to the server...
I'm able to log in.....
The source file exists....
The permissions on the destination directory are set properly...
0
 
amoenum123Author Commented:
ok i seem to have made it a little bit further....

I've changed the destination path from
/var/www/vhosts/vid.xxxxx.com/httpdocs/videos/thisvideo.mpg

to
httpdocs/videos/thisvideo.mpg

and now it's actually started to create the file at the destination, but it's of zero size and won't go any further....
0
 
amoenum123Author Commented:
well i seem to be beating my head against the wall here....

thanks for your help arnold and your patience...i'm going to have to investigate this further using some other method because it's simply not working for me...I'm obviously missing something.

cheers
sean
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.