• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

PHP file transfer question

Excuse me but I am a noob to programming. I have a PHP API. It is supposed to have most of what I need to modify it for file transfer situations. We cannot use ftp to transfer files to this remote location. The reason for modifying the API is because I can then build it into a windows batch file process which will auto-backup some workstations using NTBACKUP, then call the php script to authenticate and push the file to a remote location. Is this doable? Will someone help me if I get stuck with the code? I do have a book and want to do this just because it's something new.
0
garyoh
Asked:
garyoh
  • 4
  • 3
1 Solution
 
webwyzsystemsCommented:
Given your skills - this is not doable.

Simply writing a php program to do what you want is fairly tricky. Modifying the PHP API to work in batch files, transfer data unattended, and not to use FTP....lol...this is "suicide by code" for a newbie.

There are many technical challenges as well. For example, the destination server has memory limits on each type of data transfer. If you are running IIS7 - i think default is max file size of 30mb for POST FILES. What about time outs - both ends? How are you going to handle disruptions in transfer?
If you are moving backup files - these are GB in length....unles you are going to move tens of thousands of little files.....
At best - your final program will be clunky and unreliable...especially for something like backup.
0
 
danlsCommented:
I would have to agree with webwyzsystems. We have had issues in the past using web scripting languages to perform time-intensive operations (whether they are processor-intensive or bandwidth intensive).

Just out of curiosity, is there a particular reason why you can't FTP the files?

For something like workstation backups, most PHP-based solutions would be unreliable and insecure.
0
 
garyohAuthor Commented:
Well, I have an API with code already in it. I can choose .Net as my API but basically, I think I can edit the text and run it. So perhaps I can post the code and you can look at it? Just curious. I can also use Ruby or Python or C# as I might have mentioned. I don't know why I cannot use FTP but I cannot.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
danlsCommented:
Sure post the code and I'll take a look, but I would suggest a .NET service or Windows app running as a scheduled task would be a bit less prone to timeout issues.
0
 
garyohAuthor Commented:

    function load_from_filename($filename, $verify=True)
    {
        $fp = @fopen($filename, "r");
        if (!$fp) {
            throw new IOException("Could not open file for reading: ".$filename);
        }
        $size = (float) sprintf("%u", filesize($filename));
        if ($size > MAX_OBJECT_SIZE) {
            throw new SyntaxException("File size exceeds maximum object size.");
        }
        $auto_ct = False;
        if (function_exists("finfo_open")) {
            $finfo = False;
            try {
                $finfo = @finfo_open(FILEINFO_MIME);
            } catch (Exception $e) {
                try {
                    $my_mime = dirname(__FILE__) . "/magic";
                    $finfo = @finfo_open(FILEINFO_MIME, $my_mime);
                } catch (Exception $se) {
                    $finfo = False;
                }
            }
            if ($finfo) {
                $ct = finfo_file($finfo, $filename);
                finfo_close($finfo);
                if ($ct) {
                    $this->content_type = $ct;
                    $auto_ct = True;
                }
            }
        }
        if (!$auto_ct && function_exists("mime_content_type")) {
            $this->content_type = @mime_content_type($filename);
        } else {
            $this->content_type = "application/octet-stream";
        }
        $this->write($fp, $size, $verify);
        fclose($fp);
        return True;
    }

Open in new window

0
 
garyohAuthor Commented:
Wouldn't this work or is it bogus?
0
 
danlsCommented:
Well, it appears that function is part of a class. So I assume there is additional functionality.

It seems that all that function does is to take a file name, look at its mime type, which is set into a class property and then writes the file to disk (unless the write() function does something else).

This function itself does not solve any of the problems mentioned (i.e security, timeouts, etc).

I assume this is the API you mentioned. If so, the script above doesn't solve the issue of how you are going to make the backup files available to this script, that is, what does $filename contain? A URL?

Just by looking at the snippet, it's hard to tell. But if you understand what the class does and understand the security implications you might as well go ahead and try to make it work with what you have.

Otherwise I would advise a different solution that is more reliable/secure.

Regards,

D
0
 
garyohAuthor Commented:
It seems as though I have all the parts here and I just need to apply the filename and location. I believe it works over https (I think I saw that in the code). I also know there is a place to enter in the username and a humongous key. I'll look and get that back to you. This is interesting to me so thanks for your patience.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now