I know that I need to place a file on the ftp server using the FTP-raw command of STOR, but how do I specify what file to upload? Do I need to read the file into a string before uploading it?

Also, if I use the PASV command previous to the STOR command, how do I know what port was open? Do I need to worry about it?

Thank you all.

    No, that is not even close to what I was looking for. I do not have the ftp commands installed and that is why I have to use the FTP-RAW commands.

      Sorry, I've misread your msg ; what
      you can do is :

      1) Create a socket
      2) send the STOR command + filename
      3) open locally the file
      4) until the end of the file, read it
      and send bytes using the socket
      created at point 1

      You can read the local file, chunk by chunk
      let say 4KB by 4KB, to speed up things.

      I'm afraid I have no PHP example to show you.

        Finally, I've found that, which not exactly
        what you ask, but is very close to it

        <?
        function pullpage( $method, $host, $usepath, $postdata ) {

        open socket to filehandle

        $fp = fsockopen( $host, 80, &$errno, &$errstr, 120 );

                          # user-agent name
                          $ua = "UserAgent/1.0";
        
                          if( !$fp ) {
                              print "$errstr ($errno)<br>n";
                                  echo "there";
        
                          }
                          else {
                              echo "here";
                              if( $method == "GET" ) {
                                  fputs( $fp, "GET $usepath HTTP/1.1n" );
                                  fputs( $fp, "Host: www.mobilemail.dkn" );
                              }
                              else if( $method == "POST" ) {
                                  fputs( $fp, "POST $usepath HTTP/1.1n" );
                                  fputs( $fp, "Host: www.mobilemail.dkn" );
                              }
        
                              fputs( $fp, "User-Agent: ".$ua."n" );
                              fputs( $fp, "Accept: */*n" );
                              fputs( $fp, "Accept: image/gifn" );
                              fputs( $fp, "Accept: image/x-xbitmapn" );
                              fputs( $fp, "Accept: image/jpegn" );
        
                              if( $method == "POST" ) {
                                  $strlength = strlen( $postdata );
        
                                  fputs( $fp,
                                  "Content-type: application/x-www-form-urlencodedn" );
                                  fputs( $fp, "Content-length: ".$strlength."nn" );
                                  fputs( $fp, $postdata."n" );
                              }
        
                              fputs( $fp, "n" );
        
                              $output = "";
        
                              # while content exists, keep retrieving document in 1K chunks
                              while( !feof( $fp ) ) {
                                  $output .= fgets( $fp, 1024 );
                              }
        
                              fclose( $fp );
                          }
        
                          return $output;
                          }

          Thank you so much for the info, but I am having a difficult time understanding the PORT command via PHP and how to refer to that port and pass the data. Can you help me with this?

            This is nice, but uses HTTP commands rather than creating a PORT via RAW-FTP and sending data over that port.

              Nevermind. I have written code that will utillize the data port reported by a PASV command and can now upload files 100% of the time.

                3 months later
                Write a Reply...