User Tools

Site Tools


uphp:functions:ftp_open

ftp_open

WM-MINI2, WM-MEGA FW >= 2.1137 WM-M2 FW >= 3.1137

Open a connection to an FTP server

Description

int ftp_open ( string $host , int $port , string $username , string $password [, int $secure ] [, int $use_keepalive ] [, int $ignore_response ] )

Connect to the server and return the response code.

Parameters

$host: String containing the host name or IP address of teh FTP server

$port: Int FTP port number

$username: String containing the FTP username

$password: String containing the FTP password

$secure: Int whether to use TLS (1) or not (0)

$use_keepalive: Int whether to send keepalive messages or not (1=yes) [only on FW > x.1169]

$ignore_reponse: Int set to 1 if your FTP uploads are not completing properly, this will not wait for the 226 response confirmation but instead close the connection once the data socket has finished sending data to the server. [only on FW > x.1169]

Return Values

int: Returns 1 if FTP connection was successful and 0 if it failed.

Example 1

<?
	$res = ftp_open("ftp.myserver.com",21,"myuser","mypassword");
	if ($res) {
		print("connected to FTP server!!");
		ftp_close();
	}
?>

Example 2

Upload a file to the server but don't wait for the response

<?
        // set folder path here
        $folder_path = "/web/";
 
	$res = ftp_open("ftp.myserver.com",21,"myuser","mypassword",0,1,1);
	if ($res) {
            print("connected to FTP server!!");
            $res=ftp_command("cwd ".$folder_path);
            // upload the file
            $res=ftp_upload("server_filename.txt","/logs/local_filename.txt",0,1);
            if ($res==1) {
                print("File uploaded successfully");
            } else {
                print("Error uploading the file");
            }
            ftp_close();
	}
 
?>

See Also

ftp_close() - Close an FTP connection

uphp/functions/ftp_open.txt · Last modified: 2021/09/13 05:57 (external edit)